43 $this->sessionMock = $this->getMockBuilder(\
Magento\Customer\Model\Session::class)
44 ->disableOriginalConstructor()
46 $this->visitorMock = $this->getMockBuilder(\
Magento\Customer\Model\Visitor::class)
47 ->disableOriginalConstructor()
49 $this->productFrontendActionFactoryMock = $this
50 ->getMockBuilder(\
Magento\Catalog\Model\ProductFrontendActionFactory::class)
51 ->disableOriginalConstructor()
52 ->setMethods([
'create'])
54 $this->entityManagerMock = $this->getMockBuilder(\
Magento\Framework\EntityManager\EntityManager::class)
55 ->disableOriginalConstructor()
57 $this->collectionFactoryMock = $this
58 ->getMockBuilder(\
Magento\Catalog\Model\
ResourceModel\ProductFrontendAction\CollectionFactory::class)
59 ->disableOriginalConstructor()
60 ->setMethods([
'create'])
62 $this->frontendStorageConfigurationPoolMock = $this
63 ->getMockBuilder(\
Magento\Catalog\Model\FrontendStorageConfigurationPool::class)
64 ->disableOriginalConstructor()
67 $this->objectManagerHelper =
new ObjectManagerHelper($this);
68 $this->model = $this->objectManagerHelper->getObject(
69 \
Magento\Catalog\Model\
Product\ProductFrontendAction\Synchronizer::class,
71 'session' => $this->sessionMock,
72 'visitor' => $this->visitorMock,
73 'productFrontendActionFactory' => $this->productFrontendActionFactoryMock,
74 'entityManager' => $this->entityManagerMock,
75 'collectionFactory' => $this->collectionFactoryMock,
76 'frontendStorageConfigurationPool' => $this->frontendStorageConfigurationPoolMock
97 $frontendConfiguration = $this->createMock(\
Magento\Catalog\Model\FrontendStorageConfigurationInterface::class);
98 $frontendConfiguration->expects($this->once())
103 $this->frontendStorageConfigurationPoolMock->expects($this->once())
105 ->with(
'recently_compared_product')
106 ->willReturn($frontendConfiguration);
107 $action1 = $this->getMockBuilder(ProductFrontendActionInterface::class)
108 ->disableOriginalConstructor()
109 ->getMockForAbstractClass();
110 $action2 = $this->getMockBuilder(ProductFrontendActionInterface::class)
111 ->getMockForAbstractClass();
113 $frontendAction = $this->createMock(ProductFrontendActionInterface::class);
114 $collection = $this->getMockBuilder(Collection::class)
115 ->disableOriginalConstructor()
117 $this->sessionMock->expects($this->any())
118 ->method(
'getCustomerId')
120 $this->visitorMock->expects($this->exactly(2))
123 $this->collectionFactoryMock->expects($this->once())
127 ->method(
'addFilterByUserIdentities')
130 ->method(
'addFieldToFilter')
131 ->withConsecutive([
'type_id'], [
'product_id']);
133 $iterator = new \IteratorIterator(
new \ArrayIterator([$frontendAction]));
135 ->method(
'getIterator')
137 $this->entityManagerMock->expects($this->once())
139 ->with($frontendAction);
140 $this->productFrontendActionFactoryMock->expects($this->exactly(2))
146 'visitor_id' =>
null,
150 'type_id' =>
'recently_compared_product' 157 'visitor_id' =>
null,
161 'type_id' =>
'recently_compared_product' 166 ->willReturnOnConsecutiveCalls($action1, $action2);
167 $this->entityManagerMock->expects($this->exactly(2))
169 ->withConsecutive([$action1], [$action2]);
170 $this->model->syncActions(
$productsData,
'recently_compared_product');
testFilterProductActions()
$frontendStorageConfigurationPoolMock
$productFrontendActionFactoryMock