Skip to content

Commit 3285d4a

Browse files
committed
Merge branch 'ACP2E-39' of https://github.com/magento-l3/magento2ce into ACP2E-39
2 parents f7bb2f2 + 4f2b7f4 commit 3285d4a

File tree

2 files changed

+39
-100
lines changed

2 files changed

+39
-100
lines changed

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

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -107,36 +107,10 @@ protected function setUp(): void
107107
);
108108
}
109109

110-
/**
111-
* Variation for UserIdentities.
112-
*
113-
* @return array
114-
*/
115-
public function getUserIdentitiesCases(): array
116-
{
117-
return [
118-
[
119-
'customerId' => 1,
120-
'visitorId' => null
121-
],
122-
[
123-
'customerId' => null,
124-
'visitorId' => 33
125-
],
126-
[
127-
'customerId' => null,
128-
'visitorId' => null
129-
],
130-
];
131-
}
132-
133110
/**
134111
* @inheritDoc
135-
* @param int $customerId
136-
* @param int $visitorId
137-
* @dataProvider getUserIdentitiesCases
138112
*/
139-
public function testFilterProductActions(int $customerId = null, int $visitorId = null): void
113+
public function testFilterProductActions(): void
140114
{
141115
$typeId = 'recently_compared_product';
142116
$productsData = [
@@ -175,16 +149,16 @@ public function testFilterProductActions(int $customerId = null, int $visitorId
175149
->getMock();
176150
$this->sessionMock->expects($this->any())
177151
->method('getCustomerId')
178-
->willReturn($customerId);
152+
->willReturn(1);
179153
$this->visitorMock->expects($this->exactly(2))
180154
->method('getId')
181-
->willReturn($visitorId);
155+
->willReturn(34);
182156
$this->collectionFactoryMock->expects($this->once())
183157
->method('create')
184158
->willReturn($collection);
185159
$collection->expects($this->once())
186160
->method('addFilterByUserIdentities')
187-
->with($customerId, $visitorId);
161+
->with(1, 34);
188162
$collection
189163
->method('addFieldToFilter')
190164
->withConsecutive(['type_id', $typeId], ['product_id', [1, 2]]);
@@ -201,8 +175,8 @@ public function testFilterProductActions(int $customerId = null, int $visitorId
201175
[
202176
[
203177
'data' => [
204-
'visitor_id' => $visitorId,
205-
'customer_id' => $customerId,
178+
'visitor_id' => null,
179+
'customer_id' => 1,
206180
'added_at' => 12,
207181
'product_id' => 1,
208182
'type_id' => 'recently_compared_product'
@@ -212,8 +186,8 @@ public function testFilterProductActions(int $customerId = null, int $visitorId
212186
[
213187
[
214188
'data' => [
215-
'visitor_id' => $visitorId,
216-
'customer_id' => $customerId,
189+
'visitor_id' => null,
190+
'customer_id' => 1,
217191
'added_at' => 13,
218192
'product_id' => 2,
219193
'type_id' => 'recently_compared_product'

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/ProductFrontendAction/SynchronizerTest.php

Lines changed: 31 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
namespace Magento\Catalog\Model\Product\ProductFrontendAction;
99

1010
use Magento\Catalog\Model\ProductRepository;
11+
use Magento\Customer\Api\CustomerRepositoryInterface;
12+
use Magento\Customer\Model\Session;
13+
use Magento\Customer\Model\Visitor;
1114

1215
/**
1316
* Test for \Magento\Catalog\Model\Product\ProductFrontendAction\Synchronizer.
@@ -30,17 +33,23 @@ class SynchronizerTest extends \PHPUnit\Framework\TestCase
3033
*/
3134
private $productRepository;
3235

36+
/**
37+
* @var CustomerRepositoryInterface
38+
*/
39+
private $customerRepository;
40+
3341
/**
3442
* @inheritDoc
3543
*/
3644
protected function setUp(): void
3745
{
3846
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
39-
$this->session = $objectManager->get(\Magento\Customer\Model\Session::class);
40-
$this->visitor = $objectManager->get(\Magento\Customer\Model\Visitor::class);
47+
$this->session = $objectManager->get(Session::class);
48+
$this->visitor = $objectManager->get(Visitor::class);
4149

4250
$this->synchronizer = $objectManager->get(Synchronizer::class);
4351
$this->productRepository = $objectManager->get(ProductRepository::class);
52+
$this->customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
4453
}
4554

4655
/**
@@ -120,27 +129,23 @@ public function testSyncActionsWithoutActionsType(): void
120129
}
121130

122131
/**
132+
* Tests that product actions are returned correctly according to the provided customer or visitor.
133+
*
134+
* @param int|null $visitorId
135+
* @param string|null $customerEmail
136+
* @param int $expectedCollectionSize
123137
* @return void
124-
* @throws \Magento\Framework\Exception\LocalizedException
125-
* @throws \Magento\Framework\Exception\NoSuchEntityException
126-
*/
127-
public function testGetAllActionsWithoutCustomerAndVisitor(): void
128-
{
129-
$collection = $this->synchronizer->getAllActions();
130-
$this->assertEquals($collection->getSize(), 0);
131-
}
132-
133-
/**
138+
* @dataProvider getAllActionsDataProvider
139+
*
140+
* @magentoDataFixture Magento/Customer/_files/customer.php
134141
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
135142
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
136-
*
137-
* @return void
138-
* @throws \Magento\Framework\Exception\LocalizedException
139-
* @throws \Magento\Framework\Exception\NoSuchEntityException
140143
*/
141-
public function testGetAllActionsOfVisitor(): void
144+
public function testGetAllActions(?int $visitorId, ?string $customerEmail, int $expectedCollectionSize): void
142145
{
143-
$this->visitor->setId(123);
146+
$customerId = $customerEmail ? $this->customerRepository->get($customerEmail)->getId() : null;
147+
$this->session->setCustomerId($customerId);
148+
$this->visitor->setId($visitorId);
144149
$actionsType = 'recently_viewed_product';
145150
$productScope = 'website';
146151
$scopeId = 1;
@@ -161,61 +166,21 @@ public function testGetAllActionsOfVisitor(): void
161166

162167
$this->synchronizer->syncActions($productsData, $actionsType);
163168
$collection = $this->synchronizer->getAllActions();
164-
$this->assertEquals($collection->getSize(), 2);
169+
170+
$this->assertEquals($expectedCollectionSize, $collection->getSize());
165171
}
166172

167173
/**
168-
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
169-
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
170-
*
171-
* @return void
174+
* @return array[]
172175
* @throws \Magento\Framework\Exception\LocalizedException
173176
* @throws \Magento\Framework\Exception\NoSuchEntityException
174177
*/
175-
public function testGetAllActionsOfCustomer(): void
178+
public function getAllActionsDataProvider()
176179
{
177-
$customer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
178-
->create(\Magento\Customer\Model\Customer::class);
179-
/** @var \Magento\Customer\Model\Customer $customer */
180-
$customer
181-
->setWebsiteId(1)
182-
->setId(1)
183-
->setEntityTypeId(1)
184-
->setAttributeSetId(1)
185-
->setEmail('customer@example.com')
186-
->setPassword('password')
187-
->setGroupId(1)
188-
->setStoreId(1)
189-
->setIsActive(1)
190-
->setFirstname('Firstname')
191-
->setLastname('Lastname')
192-
->setDefaultBilling(1)
193-
->setDefaultShipping(1);
194-
$customer->isObjectNew(true);
195-
$customer->save();
196-
197-
$this->session->setCustomerId(1);
198-
$this->visitor->setId(null);
199-
$actionsType = 'recently_viewed_product';
200-
$productScope = 'website';
201-
$scopeId = 1;
202-
$product1 = $this->productRepository->get('simple');
203-
$product2 = $this->productRepository->get('simple2');
204-
$product1Id = $product1->getId();
205-
$product2Id = $product2->getId();
206-
$productsData = [
207-
$productScope . '-' . $scopeId . '-' . $product1Id => [
208-
'added_at' => '1576582660',
209-
'product_id' => $product1Id,
210-
],
211-
$productScope . '-' . $scopeId . '-' . $product2Id => [
212-
'added_at' => '1576587153',
213-
'product_id' => $product2Id,
214-
],
180+
return [
181+
['visitorId' => null, 'customerEmail' => 'customer@example.com', 'expectedCollectionSize' => 2],
182+
['visitorId' => 123, 'customerEmail' => null, 'expectedCollectionSize' => 2],
183+
['visitorId' => null, 'customerEmail' => null, 'expectedCollectionSize' => 0],
215184
];
216-
217-
$this->synchronizer->syncActions($productsData, $actionsType);
218-
$collection = $this->synchronizer->getAllActions();
219-
$this->assertEquals($collection->getSize(), 2);
220185
}
221186
}

0 commit comments

Comments
 (0)