2015-09-14 15:49:20 -04:00
|
|
|
<?php
|
|
|
|
|
2015-09-15 13:19:29 -04:00
|
|
|
use Aviat\AnimeClient\UrlGenerator;
|
2016-10-20 22:32:17 -04:00
|
|
|
use Aviat\Ion\Config;
|
2015-09-14 15:49:20 -04:00
|
|
|
|
|
|
|
class UrlGeneratorTest extends AnimeClient_TestCase {
|
|
|
|
|
|
|
|
public function assetUrlProvider()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'single argument' => [
|
|
|
|
'args' => [
|
|
|
|
'images'
|
|
|
|
],
|
|
|
|
'expected' => '//localhost/assets/images',
|
|
|
|
],
|
|
|
|
'multiple arguments' => [
|
|
|
|
'args' => [
|
|
|
|
'images', 'anime', 'foo.png'
|
|
|
|
],
|
|
|
|
'expected' => '//localhost/assets/images/anime/foo.png'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider assetUrlProvider
|
|
|
|
*/
|
|
|
|
public function testAssetUrl($args, $expected)
|
|
|
|
{
|
|
|
|
$urlGenerator = new UrlGenerator($this->container);
|
|
|
|
|
|
|
|
$result = call_user_func_array([$urlGenerator, 'asset_url'], $args);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataFullUrl()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'default_view' => [
|
|
|
|
'config' => [
|
2016-01-06 11:08:56 -05:00
|
|
|
'routes' => [
|
|
|
|
'routes' => [],
|
|
|
|
'route_config' => [
|
|
|
|
'anime_path' => 'anime',
|
|
|
|
'manga_path' => 'manga',
|
|
|
|
'default_list' => 'manga',
|
|
|
|
'default_anime_path' => '/anime/watching',
|
|
|
|
'default_manga_path' => '/manga/all',
|
|
|
|
'default_to_list_view' => FALSE,
|
|
|
|
]
|
2015-09-14 15:49:20 -04:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'path' => '',
|
|
|
|
'type' => 'manga',
|
|
|
|
'expected' => '//localhost/manga/all',
|
|
|
|
],
|
|
|
|
'default_view_list' => [
|
|
|
|
'config' => [
|
2016-01-06 11:08:56 -05:00
|
|
|
'routes' => [
|
|
|
|
'routes' => [],
|
|
|
|
'route_config' => [
|
|
|
|
'anime_path' => 'anime',
|
|
|
|
'manga_path' => 'manga',
|
|
|
|
'default_list' => 'manga',
|
|
|
|
'default_anime_path' => '/anime/watching',
|
|
|
|
'default_manga_path' => '/manga/all',
|
|
|
|
'default_to_list_view' => TRUE,
|
|
|
|
]
|
2015-09-14 15:49:20 -04:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'path' => '',
|
|
|
|
'type' => 'manga',
|
|
|
|
'expected' => '//localhost/manga/all/list',
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataFullUrl
|
|
|
|
*/
|
|
|
|
public function testFullUrl($config, $path, $type, $expected)
|
|
|
|
{
|
|
|
|
$config = new Config($config);
|
2016-08-29 15:36:36 -04:00
|
|
|
$this->container->setInstance('config', $config);
|
2015-09-14 15:49:20 -04:00
|
|
|
$urlGenerator = new UrlGenerator($this->container);
|
|
|
|
|
|
|
|
$result = $urlGenerator->full_url($path, $type);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataBaseUrl()
|
|
|
|
{
|
|
|
|
$config = [
|
2016-01-06 11:08:56 -05:00
|
|
|
'routes' => [
|
|
|
|
'routes' => [],
|
|
|
|
'route_config' => [
|
|
|
|
'anime_path' => 'anime',
|
|
|
|
'manga_path' => 'manga',
|
|
|
|
'default_list' => 'manga',
|
|
|
|
'default_anime_path' => '/watching',
|
|
|
|
'default_manga_path' => '/all',
|
|
|
|
'default_to_list_view' => TRUE,
|
|
|
|
],
|
|
|
|
]
|
2015-09-14 15:49:20 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
return [
|
|
|
|
'path_based_routing_anime' => [
|
|
|
|
'config' => $config,
|
|
|
|
'type' => 'anime',
|
|
|
|
'expected' => '//localhost/anime'
|
|
|
|
],
|
|
|
|
'path_based_routing_manga' => [
|
|
|
|
'config' => $config,
|
|
|
|
'type' => 'manga',
|
|
|
|
'expected' => '//localhost/manga'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataBaseUrl
|
|
|
|
*/
|
|
|
|
public function testBaseUrl($config, $type, $expected)
|
|
|
|
{
|
|
|
|
$config = new Config($config);
|
2016-08-29 15:36:36 -04:00
|
|
|
$this->container->setInstance('config', $config);
|
2015-09-14 15:49:20 -04:00
|
|
|
$urlGenerator = new UrlGenerator($this->container);
|
|
|
|
|
|
|
|
$result = $urlGenerator->base_url($type);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
}
|