From e05b05a33b56561c85597ebf460aa2faf5977071 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 26 Oct 2011 22:27:19 -0500 Subject: [PATCH] added route loader tests. --- tests/Cases/Routing/RouteLoaderTest.php | 53 +++++++++++++++++++ tests/Fixtures/RouteLoader/routes.php | 15 ++++++ .../RouteLoader/routes/admin/panel.php | 15 ++++++ tests/Fixtures/RouteLoader/routes/user.php | 15 ++++++ tests/bootstrap.php | 14 +++++ 5 files changed, 112 insertions(+) create mode 100644 tests/Cases/Routing/RouteLoaderTest.php create mode 100644 tests/Fixtures/RouteLoader/routes.php create mode 100644 tests/Fixtures/RouteLoader/routes/admin/panel.php create mode 100644 tests/Fixtures/RouteLoader/routes/user.php diff --git a/tests/Cases/Routing/RouteLoaderTest.php b/tests/Cases/Routing/RouteLoaderTest.php new file mode 100644 index 00000000..4dae5d37 --- /dev/null +++ b/tests/Cases/Routing/RouteLoaderTest.php @@ -0,0 +1,53 @@ +getLoader(); + + $routes = $loader->load('/'); + + $this->assertEquals(count($routes), 2); + $this->assertTrue(array_key_exists('GET /', $routes)); + $this->assertTrue(array_key_exists('GET /root', $routes)); + } + + public function test_loader_can_load_single_nested_routes() + { + $loader = $this->getLoader(); + + $routes = $loader->load('user'); + + $this->assertEquals(count($routes), 4); + $this->assertTrue(array_key_exists('GET /user', $routes)); + $this->assertTrue(array_key_exists('GET /user/profile', $routes)); + } + + public function test_loader_can_load_multi_nested_routes() + { + $loader = $this->getLoader(); + + $routes = $loader->load('admin/panel'); + + $this->assertEquals(count($routes), 4); + $this->assertTrue(array_key_exists('GET /admin/panel/show', $routes)); + $this->assertTrue(array_key_exists('GET /admin/panel/update', $routes)); + } + + public function test_everything_loads_all_routes() + { + $loader = $this->getLoader(); + + $routes = $loader->everything(); + + $this->assertEquals(count($routes), 6); + + } + + private function getLoader() + { + return new Loader(FIXTURE_PATH.'RouteLoader/', FIXTURE_PATH.'RouteLoader/routes/'); + } + +} diff --git a/tests/Fixtures/RouteLoader/routes.php b/tests/Fixtures/RouteLoader/routes.php new file mode 100644 index 00000000..473f3bd6 --- /dev/null +++ b/tests/Fixtures/RouteLoader/routes.php @@ -0,0 +1,15 @@ + function() + { + return 'GET /'; + }, + + 'GET /root' => function() + { + return 'GET /root'; + }, + +); \ No newline at end of file diff --git a/tests/Fixtures/RouteLoader/routes/admin/panel.php b/tests/Fixtures/RouteLoader/routes/admin/panel.php new file mode 100644 index 00000000..4ba3b3c8 --- /dev/null +++ b/tests/Fixtures/RouteLoader/routes/admin/panel.php @@ -0,0 +1,15 @@ + function() + { + return 'GET /admin/panel/show'; + }, + + 'GET /admin/panel/update' => function() + { + return 'GET /admin/panel/update'; + }, + +); \ No newline at end of file diff --git a/tests/Fixtures/RouteLoader/routes/user.php b/tests/Fixtures/RouteLoader/routes/user.php new file mode 100644 index 00000000..156b97cf --- /dev/null +++ b/tests/Fixtures/RouteLoader/routes/user.php @@ -0,0 +1,15 @@ + function() + { + return 'GET /user'; + }, + + 'GET /user/profile' => function() + { + return 'GET /user/profile'; + }, + +); \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ac6f6122..b594d0b8 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -23,4 +23,18 @@ $storage = '../storage'; $public = '../public'; +/* +|-------------------------------------------------------------------------- +| Test Path Constants +|-------------------------------------------------------------------------- +*/ + +define('FIXTURE_PATH', realpath('Fixtures').'/'); + +/* +|-------------------------------------------------------------------------- +| Bootstrap The Laravel Core +|-------------------------------------------------------------------------- +*/ + require realpath($laravel).'/bootstrap/core.php'; \ No newline at end of file