From 73835118550f4bf9c0df510283c905f89224d612 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 4 Apr 2019 07:30:48 -0400 Subject: [PATCH] Added test case for Router->getModuleClass --- tests/src/App/RouterTest.php | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/src/App/RouterTest.php diff --git a/tests/src/App/RouterTest.php b/tests/src/App/RouterTest.php new file mode 100644 index 0000000000..5a573bda95 --- /dev/null +++ b/tests/src/App/RouterTest.php @@ -0,0 +1,42 @@ +getRouteCollector(); + $routeCollector->addRoute(['GET'], '/', 'IndexModuleClassName'); + $routeCollector->addRoute(['GET'], '/test', 'TestModuleClassName'); + $routeCollector->addRoute(['GET'], '/test/sub', 'TestSubModuleClassName'); + $routeCollector->addRoute(['GET'], '/optional[/option]', 'OptionalModuleClassName'); + $routeCollector->addRoute(['GET'], '/variable/{var}', 'VariableModuleClassName'); + $routeCollector->addRoute(['GET'], '/optionalvariable[/{option}]', 'OptionalVariableModuleClassName'); + $routeCollector->addRoute(['POST', 'PUT', 'PATCH', 'DELETE', 'HEAD'], '/unsupported', 'UnsupportedMethodModuleClassName'); + + $this->assertEquals('IndexModuleClassName', $router->getModuleClass('/')); + + $this->assertEquals('TestModuleClassName', $router->getModuleClass('/test')); + $this->assertNull($router->getModuleClass('/tes')); + + $this->assertEquals('TestSubModuleClassName', $router->getModuleClass('/test/sub')); + + $this->assertEquals('OptionalModuleClassName', $router->getModuleClass('/optional')); + $this->assertEquals('OptionalModuleClassName', $router->getModuleClass('/optional/option')); + $this->assertNull($router->getModuleClass('/optional/opt')); + + $this->assertEquals('VariableModuleClassName', $router->getModuleClass('/variable/123abc')); + $this->assertNull($router->getModuleClass('/variable')); + + $this->assertEquals('OptionalVariableModuleClassName', $router->getModuleClass('/optionalvariable')); + $this->assertEquals('OptionalVariableModuleClassName', $router->getModuleClass('/optionalvariable/123abc')); + + $this->assertNull($router->getModuleClass('/unsupported')); + } +} -- 2.39.5