@@ -78,27 +78,20 @@ protected function setUp()
78
78
);
79
79
}
80
80
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 )
82
89
{
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
- ];
97
90
$ frontendConfiguration = $ this ->createMock (\Magento \Catalog \Model \FrontendStorageConfigurationInterface::class);
98
91
$ frontendConfiguration ->expects ($ this ->once ())
99
92
->method ('get ' )
100
93
->willReturn ([
101
- 'lifetime ' => 2
94
+ 'lifetime ' => 2 ,
102
95
]);
103
96
$ this ->frontendStorageConfigurationPoolMock ->expects ($ this ->once ())
104
97
->method ('get ' )
@@ -110,7 +103,6 @@ public function testFilterProductActions()
110
103
$ action2 = $ this ->getMockBuilder (ProductFrontendActionInterface::class)
111
104
->getMockForAbstractClass ();
112
105
113
- $ frontendAction = $ this ->createMock (ProductFrontendActionInterface::class);
114
106
$ collection = $ this ->getMockBuilder (Collection::class)
115
107
->disableOriginalConstructor ()
116
108
->getMock ();
@@ -126,47 +118,91 @@ public function testFilterProductActions()
126
118
$ collection ->expects ($ this ->once ())
127
119
->method ('addFilterByUserIdentities ' )
128
120
->with (1 , 34 );
129
- $ collection ->expects ($ this ->any ())
130
- ->method ('addFieldToFilter ' )
131
- ->withConsecutive (['type_id ' ], ['product_id ' ]);
132
121
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 (
144
140
[
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
+ ],
155
151
[
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
+ ],
163
161
]
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
+
170
171
$ this ->model ->syncActions ($ productsData , 'recently_compared_product ' );
171
172
}
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
+ }
172
208
}
0 commit comments