|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nip\Router\Tests\Router\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Nip\Router\Generator\CompiledUrlGenerator; |
|
6
|
|
|
use Nip\Router\Route\Route; |
|
7
|
|
|
use Nip\Router\RouteFactory; |
|
8
|
|
|
use Nip\Router\Router; |
|
9
|
|
|
use Nip\Router\Tests\AbstractTest; |
|
10
|
|
|
use Nip\Router\Tests\Fixtures\Application\Library\Router\Route\StandardRoute; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class HasGeneratorTraitTest |
|
14
|
|
|
* @package Nip\Router\Tests\Router\Traits |
|
15
|
|
|
*/ |
|
16
|
|
|
class HasGeneratorTraitTest extends AbstractTest |
|
17
|
|
|
{ |
|
18
|
|
|
public function testGetGenerator() |
|
19
|
|
|
{ |
|
20
|
|
|
$router = new Router(); |
|
21
|
|
|
$router->initRouteCollection(); |
|
22
|
|
|
self::assertInstanceOf(CompiledUrlGenerator::class, $router->getGenerator()); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testAssemble() |
|
26
|
|
|
{ |
|
27
|
|
|
$router = new Router(); |
|
28
|
|
|
$router->initRouteCollection(); |
|
29
|
|
|
$collection = $router->getRoutes(); |
|
30
|
|
|
|
|
31
|
|
|
RouteFactory::generateLiteralRoute($collection, "admin.index", Route::class, "/admin", "/index"); |
|
32
|
|
|
RouteFactory::generateStandardRoute($collection, "api.index", StandardRoute::class, "/api"); |
|
33
|
|
|
|
|
34
|
|
|
self::assertSame( |
|
35
|
|
|
'/admin/index?controller=posts', |
|
36
|
|
|
$router->assemble('admin.index', ['controller' => 'posts']) |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
self::assertSame( |
|
40
|
|
|
'/api/posts', |
|
41
|
|
|
$router->assemble('api.index', ['controller' => 'posts']) |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
self::assertSame( |
|
45
|
|
|
'/api/posts/create?test=true', |
|
46
|
|
|
$router->assemble('api.index', ['controller' => 'posts', 'action' => 'create', 'test' => 'true']) |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testGenerate() |
|
51
|
|
|
{ |
|
52
|
|
|
$router = new Router(); |
|
53
|
|
|
$router->initRouteCollection(); |
|
54
|
|
|
$collection = $router->getRoutes(); |
|
55
|
|
|
|
|
56
|
|
|
RouteFactory::generateLiteralRoute($collection, "admin.index", Route::class, "/admin", "/index"); |
|
57
|
|
|
RouteFactory::generateStandardRoute($collection, "api.index", StandardRoute::class, "/api"); |
|
58
|
|
|
|
|
59
|
|
|
self::assertSame( |
|
60
|
|
|
'/admin/index?controller=posts', |
|
61
|
|
|
$router->generate('admin.index', ['controller' => 'posts']) |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
self::assertSame( |
|
65
|
|
|
'/api/posts', |
|
66
|
|
|
$router->generate('api.index', ['controller' => 'posts']) |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
self::assertSame( |
|
70
|
|
|
'/api/posts/create?param=test', |
|
71
|
|
|
$router->generate('api.index', ['controller' => 'posts','action' => 'create', 'param' => 'test']) |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|