|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nip\Router\Tests\RouteFactory; |
|
4
|
|
|
|
|
5
|
|
|
use Nip\Router\Route\LiteralRoute; |
|
6
|
|
|
use Nip\Router\Route\StandardRoute; |
|
7
|
|
|
use Nip\Router\RouteCollection; |
|
8
|
|
|
use Nip\Router\RouteFactory; |
|
9
|
|
|
use Nip\Router\Tests\AbstractTest; |
|
10
|
|
|
use Nip\Router\Tests\Fixtures\Application\Library\Router\Route\LiteralRoute as FixturesLiteralRoute; |
|
11
|
|
|
use Nip\Router\Tests\Fixtures\Application\Library\Router\Route\StandardRoute as FixturesStandardRoute; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class HasBaseRoutesTraitTest |
|
15
|
|
|
* @package Nip\Router\Tests\RouteFactory |
|
16
|
|
|
*/ |
|
17
|
|
|
class HasBaseRoutesTraitTest extends AbstractTest |
|
18
|
|
|
{ |
|
19
|
|
|
public function test_generateIndexRoute_emptyClass() |
|
20
|
|
|
{ |
|
21
|
|
|
$collection = new RouteCollection(); |
|
22
|
|
|
RouteFactory::generateIndexRoute($collection, 'index'); |
|
23
|
|
|
|
|
24
|
|
|
self::assertCount(2, $collection); |
|
25
|
|
|
|
|
26
|
|
|
$firstRoute = $collection->get('index'); |
|
27
|
|
|
self::assertInstanceOf(LiteralRoute::class, $firstRoute); |
|
28
|
|
|
self::assertSame('/', $firstRoute->getParser()->getMap()); |
|
29
|
|
|
self::assertSame(["controller" => "index", "action" => "index"], $firstRoute->getDefaults()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function test_generateIndexRoute_existingClass() |
|
33
|
|
|
{ |
|
34
|
|
|
$collection = new RouteCollection(); |
|
35
|
|
|
RouteFactory::generateIndexRoute($collection, 'index', FixturesLiteralRoute::class); |
|
36
|
|
|
|
|
37
|
|
|
self::assertCount(2, $collection); |
|
38
|
|
|
|
|
39
|
|
|
$firstRoute = $collection->get('index'); |
|
40
|
|
|
self::assertInstanceOf(FixturesLiteralRoute::class, $firstRoute); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function test_generateIndexRoute_nonClass() |
|
44
|
|
|
{ |
|
45
|
|
|
$collection = new RouteCollection(); |
|
46
|
|
|
RouteFactory::generateIndexRoute($collection, 'index', 'MyApplication\Module\Route\LiteralRoute'); |
|
47
|
|
|
|
|
48
|
|
|
self::assertCount(2, $collection); |
|
49
|
|
|
|
|
50
|
|
|
$firstRoute = $collection->get('index'); |
|
51
|
|
|
self::assertInstanceOf(LiteralRoute::class, $firstRoute); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
public function test_generateStandardRoute_emptyClass() |
|
56
|
|
|
{ |
|
57
|
|
|
$collection = new RouteCollection(); |
|
58
|
|
|
RouteFactory::generateStandardRoute($collection, 'index'); |
|
59
|
|
|
|
|
60
|
|
|
self::assertCount(2, $collection); |
|
61
|
|
|
|
|
62
|
|
|
$firstRoute = $collection->get('index'); |
|
63
|
|
|
self::assertInstanceOf(StandardRoute::class, $firstRoute); |
|
64
|
|
|
self::assertSame('/{controller}/{action?index}', $firstRoute->getParser()->getMap()); |
|
65
|
|
|
self::assertSame(["action" => "index"], $firstRoute->getDefaults()); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function test_generateStandardRoute_existingClass() |
|
69
|
|
|
{ |
|
70
|
|
|
$collection = new RouteCollection(); |
|
71
|
|
|
RouteFactory::generateStandardRoute($collection, 'index', FixturesStandardRoute::class); |
|
72
|
|
|
|
|
73
|
|
|
self::assertCount(2, $collection); |
|
74
|
|
|
|
|
75
|
|
|
$firstRoute = $collection->get('index'); |
|
76
|
|
|
self::assertInstanceOf(FixturesStandardRoute::class, $firstRoute); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function test_generateStandardRoute_nonClass() |
|
80
|
|
|
{ |
|
81
|
|
|
$collection = new RouteCollection(); |
|
82
|
|
|
RouteFactory::generateStandardRoute($collection, 'index', 'MyApplication\Module\Route\StandardRoute'); |
|
83
|
|
|
|
|
84
|
|
|
self::assertCount(2, $collection); |
|
85
|
|
|
|
|
86
|
|
|
$firstRoute = $collection->get('index'); |
|
87
|
|
|
self::assertInstanceOf(StandardRoute::class, $firstRoute); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|