7
7
// @codingStandardsIgnoreFile
8
8
9
9
namespace Magento \Catalog \Controller \Product ;
10
+ use Magento \Framework \Message \MessageInterface ;
10
11
11
12
/**
12
13
* @magentoDataFixture Magento/Catalog/controllers/_files/products.php
@@ -43,16 +44,7 @@ public function testAddAction()
43
44
)
44
45
);
45
46
46
- /** @var $messageManager \Magento\Framework\Message\Manager */
47
- $ messageManager = $ objectManager ->get ('Magento\Framework\Message\Manager ' );
48
- $ this ->assertInstanceOf (
49
- 'Magento\Framework\Message\Success ' ,
50
- $ messageManager ->getMessages ()->getLastAddedMessage ()
51
- );
52
- $ this ->assertContains (
53
- 'Simple Product 1 Name ' ,
54
- (string )$ messageManager ->getMessages ()->getLastAddedMessage ()->getText ()
55
- );
47
+ $ this ->assertSessionMessages ($ this ->contains ('Simple Product 1 Name ' ), MessageInterface::TYPE_SUCCESS );
56
48
57
49
$ this ->assertRedirect ();
58
50
@@ -76,17 +68,7 @@ public function testRemoveAction()
76
68
$ product = $ this ->productRepository ->get ('simple_product_2 ' );
77
69
$ this ->dispatch ('catalog/product_compare/remove/product/ ' . $ product ->getEntityId ());
78
70
79
- /** @var $messageManager \Magento\Framework\Message\Manager */
80
- $ messageManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()
81
- ->get ('Magento\Framework\Message\Manager ' );
82
- $ this ->assertInstanceOf (
83
- 'Magento\Framework\Message\Success ' ,
84
- $ messageManager ->getMessages ()->getLastAddedMessage ()
85
- );
86
- $ this ->assertContains (
87
- 'Simple Product 2 Name ' ,
88
- (string )$ messageManager ->getMessages ()->getLastAddedMessage ()->getText ()
89
- );
71
+ $ this ->assertSessionMessages ($ this ->contains ('Simple Product 2 Name ' ), MessageInterface::TYPE_SUCCESS );
90
72
91
73
$ this ->assertRedirect ();
92
74
$ restProduct = $ this ->productRepository ->get ('simple_product_1 ' );
@@ -99,15 +81,8 @@ public function testRemoveActionWithSession()
99
81
$ product = $ this ->productRepository ->get ('simple_product_1 ' );
100
82
$ this ->dispatch ('catalog/product_compare/remove/product/ ' . $ product ->getEntityId ());
101
83
$ secondProduct = $ this ->productRepository ->get ('simple_product_2 ' );
102
- /** @var $messageManager \Magento\Framework\Message\Manager */
103
- $ messageManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()
104
- ->get ('Magento\Framework\Message\Manager ' );
105
- $ this ->assertInstanceOf (
106
- 'Magento\Framework\Message\Success ' ,
107
- $ messageManager ->getMessages ()->getLastAddedMessage ()
108
- );
109
- $ this ->assertContains ('Simple Product 1 Name ' ,
110
- (string )$ messageManager ->getMessages ()->getLastAddedMessage ()->getText ());
84
+
85
+ $ this ->assertSessionMessages ($ this ->contains ('Simple Product 1 Name ' ), MessageInterface::TYPE_SUCCESS );
111
86
112
87
$ this ->assertRedirect ();
113
88
@@ -146,12 +121,9 @@ public function testClearAction()
146
121
147
122
$ this ->dispatch ('catalog/product_compare/clear ' );
148
123
149
- /** @var $messageManager \Magento\Framework\Message\Manager */
150
- $ messageManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()
151
- ->get ('Magento\Framework\Message\Manager ' );
152
- $ this ->assertInstanceOf (
153
- 'Magento\Framework\Message\Success ' ,
154
- $ messageManager ->getMessages ()->getLastAddedMessage ()
124
+ $ this ->assertSessionMessages (
125
+ $ this ->contains ('You cleared the comparison list. ' ),
126
+ MessageInterface::TYPE_SUCCESS
155
127
);
156
128
157
129
$ this ->assertRedirect ();
@@ -167,17 +139,14 @@ public function testRemoveActionProductNameXss()
167
139
$ this ->_prepareCompareListWithProductNameXss ();
168
140
$ product = $ this ->productRepository ->get ('product-with-xss ' );
169
141
$ this ->dispatch ('catalog/product_compare/remove/product/ ' . $ product ->getEntityId () . '?nocookie=1 ' );
170
- $ messages = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
171
- 'Magento\Framework\Message\Manager '
172
- )->getMessages ()->getItems ();
173
- $ isProductNamePresent = false ;
174
- foreach ($ messages as $ message ) {
175
- if (strpos ($ message ->getText (), '<script>alert("xss");</script> ' ) !== false ) {
176
- $ isProductNamePresent = true ;
177
- }
178
- $ this ->assertNotContains ('<script>alert("xss");</script> ' , (string )$ message ->getText ());
179
- }
180
- $ this ->assertTrue ($ isProductNamePresent , 'Product name was not found in session messages ' );
142
+
143
+ $ this ->assertSessionMessages (
144
+ $ this ->logicalNot ($ this ->contains ('<script>alert("xss");</script> ' ))
145
+ );
146
+ $ this ->assertSessionMessages (
147
+ $ this ->contains ('<script>alert("xss");</script> ' ),
148
+ MessageInterface::TYPE_SUCCESS
149
+ );
181
150
}
182
151
183
152
protected function _prepareCompareListWithProductNameXss ()
0 commit comments