@@ -19,6 +19,12 @@ class SynchronizerTest extends \PHPUnit\Framework\TestCase
19
19
*/
20
20
private $ synchronizer ;
21
21
22
+ /** @var Session */
23
+ private $ session ;
24
+
25
+ /** @var Visitor */
26
+ private $ visitor ;
27
+
22
28
/**
23
29
* @var ProductRepository
24
30
*/
@@ -30,6 +36,8 @@ class SynchronizerTest extends \PHPUnit\Framework\TestCase
30
36
protected function setUp (): void
31
37
{
32
38
$ 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);
33
41
34
42
$ this ->synchronizer = $ objectManager ->get (Synchronizer::class);
35
43
$ this ->productRepository = $ objectManager ->get (ProductRepository::class);
@@ -110,4 +118,84 @@ public function testSyncActionsWithoutActionsType(): void
110
118
111
119
$ this ->synchronizer ->syncActions ($ productsData , '' );
112
120
}
121
+
122
+ /**
123
+ * @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
+ /**
134
+ * @magentoDataFixture Magento/Catalog/_files/product_simple.php
135
+ * @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
136
+ *
137
+ * @return void
138
+ * @throws \Magento\Framework\Exception\LocalizedException
139
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
140
+ */
141
+ public function testGetAllActionsOfVisitor (): void
142
+ {
143
+ $ this ->visitor ->setId (123 );
144
+ $ actionsType = 'recently_viewed_product ' ;
145
+ $ productScope = 'website ' ;
146
+ $ scopeId = 1 ;
147
+ $ product1 = $ this ->productRepository ->get ('simple ' );
148
+ $ product2 = $ this ->productRepository ->get ('simple2 ' );
149
+ $ product1Id = $ product1 ->getId ();
150
+ $ product2Id = $ product2 ->getId ();
151
+ $ productsData = [
152
+ $ productScope . '- ' . $ scopeId . '- ' . $ product1Id => [
153
+ 'added_at ' => '1576582660 ' ,
154
+ 'product_id ' => $ product1Id ,
155
+ ],
156
+ $ productScope . '- ' . $ scopeId . '- ' . $ product2Id => [
157
+ 'added_at ' => '1576587153 ' ,
158
+ 'product_id ' => $ product2Id ,
159
+ ],
160
+ ];
161
+
162
+ $ this ->synchronizer ->syncActions ($ productsData , $ actionsType );
163
+ $ collection = $ this ->synchronizer ->getAllActions ();
164
+ $ this ->assertEquals ($ collection ->getSize (), 2 );
165
+ }
166
+
167
+ /**
168
+ * @magentoDataFixture Magento/Catalog/_files/product_simple.php
169
+ * @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
170
+ *
171
+ * @return void
172
+ * @throws \Magento\Framework\Exception\LocalizedException
173
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
174
+ */
175
+ public function testGetAllActionsOfCustomer (): void
176
+ {
177
+ $ this ->session ->setCustomerId (1 );
178
+ $ this ->visitor ->setId (null );
179
+ $ actionsType = 'recently_viewed_product ' ;
180
+ $ productScope = 'website ' ;
181
+ $ scopeId = 1 ;
182
+ $ product1 = $ this ->productRepository ->get ('simple ' );
183
+ $ product2 = $ this ->productRepository ->get ('simple2 ' );
184
+ $ product1Id = $ product1 ->getId ();
185
+ $ product2Id = $ product2 ->getId ();
186
+ $ productsData = [
187
+ $ productScope . '- ' . $ scopeId . '- ' . $ product1Id => [
188
+ 'added_at ' => '1576582660 ' ,
189
+ 'product_id ' => $ product1Id ,
190
+ ],
191
+ $ productScope . '- ' . $ scopeId . '- ' . $ product2Id => [
192
+ 'added_at ' => '1576587153 ' ,
193
+ 'product_id ' => $ product2Id ,
194
+ ],
195
+ ];
196
+
197
+ $ this ->synchronizer ->syncActions ($ productsData , $ actionsType );
198
+ $ collection = $ this ->synchronizer ->getAllActions ();
199
+ $ this ->assertEquals ($ collection ->getSize (), 2 );
200
+ }
113
201
}
0 commit comments