@@ -78,27 +78,19 @@ protected function setUp()
78
78
);
79
79
}
80
80
81
- public function testFilterProductActions ()
81
+ /**
82
+ * @dataProvider filterProductActionsDataProvider
83
+ *
84
+ * @param $productsData
85
+ * @return void
86
+ */
87
+ public function testFilterProductActions ($ productsData , $ correct )
82
88
{
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
89
$ frontendConfiguration = $ this ->createMock (\Magento \Catalog \Model \FrontendStorageConfigurationInterface::class);
98
90
$ frontendConfiguration ->expects ($ this ->once ())
99
91
->method ('get ' )
100
92
->willReturn ([
101
- 'lifetime ' => 2
93
+ 'lifetime ' => 2 ,
102
94
]);
103
95
$ this ->frontendStorageConfigurationPoolMock ->expects ($ this ->once ())
104
96
->method ('get ' )
@@ -110,7 +102,6 @@ public function testFilterProductActions()
110
102
$ action2 = $ this ->getMockBuilder (ProductFrontendActionInterface::class)
111
103
->getMockForAbstractClass ();
112
104
113
- $ frontendAction = $ this ->createMock (ProductFrontendActionInterface::class);
114
105
$ collection = $ this ->getMockBuilder (Collection::class)
115
106
->disableOriginalConstructor ()
116
107
->getMock ();
@@ -126,47 +117,86 @@ public function testFilterProductActions()
126
117
$ collection ->expects ($ this ->once ())
127
118
->method ('addFilterByUserIdentities ' )
128
119
->with (1 , 34 );
129
- $ collection ->expects ($ this ->any ())
130
- ->method ('addFieldToFilter ' )
131
- ->withConsecutive (['type_id ' ], ['product_id ' ]);
132
120
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
- [
121
+ if ($ correct ) {
122
+ $ frontendAction = $ this ->createMock (ProductFrontendActionInterface::class);
123
+ $ iterator = new \IteratorIterator (new \ArrayIterator ([$ frontendAction ]));
124
+ $ collection ->expects ($ this ->any ())
125
+ ->method ('addFieldToFilter ' )
126
+ ->withConsecutive (['type_id ' ], ['product_id ' ]);
127
+ $ collection ->expects ($ this ->once ())
128
+ ->method ('getIterator ' )
129
+ ->willReturn ($ iterator );
130
+ $ this ->entityManagerMock ->expects ($ this ->once ())
131
+ ->method ('delete ' )
132
+ ->with ($ frontendAction );
133
+ $ this ->entityManagerMock ->expects ($ this ->exactly (2 ))
134
+ ->method ('save ' )
135
+ ->withConsecutive ([$ action1 ], [$ action2 ]);
136
+ $ this ->productFrontendActionFactoryMock ->expects ($ this ->exactly (2 ))
137
+ ->method ('create ' )
138
+ ->withConsecutive (
144
139
[
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
- [
140
+ [
141
+ 'data ' => [
142
+ ' visitor_id ' => null ,
143
+ ' customer_id ' => 1 ,
144
+ ' added_at ' => 12 ,
145
+ ' product_id ' => 1 ,
146
+ ' type_id ' => ' recently_compared_product ' ,
147
+ ],
148
+ ],
149
+ ],
155
150
[
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
- ]
151
+ [
152
+ 'data ' => [
153
+ 'visitor_id ' => null ,
154
+ 'customer_id ' => 1 ,
155
+ 'added_at ' => 13 ,
156
+ 'product_id ' => 2 ,
157
+ 'type_id ' => 'recently_compared_product ' ,
158
+ ],
159
+ ],
163
160
]
164
- ]
165
- )
166
- ->willReturnOnConsecutiveCalls ($ action1 , $ action2 );
167
- $ this ->entityManagerMock ->expects ($ this ->exactly (2 ))
168
- ->method ('save ' )
169
- ->withConsecutive ([$ action1 ], [$ action2 ]);
161
+ )
162
+ ->willReturnOnConsecutiveCalls ($ action1 , $ action2 );
163
+ }
164
+
170
165
$ this ->model ->syncActions ($ productsData , 'recently_compared_product ' );
171
166
}
167
+
168
+ /**
169
+ * @return array
170
+ */
171
+ public function filterProductActionsDataProvider (): array
172
+ {
173
+ return [
174
+ [
175
+ 'productsData ' => [
176
+ 1 => [
177
+ 'added_at ' => 12 ,
178
+ 'product_id ' => 1 ,
179
+ ],
180
+ 2 => [
181
+ 'added_at ' => 13 ,
182
+ 'product_id ' => 2 ,
183
+ ],
184
+ 3 => [
185
+ 'added_at ' => 14 ,
186
+ 'product_id ' => 3 ,
187
+ ],
188
+ ],
189
+ 'correct ' => true ,
190
+ ],
191
+ [
192
+ 'productsData ' => [
193
+ 1 => [
194
+ 'added_at ' => 12 ,
195
+ 'product_id ' => 'test ' ,
196
+ ],
197
+ ],
198
+ 'correct ' => false ,
199
+ ],
200
+ ];
201
+ }
172
202
}
0 commit comments