public function testDispatcherShouldRunRouteWithoutInvocingController() { $routes = new \Nano\Routes(); $route = new TestRunnableRouteAbstract(); $routes->addRoute('get', $route); $_SERVER['REQUEST_METHOD'] = 'get'; self::assertFalse($route->wasRun()); self::assertNull($this->application->dispatcher->dispatch($routes, TestRunnableRouteAbstract::LOCATION)); self::assertTrue($route->wasRun()); }
public function testDetectingContextBySuffix() { Nano::setApplication(null); $application = new \Nano\Application(); $application->withConfigurationFormat('php')->withRootDir($this->files->get($this, ''))->configure(); $application->dispatcher->setResponse(new \Nano\Controller\Response\Test($application)); $_SERVER['REQUEST_METHOD'] = 'GET'; $routes = new \Nano\Routes(); $routes->suffix('~(\\.(?P<context>xml|rss))?')->get('index', 'test', 'index'); self::assertInstanceOf('Nano\\Route\\RegExp', $application->dispatcher->getRoute($routes, 'index.xml')); $application->dispatcher->run($application->dispatcher->getRoute($routes, 'index.xml')); self::assertEquals('xml', $application->dispatcher->controllerInstance()->context); }
public function testModuleRoutes() { $this->application->withConfigurationFormat('php')->withModule('test', $this->files->get($this, '/test'))->configure(); $routes = new \Nano\Routes(); $route = \Nano\Route\Common::create('some', 'class1', 'index', 'test'); $dispatcher = $this->application->dispatcher; $response = new \Nano\Controller\Response\Test($this->application); $dispatcher->setResponse($response); $routes->addRoute('get', $route); self::assertNotNull($dispatcher->getRoute($routes, '/some')); self::assertEquals($route->controller(), $dispatcher->getRoute($routes, '/some')->controller()); self::assertEquals($route->action(), $dispatcher->getRoute($routes, '/some')->action()); self::assertInstanceOf('Module\\Test\\Controller\\Class1', $dispatcher->getController($route)); $dispatcher->dispatch($routes, '/some'); self::assertTrue(class_exists('Module\\Test\\Controller\\Class1', false)); self::assertEquals(Module\Test\Controller\Class1::name(), $response->getBody()); }