Skip to content
Permalink
Browse files

Add tests for plugin() method.

  • Loading branch information...
markstory committed Jun 24, 2014
1 parent f0af8f8 commit 3a595147fd1744e19b2ca94316c77aad3737f66a
Showing with 31 additions and 4 deletions.
  1. +4 −4 src/Routing/ScopedRouteCollection.php
  2. +27 −0 tests/TestCase/Routing/ScopedRouteCollectionTest.php
@@ -471,18 +471,18 @@ public function prefix($name, callable $callback) {
* @param callable $callback The callback to invoke that builds the plugin routes.
* Only required when $options is defined.
* @return void
* @throws \Cake\Error\Exception When an invalid callback is provided
*/
public function plugin($name, $options = [], $callback = null) {
if ($callback === null) {
$callback = $options;
$options = [];
}
$params = ['plugin' => $name];
if (empty($optons['path'])) {
$params = ['plugin' => $name] + $this->_params;
if (empty($options['path'])) {
$options['path'] = '/' . Inflector::underscore($name);
}
return Router::scope($options['path'], $params, $callback);
$options['path'] = $this->_path . $options['path'];
Router::scope($options['path'], $params, $callback);
}
/**
@@ -198,4 +198,31 @@ public function testNestedPrefix() {
$this->assertNull($res);
}
/**
* Test creating sub-scopes with plugin()
*
* @return void
*/
public function testNestedPlugin() {
$routes = new ScopedRouteCollection('/b', ['key' => 'value']);
$res = $routes->plugin('Contacts', function($r) {
$this->assertEquals('/b/contacts', $r->path());
$this->assertEquals(['plugin' => 'Contacts', 'key' => 'value'], $r->params());
});
$this->assertNull($res);
}
/**
* Test creating sub-scopes with plugin() + path option
*
* @return void
*/
public function testNestedPluginPathOption() {
$routes = new ScopedRouteCollection('/b', ['key' => 'value']);
$routes->plugin('Contacts', ['path' => '/people'], function($r) {
$this->assertEquals('/b/people', $r->path());
$this->assertEquals(['plugin' => 'Contacts', 'key' => 'value'], $r->params());
});
}
}

0 comments on commit 3a59514

Please sign in to comment.
You can’t perform that action at this time.