added route loader tests.
This commit is contained in:
53
tests/Cases/Routing/RouteLoaderTest.php
Normal file
53
tests/Cases/Routing/RouteLoaderTest.php
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?php use Laravel\Routing\Loader;
|
||||||
|
|
||||||
|
class RouteLoaderTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
public function test_loader_can_load_base_routes()
|
||||||
|
{
|
||||||
|
$loader = $this->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/');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
15
tests/Fixtures/RouteLoader/routes.php
Normal file
15
tests/Fixtures/RouteLoader/routes.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return array(
|
||||||
|
|
||||||
|
'GET /' => function()
|
||||||
|
{
|
||||||
|
return 'GET /';
|
||||||
|
},
|
||||||
|
|
||||||
|
'GET /root' => function()
|
||||||
|
{
|
||||||
|
return 'GET /root';
|
||||||
|
},
|
||||||
|
|
||||||
|
);
|
||||||
15
tests/Fixtures/RouteLoader/routes/admin/panel.php
Normal file
15
tests/Fixtures/RouteLoader/routes/admin/panel.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return array(
|
||||||
|
|
||||||
|
'GET /admin/panel/show' => function()
|
||||||
|
{
|
||||||
|
return 'GET /admin/panel/show';
|
||||||
|
},
|
||||||
|
|
||||||
|
'GET /admin/panel/update' => function()
|
||||||
|
{
|
||||||
|
return 'GET /admin/panel/update';
|
||||||
|
},
|
||||||
|
|
||||||
|
);
|
||||||
15
tests/Fixtures/RouteLoader/routes/user.php
Normal file
15
tests/Fixtures/RouteLoader/routes/user.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return array(
|
||||||
|
|
||||||
|
'GET /user' => function()
|
||||||
|
{
|
||||||
|
return 'GET /user';
|
||||||
|
},
|
||||||
|
|
||||||
|
'GET /user/profile' => function()
|
||||||
|
{
|
||||||
|
return 'GET /user/profile';
|
||||||
|
},
|
||||||
|
|
||||||
|
);
|
||||||
@@ -23,4 +23,18 @@ $storage = '../storage';
|
|||||||
|
|
||||||
$public = '../public';
|
$public = '../public';
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Test Path Constants
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
define('FIXTURE_PATH', realpath('Fixtures').'/');
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Bootstrap The Laravel Core
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
require realpath($laravel).'/bootstrap/core.php';
|
require realpath($laravel).'/bootstrap/core.php';
|
||||||
Reference in New Issue
Block a user