Skip to content

Commit d2ce214

Browse files
author
OlgaVasyltsun
committed
MC-14894: The *Recently Viewed Products* widget not displayed when more one product it was viewed
1 parent ae764ff commit d2ce214

File tree

1 file changed

+84
-54
lines changed

1 file changed

+84
-54
lines changed

app/code/Magento/Catalog/Test/Unit/Model/Product/ProductFrontendAction/SynchronizerTest.php

Lines changed: 84 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,19 @@ protected function setUp()
7878
);
7979
}
8080

81-
public function testFilterProductActions()
81+
/**
82+
* @dataProvider filterProductActionsDataProvider
83+
*
84+
* @param $productsData
85+
* @return void
86+
*/
87+
public function testFilterProductActions($productsData, $correct)
8288
{
83-
$productsData = [
84-
1 => [
85-
'added_at' => 12,
86-
'product_id' => 1,
87-
],
88-
2 => [
89-
'added_at' => 13,
90-
'product_id' => 2,
91-
],
92-
3 => [
93-
'added_at' => 14,
94-
'product_id' => 3,
95-
]
96-
];
9789
$frontendConfiguration = $this->createMock(\Magento\Catalog\Model\FrontendStorageConfigurationInterface::class);
9890
$frontendConfiguration->expects($this->once())
9991
->method('get')
10092
->willReturn([
101-
'lifetime' => 2
93+
'lifetime' => 2,
10294
]);
10395
$this->frontendStorageConfigurationPoolMock->expects($this->once())
10496
->method('get')
@@ -110,7 +102,6 @@ public function testFilterProductActions()
110102
$action2 = $this->getMockBuilder(ProductFrontendActionInterface::class)
111103
->getMockForAbstractClass();
112104

113-
$frontendAction = $this->createMock(ProductFrontendActionInterface::class);
114105
$collection = $this->getMockBuilder(Collection::class)
115106
->disableOriginalConstructor()
116107
->getMock();
@@ -126,47 +117,86 @@ public function testFilterProductActions()
126117
$collection->expects($this->once())
127118
->method('addFilterByUserIdentities')
128119
->with(1, 34);
129-
$collection->expects($this->any())
130-
->method('addFieldToFilter')
131-
->withConsecutive(['type_id'], ['product_id']);
132120

133-
$iterator = new \IteratorIterator(new \ArrayIterator([$frontendAction]));
134-
$collection->expects($this->once())
135-
->method('getIterator')
136-
->willReturn($iterator);
137-
$this->entityManagerMock->expects($this->once())
138-
->method('delete')
139-
->with($frontendAction);
140-
$this->productFrontendActionFactoryMock->expects($this->exactly(2))
141-
->method('create')
142-
->withConsecutive(
143-
[
121+
if ($correct) {
122+
$frontendAction = $this->createMock(ProductFrontendActionInterface::class);
123+
$iterator = new \IteratorIterator(new \ArrayIterator([$frontendAction]));
124+
$collection->expects($this->any())
125+
->method('addFieldToFilter')
126+
->withConsecutive(['type_id'], ['product_id']);
127+
$collection->expects($this->once())
128+
->method('getIterator')
129+
->willReturn($iterator);
130+
$this->entityManagerMock->expects($this->once())
131+
->method('delete')
132+
->with($frontendAction);
133+
$this->entityManagerMock->expects($this->exactly(2))
134+
->method('save')
135+
->withConsecutive([$action1], [$action2]);
136+
$this->productFrontendActionFactoryMock->expects($this->exactly(2))
137+
->method('create')
138+
->withConsecutive(
144139
[
145-
'data' => [
146-
'visitor_id' => null,
147-
'customer_id' => 1,
148-
'added_at' => 12,
149-
'product_id' => 1,
150-
'type_id' => 'recently_compared_product'
151-
]
152-
]
153-
],
154-
[
140+
[
141+
'data' => [
142+
'visitor_id' => null,
143+
'customer_id' => 1,
144+
'added_at' => 12,
145+
'product_id' => 1,
146+
'type_id' => 'recently_compared_product',
147+
],
148+
],
149+
],
155150
[
156-
'data' => [
157-
'visitor_id' => null,
158-
'customer_id' => 1,
159-
'added_at' => 13,
160-
'product_id' => 2,
161-
'type_id' => 'recently_compared_product'
162-
]
151+
[
152+
'data' => [
153+
'visitor_id' => null,
154+
'customer_id' => 1,
155+
'added_at' => 13,
156+
'product_id' => 2,
157+
'type_id' => 'recently_compared_product',
158+
],
159+
],
163160
]
164-
]
165-
)
166-
->willReturnOnConsecutiveCalls($action1, $action2);
167-
$this->entityManagerMock->expects($this->exactly(2))
168-
->method('save')
169-
->withConsecutive([$action1], [$action2]);
161+
)
162+
->willReturnOnConsecutiveCalls($action1, $action2);
163+
}
164+
170165
$this->model->syncActions($productsData, 'recently_compared_product');
171166
}
167+
168+
/**
169+
* @return array
170+
*/
171+
public function filterProductActionsDataProvider(): array
172+
{
173+
return [
174+
[
175+
'productsData' => [
176+
1 => [
177+
'added_at' => 12,
178+
'product_id' => 1,
179+
],
180+
2 => [
181+
'added_at' => 13,
182+
'product_id' => 2,
183+
],
184+
3 => [
185+
'added_at' => 14,
186+
'product_id' => 3,
187+
],
188+
],
189+
'correct' => true,
190+
],
191+
[
192+
'productsData' => [
193+
1 => [
194+
'added_at' => 12,
195+
'product_id' => 'test',
196+
],
197+
],
198+
'correct' => false,
199+
],
200+
];
201+
}
172202
}

0 commit comments

Comments
 (0)