@@ -11,336 +11,336 @@ |
||
| 11 | 11 | |
| 12 | 12 | class RouterTest extends PHPUnit_Framework_TestCase |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var Router |
|
| 16 | - */ |
|
| 17 | - protected $router; |
|
| 18 | - protected $closure; |
|
| 19 | - protected $param1; |
|
| 20 | - protected $param2; |
|
| 14 | + /** |
|
| 15 | + * @var Router |
|
| 16 | + */ |
|
| 17 | + protected $router; |
|
| 18 | + protected $closure; |
|
| 19 | + protected $param1; |
|
| 20 | + protected $param2; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Sets up the fixture, for example, opens a network connection. |
|
| 24 | - * This method is called before a test is executed. |
|
| 25 | - */ |
|
| 26 | - protected function setUp() |
|
| 27 | - { |
|
| 28 | - $parser = new RouterParser(); |
|
| 29 | - $this->router = new Router($parser, [], '', []); |
|
| 30 | - $this->param1 = ['controller' => 'test', 'action' => 'someaction']; |
|
| 31 | - $this->param2 = ['controller' => 'test', 'action' => 'someaction', 'type' => 'json']; |
|
| 32 | - $this->closure = function () { |
|
| 33 | - }; |
|
| 34 | - } |
|
| 22 | + /** |
|
| 23 | + * Sets up the fixture, for example, opens a network connection. |
|
| 24 | + * This method is called before a test is executed. |
|
| 25 | + */ |
|
| 26 | + protected function setUp() |
|
| 27 | + { |
|
| 28 | + $parser = new RouterParser(); |
|
| 29 | + $this->router = new Router($parser, [], '', []); |
|
| 30 | + $this->param1 = ['controller' => 'test', 'action' => 'someaction']; |
|
| 31 | + $this->param2 = ['controller' => 'test', 'action' => 'someaction', 'type' => 'json']; |
|
| 32 | + $this->closure = function () { |
|
| 33 | + }; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @covers Router::getRoutes |
|
| 38 | - */ |
|
| 39 | - public function testMapAndGetRoutes() |
|
| 40 | - { |
|
| 41 | - $route = ['POST', '/[:controller]/[:action]', $this->closure, null]; |
|
| 36 | + /** |
|
| 37 | + * @covers Router::getRoutes |
|
| 38 | + */ |
|
| 39 | + public function testMapAndGetRoutes() |
|
| 40 | + { |
|
| 41 | + $route = ['POST', '/[:controller]/[:action]', $this->closure, null]; |
|
| 42 | 42 | |
| 43 | - call_user_func_array([$this->router, 'map'], $route); |
|
| 43 | + call_user_func_array([$this->router, 'map'], $route); |
|
| 44 | 44 | |
| 45 | - $routes = $this->router->getRoutes(); |
|
| 45 | + $routes = $this->router->getRoutes(); |
|
| 46 | 46 | |
| 47 | - $this->assertInternalType('array', $routes); |
|
| 48 | - $this->assertEquals([$route], $routes); |
|
| 49 | - } |
|
| 47 | + $this->assertInternalType('array', $routes); |
|
| 48 | + $this->assertEquals([$route], $routes); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @covers Router::setRoutes |
|
| 53 | - */ |
|
| 54 | - public function testAddRoutesWithArrayArgument() |
|
| 55 | - { |
|
| 56 | - $route1 = ['POST', '/[:controller]/[:action]', $this->closure, null]; |
|
| 57 | - $route2 = ['POST', '/[:controller]/[:action]', $this->closure, 'second_route']; |
|
| 51 | + /** |
|
| 52 | + * @covers Router::setRoutes |
|
| 53 | + */ |
|
| 54 | + public function testAddRoutesWithArrayArgument() |
|
| 55 | + { |
|
| 56 | + $route1 = ['POST', '/[:controller]/[:action]', $this->closure, null]; |
|
| 57 | + $route2 = ['POST', '/[:controller]/[:action]', $this->closure, 'second_route']; |
|
| 58 | 58 | |
| 59 | - $this->router->setRoutes([$route1, $route2]); |
|
| 59 | + $this->router->setRoutes([$route1, $route2]); |
|
| 60 | 60 | |
| 61 | - $routes = $this->router->getRoutes(); |
|
| 61 | + $routes = $this->router->getRoutes(); |
|
| 62 | 62 | |
| 63 | - $this->assertEquals($route1, $routes[0]); |
|
| 64 | - $this->assertEquals($route2, $routes[1]); |
|
| 65 | - } |
|
| 63 | + $this->assertEquals($route1, $routes[0]); |
|
| 64 | + $this->assertEquals($route2, $routes[1]); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @covers Router::setRoutes |
|
| 69 | - */ |
|
| 70 | - public function testAddRoutesWithTraversableArgument() |
|
| 71 | - { |
|
| 72 | - $traversable = new SimpleTraversable(); |
|
| 73 | - $this->router->setRoutes($traversable); |
|
| 67 | + /** |
|
| 68 | + * @covers Router::setRoutes |
|
| 69 | + */ |
|
| 70 | + public function testAddRoutesWithTraversableArgument() |
|
| 71 | + { |
|
| 72 | + $traversable = new SimpleTraversable(); |
|
| 73 | + $this->router->setRoutes($traversable); |
|
| 74 | 74 | |
| 75 | - $traversable->rewind(); |
|
| 75 | + $traversable->rewind(); |
|
| 76 | 76 | |
| 77 | - $first = $traversable->current(); |
|
| 78 | - $traversable->next(); |
|
| 79 | - $second = $traversable->current(); |
|
| 77 | + $first = $traversable->current(); |
|
| 78 | + $traversable->next(); |
|
| 79 | + $second = $traversable->current(); |
|
| 80 | 80 | |
| 81 | - $routes = $this->router->getRoutes(); |
|
| 81 | + $routes = $this->router->getRoutes(); |
|
| 82 | 82 | |
| 83 | - $this->assertEquals($first, $routes[0]); |
|
| 84 | - $this->assertEquals($second, $routes[1]); |
|
| 85 | - } |
|
| 83 | + $this->assertEquals($first, $routes[0]); |
|
| 84 | + $this->assertEquals($second, $routes[1]); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @covers Router::setRoutes |
|
| 89 | - */ |
|
| 90 | - public function testAddRoutesWidthInvalidArgument() |
|
| 91 | - { |
|
| 92 | - try { |
|
| 93 | - $this->router->setRoutes(new stdClass); |
|
| 94 | - } catch (RouterException $e) { |
|
| 95 | - $this->assertEquals('Routes should be an array or an instance of Iterator', $e->getMessage()); |
|
| 96 | - } |
|
| 97 | - } |
|
| 87 | + /** |
|
| 88 | + * @covers Router::setRoutes |
|
| 89 | + */ |
|
| 90 | + public function testAddRoutesWidthInvalidArgument() |
|
| 91 | + { |
|
| 92 | + try { |
|
| 93 | + $this->router->setRoutes(new stdClass); |
|
| 94 | + } catch (RouterException $e) { |
|
| 95 | + $this->assertEquals('Routes should be an array or an instance of Iterator', $e->getMessage()); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @covers Router::setBasePath |
|
| 101 | - */ |
|
| 102 | - public function testSetBasePath() |
|
| 103 | - { |
|
| 104 | - $this->router->setBasePath('/some/path'); |
|
| 105 | - $this->assertEquals('/some/path', $this->router->getBasePath()); |
|
| 106 | - } |
|
| 99 | + /** |
|
| 100 | + * @covers Router::setBasePath |
|
| 101 | + */ |
|
| 102 | + public function testSetBasePath() |
|
| 103 | + { |
|
| 104 | + $this->router->setBasePath('/some/path'); |
|
| 105 | + $this->assertEquals('/some/path', $this->router->getBasePath()); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * @covers Router::map |
|
| 110 | - */ |
|
| 111 | - public function testMapWithName() |
|
| 112 | - { |
|
| 113 | - $route = ['POST', '/[:controller]/[:action]', $this->closure, 'my_route']; |
|
| 108 | + /** |
|
| 109 | + * @covers Router::map |
|
| 110 | + */ |
|
| 111 | + public function testMapWithName() |
|
| 112 | + { |
|
| 113 | + $route = ['POST', '/[:controller]/[:action]', $this->closure, 'my_route']; |
|
| 114 | 114 | |
| 115 | - call_user_func_array([$this->router, 'map'], $route); |
|
| 115 | + call_user_func_array([$this->router, 'map'], $route); |
|
| 116 | 116 | |
| 117 | - $routes = $this->router->getRoutes(); |
|
| 118 | - $namedRoutes = $this->router->getNamedRoutes(); |
|
| 117 | + $routes = $this->router->getRoutes(); |
|
| 118 | + $namedRoutes = $this->router->getNamedRoutes(); |
|
| 119 | 119 | |
| 120 | - $this->assertInternalType('array', $routes); |
|
| 121 | - $this->assertEquals($route, $routes[0]); |
|
| 120 | + $this->assertInternalType('array', $routes); |
|
| 121 | + $this->assertEquals($route, $routes[0]); |
|
| 122 | 122 | |
| 123 | - $this->assertInternalType('array', $namedRoutes); |
|
| 124 | - $this->assertEquals('/[:controller]/[:action]', $namedRoutes['my_route']); |
|
| 125 | - } |
|
| 123 | + $this->assertInternalType('array', $namedRoutes); |
|
| 124 | + $this->assertEquals('/[:controller]/[:action]', $namedRoutes['my_route']); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * @covers Router::map |
|
| 129 | - */ |
|
| 130 | - public function testMapWithDuplicatedRouteName() |
|
| 131 | - { |
|
| 132 | - try { |
|
| 133 | - $route = ['POST', '/[:controller]/[:action]', $this->closure, 'my_route']; |
|
| 134 | - call_user_func_array([$this->router, 'map'], $route); |
|
| 135 | - call_user_func_array([$this->router, 'map'], $route); |
|
| 136 | - } catch (Exception $e) { |
|
| 137 | - $this->assertEquals("Can not redeclare route 'my_route'", $e->getMessage()); |
|
| 138 | - } |
|
| 139 | - } |
|
| 127 | + /** |
|
| 128 | + * @covers Router::map |
|
| 129 | + */ |
|
| 130 | + public function testMapWithDuplicatedRouteName() |
|
| 131 | + { |
|
| 132 | + try { |
|
| 133 | + $route = ['POST', '/[:controller]/[:action]', $this->closure, 'my_route']; |
|
| 134 | + call_user_func_array([$this->router, 'map'], $route); |
|
| 135 | + call_user_func_array([$this->router, 'map'], $route); |
|
| 136 | + } catch (Exception $e) { |
|
| 137 | + $this->assertEquals("Can not redeclare route 'my_route'", $e->getMessage()); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * @covers Router::generate |
|
| 143 | - */ |
|
| 144 | - public function testGenerate() |
|
| 145 | - { |
|
| 146 | - $this->router->map('GET', '/[:controller]/[:action]', $this->closure, 'foo_route'); |
|
| 141 | + /** |
|
| 142 | + * @covers Router::generate |
|
| 143 | + */ |
|
| 144 | + public function testGenerate() |
|
| 145 | + { |
|
| 146 | + $this->router->map('GET', '/[:controller]/[:action]', $this->closure, 'foo_route'); |
|
| 147 | 147 | |
| 148 | - $this->assertEquals('/test/someaction', $this->router->generate('foo_route', $this->param1)); |
|
| 149 | - $this->assertEquals('/test/someaction', $this->router->generate('foo_route', $this->param2)); |
|
| 150 | - } |
|
| 148 | + $this->assertEquals('/test/someaction', $this->router->generate('foo_route', $this->param1)); |
|
| 149 | + $this->assertEquals('/test/someaction', $this->router->generate('foo_route', $this->param2)); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * @covers Router::generate |
|
| 154 | - */ |
|
| 155 | - public function testGenerateWithOptionalUrlParts() |
|
| 156 | - { |
|
| 157 | - $this->router->map('GET', '/[:controller]/[:action].[:type]?', $this->closure, 'bar_route'); |
|
| 152 | + /** |
|
| 153 | + * @covers Router::generate |
|
| 154 | + */ |
|
| 155 | + public function testGenerateWithOptionalUrlParts() |
|
| 156 | + { |
|
| 157 | + $this->router->map('GET', '/[:controller]/[:action].[:type]?', $this->closure, 'bar_route'); |
|
| 158 | 158 | |
| 159 | - $this->assertEquals('/test/someaction', $this->router->generate('bar_route', $this->param1)); |
|
| 160 | - $this->assertEquals('/test/someaction.json', $this->router->generate('bar_route', $this->param2)); |
|
| 161 | - } |
|
| 159 | + $this->assertEquals('/test/someaction', $this->router->generate('bar_route', $this->param1)); |
|
| 160 | + $this->assertEquals('/test/someaction.json', $this->router->generate('bar_route', $this->param2)); |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - /** |
|
| 164 | - * @covers Router::generate |
|
| 165 | - */ |
|
| 166 | - public function testGenerateWithNonExistingRoute() |
|
| 167 | - { |
|
| 168 | - try { |
|
| 169 | - $this->router->generate('non_existing_route'); |
|
| 170 | - } catch (Exception $e) { |
|
| 171 | - $this->assertEquals("Route 'non_existing_route' does not exist.", $e->getMessage()); |
|
| 172 | - } |
|
| 173 | - } |
|
| 163 | + /** |
|
| 164 | + * @covers Router::generate |
|
| 165 | + */ |
|
| 166 | + public function testGenerateWithNonExistingRoute() |
|
| 167 | + { |
|
| 168 | + try { |
|
| 169 | + $this->router->generate('non_existing_route'); |
|
| 170 | + } catch (Exception $e) { |
|
| 171 | + $this->assertEquals("Route 'non_existing_route' does not exist.", $e->getMessage()); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * @covers Router::match |
|
| 177 | - * @covers Router::compileRoute |
|
| 178 | - */ |
|
| 179 | - public function testMatch() |
|
| 180 | - { |
|
| 181 | - $params = [ |
|
| 182 | - 'target' => 'foo_action', |
|
| 183 | - 'params' => ['controller' => 'test', 'action' => 'do'], |
|
| 184 | - 'name' => 'foo_route' |
|
| 185 | - ]; |
|
| 175 | + /** |
|
| 176 | + * @covers Router::match |
|
| 177 | + * @covers Router::compileRoute |
|
| 178 | + */ |
|
| 179 | + public function testMatch() |
|
| 180 | + { |
|
| 181 | + $params = [ |
|
| 182 | + 'target' => 'foo_action', |
|
| 183 | + 'params' => ['controller' => 'test', 'action' => 'do'], |
|
| 184 | + 'name' => 'foo_route' |
|
| 185 | + ]; |
|
| 186 | 186 | |
| 187 | - $this->router->map('GET', '/foo/[:controller]/[:action]', 'foo_action', 'foo_route'); |
|
| 187 | + $this->router->map('GET', '/foo/[:controller]/[:action]', 'foo_action', 'foo_route'); |
|
| 188 | 188 | |
| 189 | - $this->assertEquals($params, $this->router->match('/foo/test/do', 'GET')); |
|
| 190 | - $this->assertSame(false, $this->router->match('/foo/test/do', 'POST')); |
|
| 191 | - $this->assertEquals($params, $this->router->match('/foo/test/do?param=value', 'GET')); |
|
| 192 | - } |
|
| 189 | + $this->assertEquals($params, $this->router->match('/foo/test/do', 'GET')); |
|
| 190 | + $this->assertSame(false, $this->router->match('/foo/test/do', 'POST')); |
|
| 191 | + $this->assertEquals($params, $this->router->match('/foo/test/do?param=value', 'GET')); |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - public function testMatchWithFixedParamValues() |
|
| 195 | - { |
|
| 196 | - $params = [ |
|
| 197 | - 'target' => 'usersController#doAction', |
|
| 198 | - 'params' => ['id' => 1, 'action' => 'delete'], |
|
| 199 | - 'name' => 'users_do' |
|
| 200 | - ]; |
|
| 194 | + public function testMatchWithFixedParamValues() |
|
| 195 | + { |
|
| 196 | + $params = [ |
|
| 197 | + 'target' => 'usersController#doAction', |
|
| 198 | + 'params' => ['id' => 1, 'action' => 'delete'], |
|
| 199 | + 'name' => 'users_do' |
|
| 200 | + ]; |
|
| 201 | 201 | |
| 202 | - $this->router->map('POST', '/users/[i:id]/[delete|update:action]', 'usersController#doAction', 'users_do'); |
|
| 202 | + $this->router->map('POST', '/users/[i:id]/[delete|update:action]', 'usersController#doAction', 'users_do'); |
|
| 203 | 203 | |
| 204 | - $this->assertEquals($params, $this->router->match('/users/1/delete', 'POST')); |
|
| 205 | - $this->assertFalse($this->router->match('/users/1/delete', 'GET')); |
|
| 206 | - $this->assertFalse($this->router->match('/users/abc/delete', 'POST')); |
|
| 207 | - $this->assertFalse($this->router->match('/users/1/create', 'GET')); |
|
| 208 | - } |
|
| 204 | + $this->assertEquals($params, $this->router->match('/users/1/delete', 'POST')); |
|
| 205 | + $this->assertFalse($this->router->match('/users/1/delete', 'GET')); |
|
| 206 | + $this->assertFalse($this->router->match('/users/abc/delete', 'POST')); |
|
| 207 | + $this->assertFalse($this->router->match('/users/1/create', 'GET')); |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - public function testMatchWithServerVars() |
|
| 211 | - { |
|
| 212 | - $this->router->map('GET', '/foo/[:controller]/[:action]', 'foo_action', 'foo_route'); |
|
| 210 | + public function testMatchWithServerVars() |
|
| 211 | + { |
|
| 212 | + $this->router->map('GET', '/foo/[:controller]/[:action]', 'foo_action', 'foo_route'); |
|
| 213 | 213 | |
| 214 | - $this->router->setServer([ |
|
| 215 | - 'REQUEST_URI' => '/foo/test/do', |
|
| 216 | - 'REQUEST_METHOD' => 'GET' |
|
| 217 | - ]); |
|
| 214 | + $this->router->setServer([ |
|
| 215 | + 'REQUEST_URI' => '/foo/test/do', |
|
| 216 | + 'REQUEST_METHOD' => 'GET' |
|
| 217 | + ]); |
|
| 218 | 218 | |
| 219 | - $this->assertEquals(array( |
|
| 220 | - 'target' => 'foo_action', |
|
| 221 | - 'params' => array( |
|
| 222 | - 'controller' => 'test', |
|
| 223 | - 'action' => 'do' |
|
| 224 | - ), |
|
| 225 | - 'name' => 'foo_route' |
|
| 226 | - ), $this->router->match()); |
|
| 227 | - } |
|
| 219 | + $this->assertEquals(array( |
|
| 220 | + 'target' => 'foo_action', |
|
| 221 | + 'params' => array( |
|
| 222 | + 'controller' => 'test', |
|
| 223 | + 'action' => 'do' |
|
| 224 | + ), |
|
| 225 | + 'name' => 'foo_route' |
|
| 226 | + ), $this->router->match()); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - public function testMatchWithOptionalUrlParts() |
|
| 230 | - { |
|
| 231 | - $this->router->map('GET', '/bar/[:controller]/[:action].[:type]?', 'bar_action', 'bar_route'); |
|
| 229 | + public function testMatchWithOptionalUrlParts() |
|
| 230 | + { |
|
| 231 | + $this->router->map('GET', '/bar/[:controller]/[:action].[:type]?', 'bar_action', 'bar_route'); |
|
| 232 | 232 | |
| 233 | - $this->assertEquals(array( |
|
| 234 | - 'target' => 'bar_action', |
|
| 235 | - 'params' => array( |
|
| 236 | - 'controller' => 'test', |
|
| 237 | - 'action' => 'do', |
|
| 238 | - 'type' => 'json' |
|
| 239 | - ), |
|
| 240 | - 'name' => 'bar_route' |
|
| 241 | - ), $this->router->match('/bar/test/do.json', 'GET')); |
|
| 242 | - } |
|
| 233 | + $this->assertEquals(array( |
|
| 234 | + 'target' => 'bar_action', |
|
| 235 | + 'params' => array( |
|
| 236 | + 'controller' => 'test', |
|
| 237 | + 'action' => 'do', |
|
| 238 | + 'type' => 'json' |
|
| 239 | + ), |
|
| 240 | + 'name' => 'bar_route' |
|
| 241 | + ), $this->router->match('/bar/test/do.json', 'GET')); |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - public function testMatchWithWildcard() |
|
| 245 | - { |
|
| 246 | - $this->router->map('GET', '/a', 'foo_action', 'foo_route'); |
|
| 247 | - $this->router->map('GET', '*', 'bar_action', 'bar_route'); |
|
| 244 | + public function testMatchWithWildcard() |
|
| 245 | + { |
|
| 246 | + $this->router->map('GET', '/a', 'foo_action', 'foo_route'); |
|
| 247 | + $this->router->map('GET', '*', 'bar_action', 'bar_route'); |
|
| 248 | 248 | |
| 249 | - $this->assertEquals(array( |
|
| 250 | - 'target' => 'bar_action', |
|
| 251 | - 'params' => array(), |
|
| 252 | - 'name' => 'bar_route' |
|
| 253 | - ), $this->router->match('/everything', 'GET')); |
|
| 254 | - } |
|
| 249 | + $this->assertEquals(array( |
|
| 250 | + 'target' => 'bar_action', |
|
| 251 | + 'params' => array(), |
|
| 252 | + 'name' => 'bar_route' |
|
| 253 | + ), $this->router->match('/everything', 'GET')); |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - public function testMatchWithCustomRegexp() |
|
| 257 | - { |
|
| 258 | - $this->router->map('GET', '@^/[a-z]*$', 'bar_action', 'bar_route'); |
|
| 256 | + public function testMatchWithCustomRegexp() |
|
| 257 | + { |
|
| 258 | + $this->router->map('GET', '@^/[a-z]*$', 'bar_action', 'bar_route'); |
|
| 259 | 259 | |
| 260 | - $this->assertEquals(array( |
|
| 261 | - 'target' => 'bar_action', |
|
| 262 | - 'params' => array(), |
|
| 263 | - 'name' => 'bar_route' |
|
| 264 | - ), $this->router->match('/everything', 'GET')); |
|
| 260 | + $this->assertEquals(array( |
|
| 261 | + 'target' => 'bar_action', |
|
| 262 | + 'params' => array(), |
|
| 263 | + 'name' => 'bar_route' |
|
| 264 | + ), $this->router->match('/everything', 'GET')); |
|
| 265 | 265 | |
| 266 | - $this->assertFalse($this->router->match('/some-other-thing', 'GET')); |
|
| 267 | - } |
|
| 266 | + $this->assertFalse($this->router->match('/some-other-thing', 'GET')); |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - public function testMatchWithUnicodeRegex() |
|
| 270 | - { |
|
| 271 | - $pattern = '/(?<path>[^'; |
|
| 272 | - // Arabic characters |
|
| 273 | - $pattern .= '\x{0600}-\x{06FF}'; |
|
| 274 | - $pattern .= '\x{FB50}-\x{FDFD}'; |
|
| 275 | - $pattern .= '\x{FE70}-\x{FEFF}'; |
|
| 276 | - $pattern .= '\x{0750}-\x{077F}'; |
|
| 277 | - // Alphanumeric, /, _, - and space characters |
|
| 278 | - $pattern .= 'a-zA-Z0-9\/_\-\s'; |
|
| 279 | - // 'ZERO WIDTH NON-JOINER' |
|
| 280 | - $pattern .= '\x{200C}'; |
|
| 281 | - $pattern .= ']+)'; |
|
| 269 | + public function testMatchWithUnicodeRegex() |
|
| 270 | + { |
|
| 271 | + $pattern = '/(?<path>[^'; |
|
| 272 | + // Arabic characters |
|
| 273 | + $pattern .= '\x{0600}-\x{06FF}'; |
|
| 274 | + $pattern .= '\x{FB50}-\x{FDFD}'; |
|
| 275 | + $pattern .= '\x{FE70}-\x{FEFF}'; |
|
| 276 | + $pattern .= '\x{0750}-\x{077F}'; |
|
| 277 | + // Alphanumeric, /, _, - and space characters |
|
| 278 | + $pattern .= 'a-zA-Z0-9\/_\-\s'; |
|
| 279 | + // 'ZERO WIDTH NON-JOINER' |
|
| 280 | + $pattern .= '\x{200C}'; |
|
| 281 | + $pattern .= ']+)'; |
|
| 282 | 282 | |
| 283 | - $this->router->map('GET', '@' . $pattern, 'unicode_action', 'unicode_route'); |
|
| 283 | + $this->router->map('GET', '@' . $pattern, 'unicode_action', 'unicode_route'); |
|
| 284 | 284 | |
| 285 | - $this->assertEquals(array( |
|
| 286 | - 'target' => 'unicode_action', |
|
| 287 | - 'name' => 'unicode_route', |
|
| 288 | - 'params' => array( |
|
| 289 | - 'path' => '大家好' |
|
| 290 | - ) |
|
| 291 | - ), $this->router->match('/大家好', 'GET')); |
|
| 285 | + $this->assertEquals(array( |
|
| 286 | + 'target' => 'unicode_action', |
|
| 287 | + 'name' => 'unicode_route', |
|
| 288 | + 'params' => array( |
|
| 289 | + 'path' => '大家好' |
|
| 290 | + ) |
|
| 291 | + ), $this->router->match('/大家好', 'GET')); |
|
| 292 | 292 | |
| 293 | - $this->assertFalse($this->router->match('/﷽', 'GET')); |
|
| 294 | - } |
|
| 293 | + $this->assertFalse($this->router->match('/﷽', 'GET')); |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - /** |
|
| 297 | - * @covers Router::setMatchTypes |
|
| 298 | - */ |
|
| 299 | - public function testMatchWithCustomNamedRegex() |
|
| 300 | - { |
|
| 301 | - $this->router->getParser()->setMatchTypes(array('cId' => '[a-zA-Z]{2}[0-9](?:_[0-9]++)?')); |
|
| 302 | - $this->router->map('GET', '/bar/[cId:customId]', 'bar_action', 'bar_route'); |
|
| 296 | + /** |
|
| 297 | + * @covers Router::setMatchTypes |
|
| 298 | + */ |
|
| 299 | + public function testMatchWithCustomNamedRegex() |
|
| 300 | + { |
|
| 301 | + $this->router->getParser()->setMatchTypes(array('cId' => '[a-zA-Z]{2}[0-9](?:_[0-9]++)?')); |
|
| 302 | + $this->router->map('GET', '/bar/[cId:customId]', 'bar_action', 'bar_route'); |
|
| 303 | 303 | |
| 304 | - $this->assertEquals(array( |
|
| 305 | - 'target' => 'bar_action', |
|
| 306 | - 'params' => array( |
|
| 307 | - 'customId' => 'AB1', |
|
| 308 | - ), |
|
| 309 | - 'name' => 'bar_route' |
|
| 310 | - ), $this->router->match('/bar/AB1', 'GET')); |
|
| 304 | + $this->assertEquals(array( |
|
| 305 | + 'target' => 'bar_action', |
|
| 306 | + 'params' => array( |
|
| 307 | + 'customId' => 'AB1', |
|
| 308 | + ), |
|
| 309 | + 'name' => 'bar_route' |
|
| 310 | + ), $this->router->match('/bar/AB1', 'GET')); |
|
| 311 | 311 | |
| 312 | - $this->assertEquals(array( |
|
| 313 | - 'target' => 'bar_action', |
|
| 314 | - 'params' => array( |
|
| 315 | - 'customId' => 'AB1_0123456789', |
|
| 316 | - ), |
|
| 317 | - 'name' => 'bar_route' |
|
| 318 | - ), $this->router->match('/bar/AB1_0123456789', 'GET')); |
|
| 312 | + $this->assertEquals(array( |
|
| 313 | + 'target' => 'bar_action', |
|
| 314 | + 'params' => array( |
|
| 315 | + 'customId' => 'AB1_0123456789', |
|
| 316 | + ), |
|
| 317 | + 'name' => 'bar_route' |
|
| 318 | + ), $this->router->match('/bar/AB1_0123456789', 'GET')); |
|
| 319 | 319 | |
| 320 | - $this->assertFalse($this->router->match('/some-other-thing', 'GET')); |
|
| 321 | - } |
|
| 320 | + $this->assertFalse($this->router->match('/some-other-thing', 'GET')); |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - public function testMatchWithCustomNamedUnicodeRegex() |
|
| 324 | - { |
|
| 325 | - $pattern = '[^'; |
|
| 326 | - // Arabic characters |
|
| 327 | - $pattern .= '\x{0600}-\x{06FF}'; |
|
| 328 | - $pattern .= '\x{FB50}-\x{FDFD}'; |
|
| 329 | - $pattern .= '\x{FE70}-\x{FEFF}'; |
|
| 330 | - $pattern .= '\x{0750}-\x{077F}'; |
|
| 331 | - $pattern .= ']+'; |
|
| 323 | + public function testMatchWithCustomNamedUnicodeRegex() |
|
| 324 | + { |
|
| 325 | + $pattern = '[^'; |
|
| 326 | + // Arabic characters |
|
| 327 | + $pattern .= '\x{0600}-\x{06FF}'; |
|
| 328 | + $pattern .= '\x{FB50}-\x{FDFD}'; |
|
| 329 | + $pattern .= '\x{FE70}-\x{FEFF}'; |
|
| 330 | + $pattern .= '\x{0750}-\x{077F}'; |
|
| 331 | + $pattern .= ']+'; |
|
| 332 | 332 | |
| 333 | - $this->router->getParser()->setMatchTypes(array('nonArabic' => $pattern)); |
|
| 334 | - $this->router->map('GET', '/bar/[nonArabic:string]', 'non_arabic_action', 'non_arabic_route'); |
|
| 333 | + $this->router->getParser()->setMatchTypes(array('nonArabic' => $pattern)); |
|
| 334 | + $this->router->map('GET', '/bar/[nonArabic:string]', 'non_arabic_action', 'non_arabic_route'); |
|
| 335 | 335 | |
| 336 | - $this->assertEquals(array( |
|
| 337 | - 'target' => 'non_arabic_action', |
|
| 338 | - 'name' => 'non_arabic_route', |
|
| 339 | - 'params' => array( |
|
| 340 | - 'string' => 'some-path' |
|
| 341 | - ) |
|
| 342 | - ), $this->router->match('/bar/some-path', 'GET')); |
|
| 336 | + $this->assertEquals(array( |
|
| 337 | + 'target' => 'non_arabic_action', |
|
| 338 | + 'name' => 'non_arabic_route', |
|
| 339 | + 'params' => array( |
|
| 340 | + 'string' => 'some-path' |
|
| 341 | + ) |
|
| 342 | + ), $this->router->match('/bar/some-path', 'GET')); |
|
| 343 | 343 | |
| 344 | - $this->assertFalse($this->router->match('/﷽', 'GET')); |
|
| 345 | - } |
|
| 344 | + $this->assertFalse($this->router->match('/﷽', 'GET')); |
|
| 345 | + } |
|
| 346 | 346 | } |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | $this->router = new Router($parser, [], '', []); |
| 30 | 30 | $this->param1 = ['controller' => 'test', 'action' => 'someaction']; |
| 31 | 31 | $this->param2 = ['controller' => 'test', 'action' => 'someaction', 'type' => 'json']; |
| 32 | - $this->closure = function () { |
|
| 32 | + $this->closure = function() { |
|
| 33 | 33 | }; |
| 34 | 34 | } |
| 35 | 35 | |