2017-01-10 22:37:29 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* UglyRouterTest class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Alltube\Test;
|
|
|
|
|
|
|
|
use Alltube\UglyRouter;
|
|
|
|
use Slim\Http\Environment;
|
2017-01-10 22:39:58 +00:00
|
|
|
use Slim\Http\Request;
|
2017-01-10 22:37:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for the UglyRouter class.
|
|
|
|
*/
|
2019-04-21 16:30:02 +00:00
|
|
|
class UglyRouterTest extends BaseTest
|
2017-01-10 22:37:29 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* UglyRouter instance.
|
|
|
|
*
|
|
|
|
* @var UglyRouter
|
|
|
|
*/
|
|
|
|
private $router;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare tests.
|
|
|
|
*/
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
$this->router = new UglyRouter();
|
|
|
|
$this->router->map(['GET'], '/foo', 'print')->setName('foo');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the dispatch() function.
|
2017-01-10 22:39:58 +00:00
|
|
|
*
|
2017-01-10 22:37:29 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDispatch()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
[1, 'route0', []],
|
|
|
|
$this->router->dispatch(
|
2017-01-16 11:21:38 +00:00
|
|
|
Request::createFromEnvironment(
|
|
|
|
Environment::mock(
|
|
|
|
[
|
|
|
|
'REQUEST_METHOD' => 'GET',
|
2017-01-16 11:23:43 +00:00
|
|
|
'QUERY_STRING' => 'page=foo',
|
2017-01-16 11:21:38 +00:00
|
|
|
]
|
|
|
|
)
|
2017-01-10 22:37:29 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the pathFor() function.
|
2017-01-10 22:39:58 +00:00
|
|
|
*
|
2017-01-10 22:37:29 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPathFor()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
'/?page=foo',
|
|
|
|
$this->router->pathFor('foo', [], [])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the pathFor() function with a base path.
|
2017-01-10 22:39:58 +00:00
|
|
|
*
|
2017-01-10 22:37:29 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPathForWithBasePath()
|
|
|
|
{
|
|
|
|
$this->router->setBasePath('/bar');
|
|
|
|
$this->assertEquals(
|
|
|
|
'/bar/?page=foo',
|
|
|
|
$this->router->pathFor('foo', [], [])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|