|
|
@ -62,66 +62,48 @@ class RouterTest extends PHPUnit_Framework_TestCase |
|
|
|
$this->assertAttributeEquals('userLayout', 'default_layout', $router); |
|
|
|
} |
|
|
|
|
|
|
|
public function testGetRoute() |
|
|
|
public function testGetRouteWithNameIsNull() |
|
|
|
{ |
|
|
|
$name = null; |
|
|
|
$route = 'route object.'; |
|
|
|
$router = new Router(); |
|
|
|
$reflection = new ReflectionProperty('Router', 'route'); |
|
|
|
$reflection->setAccessible(true); |
|
|
|
$reflection->setValue($router, $route); |
|
|
|
$this->assertEquals($route, $router->getRoute()); |
|
|
|
} |
|
|
|
|
|
|
|
public function testGetUriWithNameIsNull() |
|
|
|
{ |
|
|
|
$name = null; |
|
|
|
$uri = 'uri from route.'; |
|
|
|
$route_mock = $this->getMockBuilder('Route') |
|
|
|
->disableOriginalConstructor() |
|
|
|
->setMethods(array('getUri')) |
|
|
|
->getMock(); |
|
|
|
$route_mock->expects($this->once()) |
|
|
|
->method('getUri') |
|
|
|
->with() |
|
|
|
->will($this->returnValue($uri)); |
|
|
|
$router = new Router(); |
|
|
|
$reflection = new ReflectionProperty('Router', 'route'); |
|
|
|
$reflection->setAccessible(true); |
|
|
|
$reflection->setValue($router, $route_mock); |
|
|
|
$this->assertEquals($uri, $router->getUri($name)); |
|
|
|
$this->assertEquals($route, $router->getRoute($name)); |
|
|
|
} |
|
|
|
|
|
|
|
public function testGetUriWithNamed() |
|
|
|
public function testGetRouteWithNamed() |
|
|
|
{ |
|
|
|
$name = 'nameofroute'; |
|
|
|
$uri = 'uri from route.'; |
|
|
|
$route_mock = $this->getMockBuilder('Route') |
|
|
|
->disableOriginalConstructor() |
|
|
|
->setMethods(array('getUri')) |
|
|
|
->getMock(); |
|
|
|
$route_mock->expects($this->once()) |
|
|
|
->method('getUri') |
|
|
|
->with() |
|
|
|
->will($this->returnValue($uri)); |
|
|
|
$route = 'route object.'; |
|
|
|
$router = new Router(); |
|
|
|
$reflection = new ReflectionProperty('Router', 'routes'); |
|
|
|
$reflection->setAccessible(true); |
|
|
|
$reflection->setValue($router, array($name => $route_mock)); |
|
|
|
$this->assertEquals($uri, $router->getUri($name)); |
|
|
|
$reflection->setValue($router, array($name => $route)); |
|
|
|
$this->assertEquals($route, $router->getRoute($name)); |
|
|
|
} |
|
|
|
|
|
|
|
public function testGetUriWithNamedWithError() |
|
|
|
public function testGetRouteWithNamedWithError() |
|
|
|
{ |
|
|
|
$name = 'name of route'; |
|
|
|
$router_mock = $this->getMockBuilder('Router') |
|
|
|
->disableOriginalConstructor() |
|
|
|
->setMethods(array('getRoute', 'getRouteByName')) |
|
|
|
->getMock(); |
|
|
|
$router_mock->expects($this->never()) |
|
|
|
->method('getRoute'); |
|
|
|
$router_mock->expects($this->never()) |
|
|
|
->method('getRouteByName'); |
|
|
|
$router = new Router(); |
|
|
|
$this->setExpectedException('ErrorException'); |
|
|
|
$router_mock->getUri($name); |
|
|
|
$router->getRoute($name); |
|
|
|
} |
|
|
|
|
|
|
|
public function testRouteIsExists() |
|
|
|
{ |
|
|
|
$route = 'route object.'; |
|
|
|
$name = 'nameofroute'; |
|
|
|
$name_is_not_exists = 'nameofroutenotexists'; |
|
|
|
$routes = array($name => $route); |
|
|
|
$router = new Router(); |
|
|
|
$reflection = new ReflectionProperty('Router', 'routes'); |
|
|
|
$reflection->setAccessible(true); |
|
|
|
$reflection->setValue($router, $routes); |
|
|
|
$this->assertTrue($router->routeIsExists($name)); |
|
|
|
$this->assertFalse($router->routeIsExists($name_is_not_exists)); |
|
|
|
} |
|
|
|
} |