Skip to content

Commit 5cad954

Browse files
slavvkaAnna Bukatar
authored andcommitted
MAGETWO-46014: delayed error messages
1 parent 14392fd commit 5cad954

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Controller/Product/CompareTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public function testAddAction()
4444
)
4545
);
4646

47-
$this->assertSessionMessages($this->contains('Simple Product 1 Name'), MessageInterface::TYPE_SUCCESS);
47+
$this->assertSessionMessages(
48+
$this->equalTo(['You added product Simple Product 1 Name to the comparison list.']),
49+
MessageInterface::TYPE_SUCCESS
50+
);
4851

4952
$this->assertRedirect();
5053

@@ -68,7 +71,10 @@ public function testRemoveAction()
6871
$product = $this->productRepository->get('simple_product_2');
6972
$this->dispatch('catalog/product_compare/remove/product/' . $product->getEntityId());
7073

71-
$this->assertSessionMessages($this->contains('Simple Product 2 Name'), MessageInterface::TYPE_SUCCESS);
74+
$this->assertSessionMessages(
75+
$this->equalTo(['You removed product Simple Product 2 Name from the comparison list.']),
76+
MessageInterface::TYPE_SUCCESS
77+
);
7278

7379
$this->assertRedirect();
7480
$restProduct = $this->productRepository->get('simple_product_1');
@@ -82,7 +88,10 @@ public function testRemoveActionWithSession()
8288
$this->dispatch('catalog/product_compare/remove/product/' . $product->getEntityId());
8389
$secondProduct = $this->productRepository->get('simple_product_2');
8490

85-
$this->assertSessionMessages($this->contains('Simple Product 1 Name'), MessageInterface::TYPE_SUCCESS);
91+
$this->assertSessionMessages(
92+
$this->equalTo(['You removed product Simple Product 1 Name from the comparison list.']),
93+
MessageInterface::TYPE_SUCCESS
94+
);
8695

8796
$this->assertRedirect();
8897

@@ -122,7 +131,7 @@ public function testClearAction()
122131
$this->dispatch('catalog/product_compare/clear');
123132

124133
$this->assertSessionMessages(
125-
$this->contains('You cleared the comparison list.'),
134+
$this->equalTo(['You cleared the comparison list.']),
126135
MessageInterface::TYPE_SUCCESS
127136
);
128137

@@ -141,10 +150,9 @@ public function testRemoveActionProductNameXss()
141150
$this->dispatch('catalog/product_compare/remove/product/' . $product->getEntityId() . '?nocookie=1');
142151

143152
$this->assertSessionMessages(
144-
$this->logicalNot($this->contains('<script>alert("xss");</script>'))
145-
);
146-
$this->assertSessionMessages(
147-
$this->contains('&lt;script&gt;alert(&quot;xss&quot;);&lt;/script&gt;'),
153+
$this->equalTo(
154+
['You removed product &lt;script&gt;alert(&quot;xss&quot;);&lt;/script&gt; from the comparison list.']
155+
),
148156
MessageInterface::TYPE_SUCCESS
149157
);
150158
}

dev/tests/integration/testsuite/Magento/Wishlist/Controller/IndexTest.php

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,29 +83,26 @@ public function testItemColumnBlock()
8383
*/
8484
public function testAddActionProductNameXss()
8585
{
86-
$this->dispatch('wishlist/index/add/product/1?nocookie=1');
87-
$messages = $this->_messages->getMessages()->getItems();
88-
$isProductNamePresent = false;
86+
/** @var \Magento\Framework\Data\Form\FormKey $formKey */
87+
$formKey = $this->_objectManager->get('Magento\Framework\Data\Form\FormKey');
88+
$this->getRequest()->setPostValue([
89+
'form_key' => $formKey->getFormKey(),
90+
]);
8991

90-
/** @var InterpretationStrategyInterface $interpretationStrategy */
91-
$interpretationStrategy = $this->_objectManager->create(
92-
'Magento\Framework\View\Element\Message\InterpretationStrategyInterface'
92+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
93+
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
94+
->create('Magento\Catalog\Api\ProductRepositoryInterface');
95+
96+
$product = $productRepository->get('product-with-xss');
97+
98+
$this->dispatch('wishlist/index/add/product/' . $product->getId() . '?nocookie=1');
99+
100+
$this->assertSessionMessages(
101+
$this->equalTo(
102+
['You removed product &lt;script&gt;alert(&quot;xss&quot;);&lt;/script&gt; from the comparison list.']
103+
),
104+
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
93105
);
94-
foreach ($messages as $message) {
95-
if (
96-
strpos(
97-
$interpretationStrategy->interpret($message),
98-
'&lt;script&gt;alert(&quot;xss&quot;);&lt;/script&gt;'
99-
) !== false
100-
) {
101-
$isProductNamePresent = true;
102-
}
103-
$this->assertNotContains(
104-
'<script>alert("xss");</script>',
105-
$interpretationStrategy->interpret($message)
106-
);
107-
}
108-
$this->assertTrue($isProductNamePresent, 'Product name was not found in session messages');
109106
}
110107

111108
/**

0 commit comments

Comments
 (0)