Skip to content

Commit eec31f6

Browse files
committed
MAGETWO-46014: delayed error messages
1 parent b4d3739 commit eec31f6

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
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: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,28 +96,13 @@ public function testAddActionProductNameXss()
9696
$product = $productRepository->get('product-with-xss');
9797

9898
$this->dispatch('wishlist/index/add/product/' . $product->getId() . '?nocookie=1');
99-
$messages = $this->_messages->getMessages()->getItems();
100-
$isProductNamePresent = false;
10199

102-
/** @var InterpretationStrategyInterface $interpretationStrategy */
103-
$interpretationStrategy = $this->_objectManager->create(
104-
'Magento\Framework\View\Element\Message\InterpretationStrategyInterface'
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
105105
);
106-
foreach ($messages as $message) {
107-
if (
108-
strpos(
109-
$interpretationStrategy->interpret($message),
110-
'&lt;script&gt;alert(&quot;xss&quot;);&lt;/script&gt;'
111-
) !== false
112-
) {
113-
$isProductNamePresent = true;
114-
}
115-
$this->assertNotContains(
116-
'<script>alert("xss");</script>',
117-
$interpretationStrategy->interpret($message)
118-
);
119-
}
120-
$this->assertTrue($isProductNamePresent, 'Product name was not found in session messages');
121106
}
122107

123108
/**

0 commit comments

Comments
 (0)