/** * @return void */ public function testBuildResetWithPlugin() { Router::connect('/:controller/:action/*'); $result = $this->Url->buildReset(['controller' => 'foobar', 'action' => 'test']); $expected = '/foobar/test'; $this->assertSame($expected, $result); $this->Url->request->here = '/admin/foo/bar/baz/test'; $this->Url->request->params['prefix'] = 'admin'; $this->Url->request->params['plugin'] = 'Foo'; Router::reload(); Router::connect('/:controller/:action/*'); Router::plugin('Foo', function ($routes) { $routes->fallbacks(); }); Router::prefix('admin', function ($routes) { $routes->plugin('Foo', function ($routes) { $routes->fallbacks(); }); }); Plugin::routes(); Router::pushRequest($this->Url->request); $result = $this->Url->build(['controller' => 'bar', 'action' => 'baz', 'x']); $expected = '/admin/foo/bar/baz/x'; $this->assertSame($expected, $result); $result = $this->Url->buildReset(['controller' => 'bar', 'action' => 'baz', 'x']); $expected = '/bar/baz/x'; $this->assertSame($expected, $result); }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); Plugin::routes('CakeDC/Users'); $this->View = $this->getMock('Cake\\View\\View', ['append']); $this->User = new UserHelper($this->View); $this->request = new Request(); }
/** * setUp * * @return void */ public function setUp() { $this->traitClassName = 'CakeDC\\Users\\Controller\\Traits\\RegisterTrait'; $this->traitMockMethods = ['validate', 'dispatchEvent', 'set', 'validateReCaptcha', 'redirect']; $this->mockDefaultEmail = true; parent::setUp(); Plugin::routes('CakeDC/Users'); }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); $this->Users = TableRegistry::get('CakeDC/Users.Users'); $this->fullBaseBackup = Router::fullBaseUrl(); Router::fullBaseUrl('http://users.test'); Email::configTransport('test', ['className' => 'Debug']); $this->configEmail = Email::config('default'); Email::config('default', ['transport' => 'test', 'from' => '*****@*****.**']); $this->Email = new Email(['from' => '*****@*****.**', 'transport' => 'test']); Plugin::routes('CakeDC/Users'); }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); Plugin::routes('CakeDC/Users'); $this->View = $this->getMockBuilder('Cake\\View\\View')->setMethods(['append'])->getMock(); //Assuming all these url's are authorized $this->AuthLink = $this->getMockBuilder('CakeDC\\Users\\View\\Helper\\AuthLinkHelper')->setMethods(['isAuthorized'])->setConstructorArgs([$this->View])->getMock(); $this->AuthLink->expects($this->any())->method('isAuthorized')->will($this->returnValue(true)); $this->User = new UserHelper($this->View); $this->User->AuthLink = $this->AuthLink; $this->request = new Request(); }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); $this->backupUsersConfig = Configure::read('Users'); Router::reload(); Plugin::routes('CakeDC/Users'); Router::connect('/route/*', ['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'requestResetPassword']); Security::salt('YJfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi'); Configure::write('App.namespace', 'Users'); $this->request = $this->getMock('Cake\\Network\\Request', ['is', 'method']); $this->request->expects($this->any())->method('is')->will($this->returnValue(true)); $this->response = $this->getMock('Cake\\Network\\Response', ['stop']); $this->Controller = new Controller($this->request, $this->response); $this->Registry = $this->Controller->components(); $this->Controller->UsersAuth = new UsersAuthComponent($this->Registry); }
$routes->connect('/admin/edit/*', ['controller' => 'Users', 'action' => 'adminEdit']); $routes->connect('/tickets/add/*', ['controller' => 'Tickets', 'action' => 'add']); $routes->connect('/tickets/delete/*', ['controller' => 'Tickets', 'action' => 'delete']); /** * ...and connect the rest of 'Pages' controller's URLs. */ $routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']); /** * Connect catchall routes for all controllers. * * Using the argument `DashedRoute`, the `fallbacks` method is a shortcut for * `$routes->connect('/:controller', ['action' => 'index'], ['routeClass' => 'DashedRoute']);` * `$routes->connect('/:controller/:action/*', [], ['routeClass' => 'DashedRoute']);` * * Any route class can be used with this method, such as: * - DashedRoute * - InflectedRoute * - Route * - Or your own route class * * You can remove these routes once you've connected the * routes you want in your application. */ $routes->fallbacks('DashedRoute'); }); /** * Load all plugin routes. See the Plugin documentation on * how to customize the loading of plugin routes. */ Plugin::routes();
/** * Tests that Plugin::loadAll() will load all plgins in the configured folder wit defaults * and overrides for a plugin * * @return void */ public function testLoadAllWithDefaultsAndOverride() { Plugin::loadAll(array(array('bootstrap' => true, 'ignoreMissing' => true), 'TestPlugin' => array('routes' => true))); Plugin::routes(); $expected = ['Company', 'PluginJs', 'TestPlugin', 'TestPluginTwo']; $this->assertEquals($expected, Plugin::loaded()); $this->assertEquals('loaded js plugin bootstrap', Configure::read('PluginTest.js_plugin.bootstrap')); $this->assertEquals('loaded plugin routes', Configure::read('PluginTest.test_plugin.routes')); $this->assertEquals(null, Configure::read('PluginTest.test_plugin.bootstrap')); $this->assertEquals('loaded plugin two bootstrap', Configure::read('PluginTest.test_plugin_two.bootstrap')); }
/** * Ensures that nested plugins are correctly created * * @return void */ public function testUpdateWithPlugins() { Plugin::unload(); Plugin::load('TestPlugin', ['routes' => true]); Plugin::load('Nested/TestPluginTwo'); Plugin::routes(); $this->_clean(); $this->Task->expects($this->atLeast(3))->method('getControllerList')->will($this->returnCallback(function ($plugin, $prefix) { switch ($plugin) { case 'TestPlugin': return ['PluginController.php']; case 'Nested/TestPluginTwo': if ($prefix !== null) { return []; } return ['PluginTwoController.php']; default: if ($prefix !== null) { return ['PostsController.php', 'BigLongNamesController.php']; } return ['CommentsController.php', 'PostsController.php', 'BigLongNamesController.php']; } })); $this->Task->startup(); $this->Task->acoUpdate(); $Aco = $this->Task->Acl->Aco; $result = $Aco->node('controllers/TestPlugin/Plugin'); $this->assertNotFalse($result); $this->assertEquals($result->toArray()[0]['alias'], 'Plugin'); $result = $Aco->node('controllers/TestPlugin/Admin/Plugin'); $this->assertNotFalse($result); $this->assertEquals($result->toArray()[0]['alias'], 'Plugin'); $result = $Aco->node('controllers/Nested\\TestPluginTwo/PluginTwo'); $this->assertNotFalse($result); $result = $result->toArray(); $this->assertEquals($result[0]['alias'], 'PluginTwo'); $result = $Aco->find('children', ['for' => $result[0]['id']])->toArray(); $this->assertEquals(count($result), 3); $this->assertEquals($result[0]['alias'], 'index'); $this->assertEquals($result[1]['alias'], 'add'); $this->assertEquals($result[2]['alias'], 'edit'); }
/** * Run Plugin::routes() */ private static function _pluginRoutes() { if (!self::_isExecuted('\\Cake\\Core\\Plugin::routes()')) { CakePlugin::routes(); self::setExecuted('\\Cake\\Core\\Plugin::routes()'); // Debugging if (self::$_debug) { self::_addToDump('\\Cake\\Core\\Plugin::routes();' . "\n"); } } }
* * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project * @license http://www.opensource.org/licenses/mit-license.php MIT License */ use Cake\Core\Configure; use Cake\Core\Plugin; use Cake\Datasource\ConnectionManager; use Cake\Event\EventManager; use Cake\Log\Log; use Cake\Routing\DispatcherFactory; use DebugKit\Routing\Filter\DebugBarFilter; $debugBar = new DebugBarFilter(EventManager::instance(), (array) Configure::read('DebugKit')); if (!$debugBar->isEnabled() || php_sapi_name() === 'cli' || php_sapi_name() === 'phpdbg') { return; } $hasDebugKitConfig = ConnectionManager::config('debug_kit'); if (!$hasDebugKitConfig && !in_array('sqlite', PDO::getAvailableDrivers())) { $msg = 'DebugKit not enabled. You need to either install pdo_sqlite, ' . 'or define the "debug_kit" connection name.'; Log::warning($msg); return; } if (!$hasDebugKitConfig) { ConnectionManager::config('debug_kit', ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Sqlite', 'database' => TMP . 'debug_kit.sqlite', 'encoding' => 'utf8', 'cacheMetadata' => true, 'quoteIdentifiers' => false]); } if (Plugin::routes('DebugKit') === false) { require __DIR__ . DS . 'routes.php'; } // Setup toolbar $debugBar->setup(); DispatcherFactory::add($debugBar);
/** * Run Plugin::routes() */ private function _pluginRoutes() { if (!self::_isExecuted('\\Cake\\Core\\Plugin::routes()')) { CakePlugin::routes(); $this->_setExecuted('\\Cake\\Core\\Plugin::routes()'); // Debugging if ($this->_debug) { $this->_addToDump('\\Cake\\Core\\Plugin::routes();' . "\n"); } } }
/** * Tests that Plugin::loadAll() will load all plugins in the configured folder wit defaults * and overrides for a plugin * * @return void */ public function testLoadAllWithDefaultsAndOverride() { Plugin::loadAll([['bootstrap' => true, 'ignoreMissing' => true], 'TestPlugin' => ['routes' => true], 'TestPluginFour' => ['bootstrap' => true, 'classBase' => '']]); Plugin::routes(); $expected = ['Company', 'PluginJs', 'TestPlugin', 'TestPluginFour', 'TestPluginTwo', 'TestTheme']; $this->assertEquals($expected, Plugin::loaded()); $this->assertEquals('loaded js plugin bootstrap', Configure::read('PluginTest.js_plugin.bootstrap')); $this->assertEquals('loaded plugin routes', Configure::read('PluginTest.test_plugin.routes')); $this->assertEquals(null, Configure::read('PluginTest.test_plugin.bootstrap')); $this->assertEquals('loaded plugin two bootstrap', Configure::read('PluginTest.test_plugin_two.bootstrap')); $this->assertEquals('loaded plugin four bootstrap', Configure::read('PluginTest.test_plugin_four.bootstrap')); // TestPluginThree won't get loaded by loadAll() since it's in a sub directory. $this->assertEquals(null, Configure::read('PluginTest.test_plugin_three.bootstrap')); }