@@ -1225,6 +1225,92 @@ public function testViewActionCanBeAccessed()
12251225 $ this ->assertActionName ('view ' );
12261226 }
12271227
1228+ /**
1229+ * @dataProvider providerTakenUrls
1230+ *
1231+ * @param string $url
1232+ */
1233+ public function testViewActionIsNotDispatchedToIfUrlIsTaken ($ url )
1234+ {
1235+ $ moduleMapper = $ this ->getMockBuilder (Mapper \Module::class)
1236+ ->disableOriginalConstructor ()
1237+ ->getMock ()
1238+ ;
1239+
1240+ $ moduleMapper
1241+ ->expects ($ this ->any ())
1242+ ->method ('findByName ' )
1243+ ->willReturn (new Entity \Module ())
1244+ ;
1245+
1246+ $ repositoryRetriever = $ this ->getMockBuilder (RepositoryRetriever::class)
1247+ ->disableOriginalConstructor ()
1248+ ->getMock ()
1249+ ;
1250+
1251+ $ repositoryRetriever
1252+ ->expects ($ this ->any ())
1253+ ->method ('getUserRepositoryMetadata ' )
1254+ ->willReturn (new stdClass ())
1255+ ;
1256+
1257+ $ this ->getApplicationServiceLocator ()
1258+ ->setAllowOverride (true )
1259+ ->setService (
1260+ Mapper \Module::class,
1261+ $ moduleMapper
1262+ )
1263+ ->setService (
1264+ RepositoryRetriever::class,
1265+ $ repositoryRetriever
1266+ )
1267+ ;
1268+
1269+ $ this ->dispatch ($ url );
1270+
1271+ $ routeMatch = $ this ->getApplication ()->getMvcEvent ()->getRouteMatch ();
1272+
1273+ $ controller = $ routeMatch ->getParam ('controller ' );
1274+ $ action = $ routeMatch ->getParam ('action ' );
1275+
1276+ $ unexpectedController = Controller \ModuleController::class;
1277+ $ unexpectedAction = 'view ' ;
1278+
1279+ $ isController = strtolower ($ controller ) === strtolower ($ unexpectedController );
1280+ $ isAction = strtolower ($ action ) === $ unexpectedAction ;
1281+
1282+ $ this ->assertFalse (
1283+ $ isController && $ isAction ,
1284+ sprintf (
1285+ 'Failed to assert that the url "%s" is not dispatched to "%s::%sAction()" ' ,
1286+ $ url ,
1287+ $ unexpectedController ,
1288+ $ unexpectedAction
1289+ )
1290+ );
1291+ }
1292+
1293+ /**
1294+ * @return array
1295+ */
1296+ public function providerTakenUrls ()
1297+ {
1298+ return [
1299+ [
1300+ '/module/add ' ,
1301+ ],
1302+ [
1303+ '/module/list ' ,
1304+ ],
1305+ [
1306+ '/module/remove ' ,
1307+ ],
1308+ [
1309+ '/user/anyone ' ,
1310+ ],
1311+ ];
1312+ }
1313+
12281314 /**
12291315 * @link http://stackoverflow.com/a/15907250
12301316 *
0 commit comments