Skip to content

Commit 2b525c4

Browse files
committed
Merge remote-tracking branch 'origin/MC-14894' into 2.2.8-develop-pr81
2 parents f39884c + 4387ab3 commit 2b525c4

File tree

2 files changed

+92
-56
lines changed

2 files changed

+92
-56
lines changed

app/code/Magento/Catalog/Model/Product/ProductFrontendAction/Synchronizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ private function getProductIdsByActions(array $actions)
138138
$productIds = [];
139139

140140
foreach ($actions as $action) {
141-
if (isset($action['product_id']) && is_int($action['product_id'])) {
142-
$productIds[] = $action['product_id'];
141+
if (isset($action['product_id']) && (int)$action['product_id']) {
142+
$productIds[] = (int)$action['product_id'];
143143
}
144144
}
145145

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

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

81-
public function testFilterProductActions()
81+
/**
82+
* @dataProvider filterProductActionsDataProvider
83+
*
84+
* @param array $productsData
85+
* @param bool $correct
86+
* @return void
87+
*/
88+
public function testFilterProductActions(array $productsData, bool $correct)
8289
{
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-
];
9790
$frontendConfiguration = $this->createMock(\Magento\Catalog\Model\FrontendStorageConfigurationInterface::class);
9891
$frontendConfiguration->expects($this->once())
9992
->method('get')
10093
->willReturn([
101-
'lifetime' => 2
94+
'lifetime' => 2,
10295
]);
10396
$this->frontendStorageConfigurationPoolMock->expects($this->once())
10497
->method('get')
@@ -110,7 +103,6 @@ public function testFilterProductActions()
110103
$action2 = $this->getMockBuilder(ProductFrontendActionInterface::class)
111104
->getMockForAbstractClass();
112105

113-
$frontendAction = $this->createMock(ProductFrontendActionInterface::class);
114106
$collection = $this->getMockBuilder(Collection::class)
115107
->disableOriginalConstructor()
116108
->getMock();
@@ -126,47 +118,91 @@ public function testFilterProductActions()
126118
$collection->expects($this->once())
127119
->method('addFilterByUserIdentities')
128120
->with(1, 34);
129-
$collection->expects($this->any())
130-
->method('addFieldToFilter')
131-
->withConsecutive(['type_id'], ['product_id']);
132121

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

0 commit comments

Comments
 (0)