- $this->lock = Mockery::mock(ILock::class);
- }
-
- public function testGetModuleClass()
- {
- $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache, $this->lock);
-
- $routeCollector = $router->getRouteCollector();
- $routeCollector->addRoute([Router::GET], '/', 'IndexModuleClassName');
- $routeCollector->addRoute([Router::GET], '/test', 'TestModuleClassName');
- $routeCollector->addRoute([Router::GET, Router::POST], '/testgetpost', 'TestGetPostModuleClassName');
- $routeCollector->addRoute([Router::GET], '/test/sub', 'TestSubModuleClassName');
- $routeCollector->addRoute([Router::GET], '/optional[/option]', 'OptionalModuleClassName');
- $routeCollector->addRoute([Router::GET], '/variable/{var}', 'VariableModuleClassName');
- $routeCollector->addRoute([Router::GET], '/optionalvariable[/{option}]', 'OptionalVariableModuleClassName');
-
- self::assertEquals('IndexModuleClassName', $router->getModuleClass('/'));
- self::assertEquals('TestModuleClassName', $router->getModuleClass('/test'));
- self::assertEquals('TestGetPostModuleClassName', $router->getModuleClass('/testgetpost'));
- self::assertEquals('TestSubModuleClassName', $router->getModuleClass('/test/sub'));
- self::assertEquals('OptionalModuleClassName', $router->getModuleClass('/optional'));
- self::assertEquals('OptionalModuleClassName', $router->getModuleClass('/optional/option'));
- self::assertEquals('VariableModuleClassName', $router->getModuleClass('/variable/123abc'));
- self::assertEquals('OptionalVariableModuleClassName', $router->getModuleClass('/optionalvariable'));
- self::assertEquals('OptionalVariableModuleClassName', $router->getModuleClass('/optionalvariable/123abc'));
- }
-
- public function testPostModuleClass()
- {
- $router = new Router(['REQUEST_METHOD' => Router::POST], '', $this->l10n, $this->cache, $this->lock);
-
- $routeCollector = $router->getRouteCollector();
- $routeCollector->addRoute([Router::POST], '/', 'IndexModuleClassName');
- $routeCollector->addRoute([Router::POST], '/test', 'TestModuleClassName');
- $routeCollector->addRoute([Router::GET, Router::POST], '/testgetpost', 'TestGetPostModuleClassName');
- $routeCollector->addRoute([Router::POST], '/test/sub', 'TestSubModuleClassName');
- $routeCollector->addRoute([Router::POST], '/optional[/option]', 'OptionalModuleClassName');
- $routeCollector->addRoute([Router::POST], '/variable/{var}', 'VariableModuleClassName');
- $routeCollector->addRoute([Router::POST], '/optionalvariable[/{option}]', 'OptionalVariableModuleClassName');
-
- self::assertEquals('IndexModuleClassName', $router->getModuleClass('/'));
- self::assertEquals('TestModuleClassName', $router->getModuleClass('/test'));
- self::assertEquals('TestGetPostModuleClassName', $router->getModuleClass('/testgetpost'));
- self::assertEquals('TestSubModuleClassName', $router->getModuleClass('/test/sub'));
- self::assertEquals('OptionalModuleClassName', $router->getModuleClass('/optional'));
- self::assertEquals('OptionalModuleClassName', $router->getModuleClass('/optional/option'));
- self::assertEquals('VariableModuleClassName', $router->getModuleClass('/variable/123abc'));
- self::assertEquals('OptionalVariableModuleClassName', $router->getModuleClass('/optionalvariable'));
- self::assertEquals('OptionalVariableModuleClassName', $router->getModuleClass('/optionalvariable/123abc'));
- }
-
- public function testGetModuleClassNotFound()
- {
- $this->expectException(NotFoundException::class);
-
- $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache, $this->lock);
-
- $router->getModuleClass('/unsupported');
- }
-
- public function testGetModuleClassNotFoundTypo()
- {
- $this->expectException(NotFoundException::class);
-
- $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache, $this->lock);
-
- $routeCollector = $router->getRouteCollector();
- $routeCollector->addRoute([Router::GET], '/test', 'TestModuleClassName');
-
- $router->getModuleClass('/tes');
- }
-
- public function testGetModuleClassNotFoundOptional()
- {
- $this->expectException(NotFoundException::class);