From 23f167acc7c955cc7e0ef49fbc09806f68e375ec Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 13 Jul 2011 23:38:18 -0500 Subject: [PATCH] added route finder tests. --- tests/suite/RouteFinderTest.php | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/suite/RouteFinderTest.php diff --git a/tests/suite/RouteFinderTest.php b/tests/suite/RouteFinderTest.php new file mode 100644 index 00000000..988fad6b --- /dev/null +++ b/tests/suite/RouteFinderTest.php @@ -0,0 +1,42 @@ + array('name' => 'home', 'do' => function() {})); + $routes['GET /user'] = array('GET /user' => array('name' => 'user', 'do' => function() {})); + + System\Route\Finder::$routes = $routes; + } + + public function testRouteFinderReturnsNullWhenRouteIsNotFound() + { + $this->assertNull(System\Route\Finder::find('doesnt-exist')); + } + + public function testRouteFinderReturnsRouteWhenFoundInSingleRoutesFile() + { + $this->assertArrayHasKey('GET /home', System\Route\Finder::find('home')); + $this->assertArrayHasKey('GET /user', System\Route\Finder::find('user')); + } + + public function testRouteFinderLoadsRoutesFromRouteDirectoryToFindRoutes() + { + System\Route\Finder::$routes = null; + $this->setupRoutesDirectory(); + + $this->assertArrayHasKey('GET /user', System\Route\Finder::find('user')); + + Utils::rrmdir(APP_PATH.'routes'); + } + + private function setupRoutesDirectory() + { + mkdir(APP_PATH.'routes', 0777); + file_put_contents(APP_PATH.'routes/user.php', " array('name' => 'user', 'do' => function() {return '/user';})); ?>", LOCK_EX); + } + +} \ No newline at end of file