@@ -98,17 +98,17 @@ protected function setUp(): void
98
98
* @param MockObject|Http $requestMock
99
99
* @param string $defaultPath
100
100
* @param string $moduleFrontName
101
- * @param string $actionPath
102
- * @param string $actionName
103
- * @param string $moduleName
101
+ * @param string|null $actionPath
102
+ * @param string|null $actionName
103
+ * @param string|null $moduleName
104
104
*/
105
105
public function testMatch (
106
106
MockObject $ requestMock ,
107
107
string $ defaultPath ,
108
108
string $ moduleFrontName ,
109
- string $ actionPath ,
110
- string $ actionName ,
111
- string $ moduleName
109
+ ? string $ actionPath ,
110
+ ? string $ actionName ,
111
+ ? string $ moduleName
112
112
) {
113
113
$ actionInstance = 'Magento_TestFramework_ActionInstance ' ;
114
114
@@ -153,87 +153,143 @@ public function matchDataProvider(): array
153
153
$ actionPath = 'action_path ' ;
154
154
$ actionName = 'action_name ' ;
155
155
$ moduleName = 'module_name ' ;
156
- $ paramList = $ moduleFrontName . '/ ' . $ actionPath . '/ ' . $ actionName . '/key/val/key2/val2/ ' ;
157
156
158
157
$ requestMock = $ this ->createMock (Http::class);
159
158
$ requestMock ->expects ($ this ->atLeastOnce ())->method ('getModuleName ' )->willReturn ($ moduleFrontName );
160
159
$ requestMock ->expects ($ this ->atLeastOnce ())->method ('getControllerName ' )->willReturn ($ actionPath );
161
160
$ requestMock ->expects ($ this ->atLeastOnce ())->method ('getActionName ' )->willReturn ($ actionName );
162
- $ requestMock ->expects ($ this ->atLeastOnce ())->method ('getPathInfo ' )->willReturn ($ paramList );
161
+ $ requestMock ->expects ($ this ->atLeastOnce ())
162
+ ->method ('getPathInfo ' )
163
+ ->willReturn ($ moduleFrontName . '/ ' . $ actionPath . '/ ' . $ actionName . '/key/val/key2/val2/ ' );
163
164
164
165
$ emptyRequestMock = $ this ->createMock (Http::class);
165
166
$ emptyRequestMock ->expects ($ this ->atLeastOnce ())->method ('getModuleName ' )->willReturn ('' );
166
167
$ emptyRequestMock ->expects ($ this ->atLeastOnce ())->method ('getControllerName ' )->willReturn ('' );
167
168
$ emptyRequestMock ->expects ($ this ->atLeastOnce ())->method ('getActionName ' )->willReturn ('' );
168
169
$ emptyRequestMock ->expects ($ this ->atLeastOnce ())->method ('getPathInfo ' )->willReturn ('' );
169
170
170
- $ emptyRequestMock2 = clone $ emptyRequestMock ;
171
- $ emptyRequestMock2 ->expects ($ this ->once ())->method ('getOriginalPathInfo ' )->willReturn ('' );
171
+ $ emptyRequestMock2 = $ this ->createMock (Http::class);
172
+ $ emptyRequestMock2 ->expects ($ this ->atLeastOnce ())->method ('getModuleName ' )->willReturn ('' );
173
+ $ emptyRequestMock2 ->expects ($ this ->atLeastOnce ())->method ('getControllerName ' )->willReturn ('' );
174
+ $ emptyRequestMock2 ->expects ($ this ->atLeastOnce ())->method ('getActionName ' )->willReturn ('' );
175
+ $ emptyRequestMock2 ->expects ($ this ->atLeastOnce ())->method ('getPathInfo ' )->willReturn ('' );
176
+ $ emptyRequestMock2 ->expects ($ this ->atLeastOnce ())->method ('getOriginalPathInfo ' )->willReturn ('' );
172
177
173
178
return [
174
- [$ requestMock , '' , $ moduleFrontName , $ actionPath , $ actionName , $ moduleName ],
175
- [$ emptyRequestMock , $ paramList , $ moduleFrontName , $ actionPath , $ actionName , $ moduleName ],
176
- [$ emptyRequestMock2 , '' , $ moduleFrontName , $ actionPath , $ actionName , $ moduleName ],
179
+ [
180
+ $ requestMock ,
181
+ 'val1/val2/val3/ ' ,
182
+ $ moduleFrontName ,
183
+ $ actionPath ,
184
+ $ actionName ,
185
+ $ moduleName
186
+ ],
187
+ [
188
+ $ emptyRequestMock ,
189
+ $ moduleFrontName . '/ ' . $ actionPath . '/ ' . $ actionName . '/key/val/key2/val2/ ' ,
190
+ $ moduleFrontName ,
191
+ $ actionPath ,
192
+ $ actionName ,
193
+ $ moduleName
194
+ ],
195
+ [
196
+ $ emptyRequestMock2 ,
197
+ '' ,
198
+ $ moduleFrontName ,
199
+ $ actionPath ,
200
+ $ actionName ,
201
+ $ moduleName
202
+ ],
177
203
];
178
204
}
179
205
180
- public function testMatchEmptyModuleList ()
181
- {
182
- $ moduleFrontName = 'module front name ' ;
183
- $ actionPath = 'action path ' ;
184
- $ actionName = 'action name ' ;
185
- $ paramList = $ moduleFrontName . '/ ' . $ actionPath . '/ ' . $ actionName . '/key/val/key2/val2/ ' ;
206
+ /**
207
+ * @dataProvider matchEmptyActionDataProvider
208
+ * @param MockObject|Http $requestMock
209
+ * @param string $defaultPath
210
+ * @param string $moduleFrontName
211
+ * @param string|null $actionPath
212
+ * @param string|null $actionName
213
+ * @param string|null $moduleName
214
+ */
215
+ public function testMatchEmptyAction (
216
+ MockObject $ requestMock ,
217
+ string $ defaultPath ,
218
+ string $ moduleFrontName ,
219
+ ?string $ actionPath ,
220
+ ?string $ actionName ,
221
+ ?string $ moduleName
222
+ ) {
223
+ $ defaultReturnMap = [
224
+ ['module ' , $ moduleFrontName ],
225
+ ['controller ' , $ actionPath ],
226
+ ['action ' , $ actionName ],
227
+ ];
228
+ $ this ->defaultPathMock ->method ('getPart ' )
229
+ ->willReturnMap ($ defaultReturnMap );
230
+ $ this ->pathConfigMock ->method ('getDefaultPath ' )
231
+ ->willReturn ($ defaultPath );
186
232
187
- $ requestMock = $ this ->createMock (Http::class);
188
- $ requestMock ->expects ($ this ->atLeastOnce ())
189
- ->method ('getModuleName ' )
190
- ->willReturn ($ moduleFrontName );
191
- $ requestMock ->expects ($ this ->atLeastOnce ())
192
- ->method ('getPathInfo ' )
193
- ->willReturn ($ paramList );
194
233
$ this ->routeConfigMock ->expects ($ this ->once ())
195
234
->method ('getModulesByFrontName ' )
196
235
->with ($ moduleFrontName )
197
- ->willReturn ([]);
198
- $ this ->actionListMock ->expects ($ this ->never ())-> method ( ' get ' );
199
- $ this -> actionFactoryMock -> expects ( $ this -> never ()) ->method ('create ' );
236
+ ->willReturn ($ moduleName ? [ $ moduleName ] : []);
237
+ $ this ->actionFactoryMock ->expects ($ this ->never ())
238
+ ->method ('create ' );
200
239
201
240
$ this ->assertNull ($ this ->model ->match ($ requestMock ));
202
241
}
203
242
204
- public function testMatchEmptyActionInstance ()
243
+ public function matchEmptyActionDataProvider (): array
205
244
{
206
- $ moduleFrontName = 'module front name ' ;
207
- $ actionPath = 'action path ' ;
208
- $ actionName = 'action name ' ;
209
- $ moduleName = 'module name ' ;
210
- $ paramList = $ moduleFrontName . '/ ' . $ actionPath . '/ ' . $ actionName . '/key/val/key2/val2/ ' ;
245
+ $ moduleFrontName = 'module_front_name ' ;
246
+ $ actionPath = 'action_path ' ;
247
+ $ actionName = 'action_name ' ;
211
248
212
- $ requestMock = $ this ->createMock (Http::class);
213
- $ requestMock ->expects ($ this ->atLeastOnce ())
214
- -> method ('getModuleName ' )
215
- -> willReturn ($ moduleFrontName );
216
- $ requestMock ->expects ($ this ->atLeastOnce ())
249
+ $ requestMock1 = $ this ->createMock (Http::class);
250
+ $ requestMock1 ->expects ($ this ->atLeastOnce ())-> method ( ' getModuleName ' )-> willReturn ( $ moduleFrontName );
251
+ $ requestMock1 -> expects ( $ this -> atLeastOnce ())-> method ('getControllerName ' )-> willReturn ( $ actionPath );
252
+ $ requestMock1 -> expects ( $ this -> atLeastOnce ())-> method ( ' getActionName ' )-> willReturn ($ actionName );
253
+ $ requestMock1 ->expects ($ this ->atLeastOnce ())
217
254
->method ('getPathInfo ' )
218
- ->willReturn ($ paramList );
219
- $ requestMock ->expects ($ this ->atLeastOnce ())
220
- ->method ('getControllerName ' )
221
- ->willReturn ($ actionPath );
222
- $ requestMock ->expects ($ this ->once ())
223
- ->method ('getActionName ' )
224
- ->willReturn ($ actionName );
225
- $ this ->routeConfigMock ->expects ($ this ->once ())
226
- ->method ('getModulesByFrontName ' )
227
- ->with ($ moduleFrontName )
228
- ->willReturn ([$ moduleName ]);
229
- $ this ->actionListMock ->expects ($ this ->once ())
230
- ->method ('get ' )
231
- ->with ($ moduleName )
232
- ->willReturn (null );
233
- $ this ->actionFactoryMock ->expects ($ this ->never ())
234
- ->method ('create ' );
255
+ ->willReturn ($ moduleFrontName . '/ ' . $ actionPath . '/ ' . $ actionName . '/ ' );
235
256
236
- $ this ->assertNull ($ this ->model ->match ($ requestMock ));
257
+ $ requestMock2 = $ this ->createMock (Http::class);
258
+ $ requestMock2 ->expects ($ this ->atLeastOnce ())->method ('getModuleName ' )->willReturn ($ moduleFrontName );
259
+ $ requestMock2 ->expects ($ this ->atLeastOnce ())
260
+ ->method ('getPathInfo ' )
261
+ ->willReturn ($ moduleFrontName . '/ ' . $ actionPath . '/ ' . $ actionName . '/ ' );
262
+
263
+ $ requestMock3 = $ this ->createMock (Http::class);
264
+ $ requestMock3 ->expects ($ this ->atLeastOnce ())->method ('getModuleName ' )->willReturn ('' );
265
+ $ requestMock3 ->expects ($ this ->atLeastOnce ())->method ('getPathInfo ' )->willReturn ('0 ' );
266
+
267
+ return [
268
+ [
269
+ $ requestMock1 ,
270
+ '' ,
271
+ $ moduleFrontName ,
272
+ $ actionPath ,
273
+ $ actionName ,
274
+ 'module_name ' ,
275
+ ],
276
+ [
277
+ $ requestMock2 ,
278
+ '' ,
279
+ $ moduleFrontName ,
280
+ $ actionPath ,
281
+ $ actionName ,
282
+ null ,
283
+ ],
284
+ [
285
+ $ requestMock3 ,
286
+ $ moduleFrontName . '/ ' . $ actionPath . '/ ' . $ actionName . '/ ' ,
287
+ '0 ' ,
288
+ null ,
289
+ null ,
290
+ null
291
+ ],
292
+ ];
237
293
}
238
294
239
295
public function testGetActionClassName ()
0 commit comments