|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* DronePHP (http://www.dronephp.com) |
|
4
|
|
|
* |
|
5
|
|
|
* @link http://github.com/Pleets/DronePHP |
|
6
|
|
|
* @copyright Copyright (c) 2016-2018 Pleets. (http://www.pleets.org) |
|
7
|
|
|
* @license http://www.dronephp.com/license |
|
8
|
|
|
* @author Darío Rivera <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace DroneTest\Util; |
|
12
|
|
|
|
|
13
|
|
|
use Drone\Mvc\Router; |
|
14
|
|
|
use Drone\Mvc\AbstractionController; |
|
15
|
|
|
use Drone\Mvc\AbstractionModule; |
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
class RouterTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Tests if the router can create an instance of a controller |
|
22
|
|
|
* |
|
23
|
|
|
* @return null |
|
24
|
|
|
*/ |
|
25
|
|
|
public function testSimpleRouteMatching() |
|
26
|
|
|
{ |
|
27
|
|
|
$router = new Router(); |
|
28
|
|
|
|
|
29
|
|
|
$router->addRoute([ |
|
30
|
|
|
'defaults' => [ |
|
31
|
|
|
'module' => 'App', |
|
32
|
|
|
'controller' => 'Index', |
|
33
|
|
|
'view' => 'Home' |
|
34
|
|
|
] |
|
35
|
|
|
]); |
|
36
|
|
|
|
|
37
|
|
|
# default route for App module |
|
38
|
|
|
$router->addRoute([ |
|
39
|
|
|
'App' => [ |
|
40
|
|
|
'module' => 'App', |
|
41
|
|
|
'controller' => 'Index', |
|
42
|
|
|
'view' => 'about' |
|
43
|
|
|
], |
|
44
|
|
|
]); |
|
45
|
|
|
|
|
46
|
|
|
$router->setIdentifiers('App', 'Index', 'about'); |
|
47
|
|
|
$router->run(); |
|
48
|
|
|
|
|
49
|
|
|
$ctrl = $router->getController(); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertEquals("App\Controller\Index", get_class($ctrl)); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/* |
|
56
|
|
|
|-------------------------------------------------------------------------- |
|
57
|
|
|
| Module Class |
|
58
|
|
|
|-------------------------------------------------------------------------- |
|
59
|
|
|
| |
|
60
|
|
|
| Each module must have a Module class. |
|
61
|
|
|
| |
|
62
|
|
|
*/ |
|
63
|
|
|
|
|
64
|
|
|
namespace App; |
|
65
|
|
|
|
|
66
|
|
|
use Drone\Mvc\AbstractionController; |
|
67
|
|
|
use Drone\Mvc\AbstractionModule; |
|
68
|
|
|
|
|
69
|
|
|
class Module extends AbstractionModule |
|
70
|
|
|
{ |
|
71
|
|
|
public function init(AbstractionController $c) |
|
72
|
|
|
{ |
|
73
|
|
|
// init |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/* |
|
78
|
|
|
|-------------------------------------------------------------------------- |
|
79
|
|
|
| Controller class |
|
80
|
|
|
|-------------------------------------------------------------------------- |
|
81
|
|
|
| |
|
82
|
|
|
| This is a simple controller implementing AbstractionController. |
|
83
|
|
|
| |
|
84
|
|
|
*/ |
|
85
|
|
|
|
|
86
|
|
|
namespace App\Controller; |
|
87
|
|
|
|
|
88
|
|
|
use Drone\Mvc\AbstractionController; |
|
89
|
|
|
|
|
90
|
|
|
class Index extends AbstractionController |
|
91
|
|
|
{ |
|
92
|
|
|
public function about() |
|
93
|
|
|
{ |
|
94
|
|
|
$this->setTerminal(); |
|
95
|
|
|
return []; |
|
96
|
|
|
} |
|
97
|
|
|
} |