/** * Tests * * @return void */ public function testResetLink() { Router::connect('/:controller/:action/*'); $result = $this->Html->resetLink('Foo', ['controller' => 'foobar', 'action' => 'test']); $expected = '<a href="/foobar/test">Foo</a>'; $this->assertEquals($expected, $result); $this->Html->request->here = '/admin/foobar/test'; $this->Html->request->params['admin'] = true; $this->Html->request->params['prefix'] = 'admin'; Router::reload(); Router::connect('/:controller/:action/*'); Router::prefix('admin', function ($routes) { $routes->connect('/:controller/:action/*'); }); $result = $this->Html->link('Foo', ['prefix' => 'admin', 'controller' => 'foobar', 'action' => 'test']); $expected = '<a href="/admin/foobar/test">Foo</a>'; $this->assertEquals($expected, $result); $result = $this->Html->link('Foo', ['controller' => 'foobar', 'action' => 'test']); $expected = '<a href="/admin/foobar/test">Foo</a>'; //debug($result); //$this->assertEquals($expected, $result); $result = $this->Html->resetLink('Foo', ['controller' => 'foobar', 'action' => 'test']); $expected = '<a href="/foobar/test">Foo</a>'; $this->assertEquals($expected, $result); }
/** * test setting parameters in beforeDispatch method * * @return void */ public function testQueryStringAndCustomTime() { $folder = CACHE . 'views' . DS; $file = $folder . 'posts-home-coffee-life-sleep-sissies-coffee-life-sleep-sissies.html'; $content = '<!--cachetime:' . (time() + WEEK) . ';ext:html-->Foo bar'; file_put_contents($file, $content); Router::reload(); Router::connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']); Router::connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']); Router::connect('/:controller/:action/*'); $_GET = ['coffee' => 'life', 'sleep' => 'sissies']; $filter = new CacheFilter(); $request = new Request('posts/home/?coffee=life&sleep=sissies'); $response = new Response(); $event = new Event(__CLASS__, $this, compact('request', 'response')); $filter->beforeDispatch($event); $result = $response->body(); $expected = '<!--created:'; $this->assertTextStartsWith($expected, $result); $expected = '-->Foo bar'; $this->assertTextEndsWith($expected, $result); $result = $response->type(); $expected = 'text/html'; $this->assertEquals($expected, $result); $result = $response->header(); $this->assertNotEmpty($result['Expires']); // + 1 week unlink($file); }
/** * @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); }
public function setUp() { parent::setUp(); $this->View = new View(); $this->AbsoluteAdmin = new AbsoluteAdminHelper($this->View); Router::connect('/:controller', ['action' => 'index']); Router::connect('/:controller/:action/*'); }
public function setUp() { parent::setUp(); Router::connect('/ann-authorize-test/allowedAction', ['controller' => 'AnnAuthorizeTest', 'action' => 'allowedAction']); Router::connect('/ann-authorize-test/loggedInAction', ['controller' => 'AnnAuthorizeTest', 'action' => 'loggedInAction']); $this->annAuthorizeHelper = new AnnAuthorizeHelper(new View()); $this->annAuthorizeHelper->request = new Request(); }
public function setUp() { parent::setUp(); Router::connect('/test/test', ['controller' => 'Test', 'action' => 'test']); Router::connect('/test/test1', ['controller' => 'Test', 'action' => 'test1']); Router::connect('/test/test2', ['controller' => 'Test', 'action' => 'test2']); Router::connect('/test/test3', ['controller' => 'Test', 'action' => 'test3']); static::$entityActionHelper = new EntityActionHelper(new View()); }
/** * Setup method * * @return void */ public function setUp() { parent::setUp(); Configure::write('App.namespace', 'TestApp'); Router::connect('/:controller/:action/*', [], ['routeClass' => 'InflectedRoute']); DispatcherFactory::clear(); DispatcherFactory::add('Routing'); DispatcherFactory::add('ControllerFactory'); }
/** * Setup * * @return void */ public function setUp() { parent::setUp(); Router::connect('/:controller/:action'); $request = new Request(); $request->addParams(array('controller' => 'pages', 'action' => 'display')); $this->View = new View($request); $this->Toolbar = new ToolbarHelper($this->View); }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); $this->io = $this->getMock('Cake\\Console\\ConsoleIo', ['helper', 'out', 'err']); $this->table = $this->getMock('Cake\\Shell\\Helper\\TableHelper', [], [$this->io]); $this->io->expects($this->any())->method('helper')->with('table')->will($this->returnValue($this->table)); $this->shell = new RoutesShell($this->io); Router::connect('/articles/:action/*', ['controller' => 'Articles']); Router::connect('/bake/:controller/:action', ['plugin' => 'Bake']); Router::connect('/tests/:action/*', ['controller' => 'Tests'], ['_name' => 'testName']); }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); $this->View = new View(); $this->View->Html = new BootstrapHtmlHelper($this->View); $this->Paginator = new BootstrapPaginatorHelper($this->View); $this->Paginator->request = new Request(); $this->Paginator->request->addParams(['paging' => ['Article' => ['page' => 1, 'current' => 9, 'count' => 62, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 7, 'sort' => null, 'direction' => null, 'limit' => null]]]); Configure::write('Routing.prefixes', []); Router::reload(); Router::connect('/:controller/:action/*'); Router::connect('/:plugin/:controller/:action/*'); }
/** * [setUp description] * * @return void */ public function setUp() { parent::setUp(); $this->resetReflectionCache(); $this->_eventManager = EventManager::instance(); $existing = Configure::read('App.paths.templates'); $existing[] = Plugin::path('Crud') . 'tests/App/Template/'; Configure::write('App.paths.templates', $existing); Configure::write('App.namespace', 'Crud\\Test\\App'); Router::extensions('json'); Router::connect('/:controller', ['action' => 'index'], ['routeClass' => 'DashedRoute']); Router::connect('/:controller/:action/*', [], ['routeClass' => 'DashedRoute']); $this->useHttpServer(false); }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); Configure::write('Config.language', 'eng'); $this->View = new View(); $this->Paginator = new PaginatorHelper($this->View); $this->Paginator->Js = $this->getMock('Cake\\View\\Helper\\PaginatorHelper', [], [$this->View]); $this->Paginator->request = new Request(); $this->Paginator->request->addParams(['paging' => ['Article' => ['page' => 1, 'current' => 9, 'count' => 62, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 7, 'sort' => null, 'direction' => null, 'limit' => null]]]); Configure::write('Routing.prefixes', []); Router::reload(); Router::connect('/:controller/:action/*'); Router::connect('/:plugin/:controller/:action/*'); $this->locale = I18n::locale(); }
/** * 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); }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); Configure::write('Security.salt', 'YJfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi'); Configure::write('App.namespace', 'TestApp'); $request = new Request(); $response = $this->getMock('Cake\\Network\\Response', array('stop')); $this->Controller = new AuthTestController($request, $response); $this->Controller->constructClasses(); $this->Auth = new TestAuthComponent($this->Controller->components()); $this->Auth->request = $request; $this->Auth->response = $response; AuthComponent::$sessionKey = 'Auth.User'; $this->initialized = true; Router::reload(); Router::connect('/:controller/:action/*'); $Users = TableRegistry::get('AuthUsers'); $Users->updateAll(['password' => Security::hash('cake', 'blowfish', false)], []); }
public function setUp() { parent::setUp(); Configure::write('Config.language', 'eng'); Configure::write('App.base', ''); Configure::write('App.namespace', 'BootstrapUI\\Test\\TestCase\\View\\Helper'); Configure::delete('Asset'); $this->View = new View(); $this->Form = new FormHelper($this->View); $request = new Request('articles/add'); $request->here = '/articles/add'; $request['controller'] = 'articles'; $request['action'] = 'add'; $request->webroot = ''; $request->base = ''; $this->Form->Url->request = $this->Form->request = $request; $this->article = ['schema' => ['id' => ['type' => 'integer'], 'author_id' => ['type' => 'integer', 'null' => true], 'title' => ['type' => 'string', 'null' => true], 'body' => 'text', 'published' => ['type' => 'boolean', 'length' => 1, 'default' => 0], '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]], 'required' => ['author_id' => true, 'title' => true]]; Security::salt('foo!'); Router::connect('/:controller', ['action' => 'index']); Router::connect('/:controller/:action/*'); }
/** * test setting parameters in beforeDispatch method * * @return void * @triggers __CLASS__ $this, compact(request) * @triggers __CLASS__ $this, compact(request) */ public function testQueryStringOnRoot() { Router::reload(); Router::connect('/', ['controller' => 'pages', 'action' => 'display', 'home']); Router::connect('/pages/*', ['controller' => 'pages', 'action' => 'display']); Router::connect('/:controller/:action/*'); $_GET = ['coffee' => 'life', 'sleep' => 'sissies']; $filter = new RoutingFilter(); $request = new Request('posts/home/?coffee=life&sleep=sissies'); $event = new Event(__CLASS__, $this, compact('request')); $filter->beforeDispatch($event); $this->assertRegExp('/posts/', $request['controller']); $this->assertRegExp('/home/', $request['action']); $this->assertTrue(isset($request['url']['sleep'])); $this->assertTrue(isset($request['url']['coffee'])); $request = new Request('/?coffee=life&sleep=sissy'); $event = new Event(__CLASS__, $this, compact('request')); $filter->beforeDispatch($event); $this->assertRegExp('/pages/', $request['controller']); $this->assertRegExp('/display/', $request['action']); $this->assertTrue(isset($request['url']['sleep'])); $this->assertTrue(isset($request['url']['coffee'])); $this->assertEquals('life', $request['url']['coffee']); }
/** * Test promote() * * @return void */ public function testPromote() { Router::connect('/:controller/:action/*'); Router::connect('/:lang/:controller/:action/*'); $result = Router::url(['controller' => 'posts', 'action' => 'index', 'lang' => 'en']); $this->assertEquals('/posts/index?lang=en', $result, 'First route should match'); Router::promote(); $result = Router::url(['controller' => 'posts', 'action' => 'index', 'lang' => 'en']); $this->assertEquals('/en/posts/index', $result, 'promote() should move 2nd route ahead.'); }
* You can disable the connection of default routes by deleting the require inside APP/Config/routes.php. */ $prefixes = Router::prefixes(); $prefixPattern = implode('|', $prefixes); $plugins = Plugin::loaded(); foreach ($plugins as $key => $value) { $plugins[$key] = Inflector::underscore($value); } $pluginPattern = implode('|', $plugins); $indexParams = ['action' => 'index']; $pluginShortMatch = ['routeClass' => 'Cake\\Routing\\Route\\PluginShortRoute', '_name' => '_plugin._controller:index']; if ($prefixPattern && $pluginPattern) { $match = ['prefix' => $prefixPattern, 'plugin' => $pluginPattern]; Router::connect('/:prefix/:plugin', $indexParams, $match + $pluginShortMatch); Router::connect('/:prefix/:plugin/:controller', $indexParams, $match); Router::connect('/:prefix/:plugin/:controller/:action/*', [], $match); } if ($pluginPattern) { $match = ['plugin' => $pluginPattern]; Router::connect('/:plugin', $indexParams, $match + $pluginShortMatch); Router::connect('/:plugin/:controller', $indexParams, $match); Router::connect('/:plugin/:controller/:action/*', [], $match); } if ($prefixPattern) { $match = ['prefix' => $prefixPattern]; Router::connect('/:prefix/:controller', $indexParams, $match); Router::connect('/:prefix/:controller/:action/*', [], $match); } Router::connect('/:controller', ['action' => 'index']); Router::connect('/:controller/:action/*'); unset($prefixes, $prefixPattern, $plugins, $pluginPattern, $indexParams, $match);
}); /* * Adding default routes for the CakeManager */ Router::plugin('CakeManager', ['path' => '/'], function ($routes) { $routes->fallbacks('InflectedRoute'); }); /** * Default routes for usersController from the CakeManager * * Previous: * manager/users/request * * New: * users/request * */ Router::connect('/users/:action/*', ['plugin' => 'CakeManager', 'prefix' => false, 'controller' => 'Users']); /** * Default login-url */ Router::connect('/login', ['plugin' => 'CakeManager', 'prefix' => false, 'controller' => 'Users', 'action' => 'login']); /** * Default admin-url */ Router::connect('/admin', ['plugin' => 'CakeManager', 'prefix' => false, 'controller' => 'Users', 'action' => 'login']); /** * Default logout-url */ Router::connect('/logout', ['plugin' => 'CakeManager', 'prefix' => false, 'controller' => 'Users', 'action' => 'logout']);
/** * Test generation of UUIDs method * * @return void */ public function testUUIDGeneration() { Router::connect('/:controller', ['action' => 'index']); $result = $this->View->uuid('form', ['controller' => 'posts', 'action' => 'index']); $this->assertEquals('form5988016017', $result); $result = $this->View->uuid('form', ['controller' => 'posts', 'action' => 'index']); $this->assertEquals('formc3dc6be854', $result); $result = $this->View->uuid('form', ['controller' => 'posts', 'action' => 'index']); $this->assertEquals('form28f92cc87f', $result); }
/** * test redirecting with patterns and a routed target * * @expectedException Cake\Routing\Exception\RedirectException * @expectedExceptionMessage http://localhost/nl/preferred_controllers * @expectedExceptionCode 301 * @return void */ public function testParsePersistMatchesAnotherRoute() { Router::connect('/:lang/preferred_controllers', ['controller' => 'tags', 'action' => 'add'], ['lang' => '(nl|en)', 'persist' => ['lang']]); $route = new RedirectRoute('/:lang/my_controllers', ['controller' => 'tags', 'action' => 'add'], ['lang' => '(nl|en)', 'persist' => ['lang']]); $route->parse('/nl/my_controllers/'); }
<?php use Cake\Routing\Router; // registering a route for the CaptchaHandler controller Router::connect('/captcha-handler', array('plugin' => 'CakeCaptcha', 'controller' => 'CaptchaHandler', 'action' => 'index'));
/** * test requestAction() and plugins. * * @return void */ public function testRequestActionPlugins() { Plugin::load('TestPlugin'); Router::reload(); Router::connect('/test_plugin/tests/:action/*', ['controller' => 'Tests', 'plugin' => 'TestPlugin']); $result = $this->object->requestAction('/test_plugin/tests/index', ['return']); $expected = 'test plugin index'; $this->assertEquals($expected, $result); $result = $this->object->requestAction('/test_plugin/tests/index/some_param', ['return']); $expected = 'test plugin index'; $this->assertEquals($expected, $result); $result = $this->object->requestAction(['controller' => 'Tests', 'action' => 'index', 'plugin' => 'TestPlugin'], ['return']); $expected = 'test plugin index'; $this->assertEquals($expected, $result); $result = $this->object->requestAction('/test_plugin/tests/some_method'); $expected = 25; $this->assertEquals($expected, $result); $result = $this->object->requestAction(['controller' => 'Tests', 'action' => 'some_method', 'plugin' => 'TestPlugin']); $expected = 25; $this->assertEquals($expected, $result); }
* `Route` (`Cake\Routing\Route\Route`) * * Note that `Route` does not do any inflections on URLs which will result in * inconsistently cased URLs when used with `:plugin`, `:controller` and * `:action` markers. * */ Router::defaultRouteClass('DashedRoute'); Router::scope('/', function ($routes) { /** * Here, we are connecting '/' (base path) to a controller called 'Pages', * its action called 'display', and we pass a param to select the view file * to use (in this case, src/Template/Pages/home.ctp)... */ Router::connect('/fb_login', array('controller' => 'users', 'action' => 'fb_login')); Router::connect('/fblogin', array('controller' => 'users', 'action' => 'fblogin')); $routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']); /** * ...and connect the rest of 'Pages' controller's URLs. */ $routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']); Router::prefix('admin', function ($routes) { $routes->connect('/admin/*', ['controller' => 'Users', 'action' => 'dashboard']); $routes->fallbacks('InflectedRoute'); }); /** * 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']);`
/** * test create() with a custom route * * @return void */ public function testCreateCustomRoute() { Router::connect('/login', ['controller' => 'users', 'action' => 'login']); $encoding = strtolower(Configure::read('App.encoding')); $this->Form->request['controller'] = 'users'; $result = $this->Form->create(false, ['action' => 'login']); $expected = ['form' => ['method' => 'post', 'action' => '/login', 'accept-charset' => $encoding], 'div' => ['style' => 'display:none;'], 'input' => ['type' => 'hidden', 'name' => '_method', 'value' => 'POST'], '/div']; $this->assertHtml($expected, $result); Router::connect('/new-article', ['controller' => 'articles', 'action' => 'myaction'], ['_name' => 'my-route']); $result = $this->Form->create(false, ['url' => ['_name' => 'my-route']]); $expected = ['form' => ['method' => 'post', 'action' => '/new-article', 'accept-charset' => $encoding], 'div' => ['style' => 'display:none;'], 'input' => ['type' => 'hidden', 'name' => '_method', 'value' => 'POST'], '/div']; $this->assertHtml($expected, $result); }
/** * testMeta method * * @return void */ public function testMeta() { Router::connect('/:controller', array('action' => 'index')); $result = $this->Html->meta('this is an rss feed', array('controller' => 'posts', 'ext' => 'rss')); $this->assertTags($result, array('link' => array('href' => 'preg:/.*\\/posts\\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed'))); $result = $this->Html->meta('rss', array('controller' => 'posts', 'ext' => 'rss'), array('title' => 'this is an rss feed')); $this->assertTags($result, array('link' => array('href' => 'preg:/.*\\/posts\\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed'))); $result = $this->Html->meta('atom', array('controller' => 'posts', 'ext' => 'xml')); $this->assertTags($result, array('link' => array('href' => 'preg:/.*\\/posts\\.xml/', 'type' => 'application/atom+xml', 'title' => 'atom'))); $result = $this->Html->meta('non-existing'); $this->assertTags($result, array('<meta')); $result = $this->Html->meta('non-existing', '/posts.xpp'); $this->assertTags($result, array('link' => array('href' => 'preg:/.*\\/posts\\.xpp/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'non-existing'))); $result = $this->Html->meta('non-existing', '/posts.xpp', array('type' => 'atom')); $this->assertTags($result, array('link' => array('href' => 'preg:/.*\\/posts\\.xpp/', 'type' => 'application/atom+xml', 'title' => 'non-existing'))); $result = $this->Html->meta('atom', array('controller' => 'posts', 'ext' => 'xml'), array('link' => '/articles.rss')); $this->assertTags($result, array('link' => array('href' => 'preg:/.*\\/articles\\.rss/', 'type' => 'application/atom+xml', 'title' => 'atom'))); $result = $this->Html->meta('keywords', 'these, are, some, meta, keywords'); $this->assertTags($result, array('meta' => array('name' => 'keywords', 'content' => 'these, are, some, meta, keywords'))); $result = $this->Html->meta('description', 'this is the meta description'); $this->assertTags($result, array('meta' => array('name' => 'description', 'content' => 'this is the meta description'))); $result = $this->Html->meta('robots', 'ALL'); $this->assertTags($result, array('meta' => array('name' => 'robots', 'content' => 'ALL'))); }
/** * test that the beforeRedirect callback properly converts * array URLs into their correct string ones, and adds base => false so * the correct URLs are generated. * * @link https://cakephp.lighthouseapp.com/projects/42648-cakephp-1x/tickets/276 * @return void * @triggers Controller.beforeRender $this->Controller */ public function testBeforeRedirectCallbackWithArrayUrl() { Configure::write('App.namespace', 'TestApp'); Router::connect('/:controller/:action/*'); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; $event = new Event('Controller.beforeRender', $this->Controller); Router::setRequestInfo([['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => []], ['base' => '', 'here' => '/accounts/', 'webroot' => '/']]); $RequestHandler = new RequestHandlerComponent($this->Controller->components()); $RequestHandler->request = new Request('posts/index'); $RequestHandler->response = $this->Controller->response; ob_start(); $RequestHandler->beforeRedirect($event, ['controller' => 'RequestHandlerTest', 'action' => 'param_method', 'first', 'second'], $this->Controller->response); $result = ob_get_clean(); $this->assertEquals('one: first two: second', $result); }
<?php use Cake\Routing\Router; Router::plugin('Editorial/Summernote', function ($routes) { $routes->fallbacks(); }); Router::connect('summernote/files/list', ['plugin' => 'Editorial/Summernote', 'controller' => 'Filesystem', 'action' => 'callback']);
/*------------------------------------------------------------------------------------------------------------ * api route json * * @input * @output * * @author Le Hung <*****@*****.**> * @license http://www.opensource.org/licenses/mit-license.php The MIT License * @created 201512 -------------------------------------------------------------------------------------------------------------*/ // Router::extensions(['json', 'xml']); // test api no route Router::prefix('api', function ($routes) { $routes->extensions(['json', 'xml']); $routes->resources('Ranklogs'); $routes->resources('Users'); Router::connect('/api/users/register', ['controller' => 'Users', 'action' => 'add', 'prefix' => 'api']); $routes->fallbacks('InflectedRoute'); }); Router::scope('/', function ($routes) { /*------------------------------------------------------------------------------------------------------------ * api route Ranklogs * * @input * @output * * @author Le Hung <*****@*****.**> * @license http://www.opensource.org/licenses/mit-license.php The MIT License * @created 201512 -------------------------------------------------------------------------------------------------------------*/ // $routes->resources('Ranklogs'); // test api no route /**
/** * testMeta method * * @return void */ public function testMeta() { Router::connect('/:controller', ['action' => 'index']); $result = $this->Html->meta('this is an rss feed', ['controller' => 'posts', '_ext' => 'rss']); $expected = ['link' => ['href' => 'preg:/.*\\/posts\\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed']]; $this->assertHtml($expected, $result); $result = $this->Html->meta('rss', ['controller' => 'posts', '_ext' => 'rss'], ['title' => 'this is an rss feed']); $expected = ['link' => ['href' => 'preg:/.*\\/posts\\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed']]; $this->assertHtml($expected, $result); $result = $this->Html->meta('atom', ['controller' => 'posts', '_ext' => 'xml']); $expected = ['link' => ['href' => 'preg:/.*\\/posts\\.xml/', 'type' => 'application/atom+xml', 'title' => 'atom']]; $this->assertHtml($expected, $result); $result = $this->Html->meta('non-existing'); $expected = ['<meta']; $this->assertHtml($expected, $result); $result = $this->Html->meta('non-existing', 'some content'); $expected = ['meta' => ['name' => 'non-existing', 'content' => 'some content']]; $this->assertHtml($expected, $result); $result = $this->Html->meta('non-existing', '/posts.xpp', ['type' => 'atom']); $expected = ['link' => ['href' => 'preg:/.*\\/posts\\.xpp/', 'type' => 'application/atom+xml', 'title' => 'non-existing']]; $this->assertHtml($expected, $result); $result = $this->Html->meta('atom', ['controller' => 'posts', '_ext' => 'xml'], ['link' => '/articles.rss']); $expected = ['link' => ['href' => 'preg:/.*\\/articles\\.rss/', 'type' => 'application/atom+xml', 'title' => 'atom']]; $this->assertHtml($expected, $result); $result = $this->Html->meta('keywords', 'these, are, some, meta, keywords'); $expected = ['meta' => ['name' => 'keywords', 'content' => 'these, are, some, meta, keywords']]; $this->assertHtml($expected, $result); $result = $this->Html->meta('description', 'this is the meta description'); $expected = ['meta' => ['name' => 'description', 'content' => 'this is the meta description']]; $this->assertHtml($expected, $result); $result = $this->Html->meta('robots', 'ALL'); $expected = ['meta' => ['name' => 'robots', 'content' => 'ALL']]; $this->assertHtml($expected, $result); $result = $this->Html->meta('viewport', 'width=device-width'); $expected = ['meta' => ['name' => 'viewport', 'content' => 'width=device-width']]; $this->assertHtml($expected, $result); $result = $this->Html->meta(['property' => 'og:site_name', 'content' => 'CakePHP']); $expected = ['meta' => ['property' => 'og:site_name', 'content' => 'CakePHP']]; $this->assertHtml($expected, $result); }