/** * Helper method to create an test API request (with the appropriate detector) */ protected function _apiRequest($params) { $request = new CakeRequest(); $request->addParams($params); $request->addDetector('api', array('callback' => array('CroogoRouter', 'isApiRequest'))); return $request; }
public function testIs() { $result = Reveal::is('App.online'); $expected = !in_array(gethostbyname('google.com'), array('google.com', false)); $this->assertEqual($result, $expected); $result = Reveal::is('DebugKit.loaded'); $expected = CakePlugin::loaded('DebugKit'); $this->assertEqual($result, $expected); $result = Reveal::is(array('OR' => array('DebugKit.enabled', 'DebugKit.automated'))); $expected = Configure::read('debug') || Configure::read('DebugKit.forceEnable') || Configure::read('DebugKit.autoRun'); $this->assertEqual($result, $expected); $_GET['debug'] = 'true'; $this->assertTrue(Reveal::is('DebugKit.requested')); $result = Reveal::is('DebugKit.loaded', array('OR' => array('DebugKit.enabled', array('AND' => array('DebugKit.automated', 'DebugKit.requested'))))); $expected = CakePlugin::loaded('DebugKit') || Configure::read('debug') || Configure::read('DebugKit.forceEnable') || Configure::read('DebugKit.autoRun') && isset($_GET['debug']) && 'true' == $_GET['debug']; $this->assertEqual($result, $expected); $this->assertEqual(Reveal::is('DebugKit.running'), $expected); $request = new CakeRequest(); Router::setRequestInfo($request->addParams(array('controller' => 'pages', 'action' => 'display', 'pass' => array('home')))); $result = Reveal::is('Page.front'); $this->assertTrue($result); Router::reload(); $request = new CakeRequest(); Router::setRequestInfo($request->addParams(array('prefix' => 'admin', 'admin' => true))); $result = Reveal::is('Page.prefixed'); $this->assertTrue($result); Router::reload(); $request = new CakeRequest(); Router::setRequestInfo($request->addParams(array('controller' => 'users', 'action' => 'login'))); $result = Reveal::is('Page.login'); $this->assertTrue($result); $this->assertTrue(Reveal::is('Page.test')); }
/** * beforeDispatch Event * * @param CakeEvent $event イベント * @return void|CakeResponse */ public function beforeDispatch(CakeEvent $event) { $request = $event->data['request']; $response = $event->data['response']; if (!empty($request->params['Content'])) { return; } else { if ($this->_existController($request)) { return; } } $site = BcSite::findCurrent(); if (!$site || !$site->enabled) { return; } $mainSite = $site->getMain(); if (!$mainSite) { return; } $mainSiteUrl = '/' . preg_replace('/^' . $site->alias . '\\//', '', $request->url); if ($mainSite->alias) { $mainSiteUrl = '/' . $mainSite->alias . $mainSiteUrl; } if ($mainSiteUrl) { $request = new CakeRequest($mainSiteUrl); $params = Router::parse($request->url); $request->addParams($params); if ($this->_existController($request)) { $response->header('Location', $request->base . $mainSiteUrl); $response->statusCode(302); return $response; } } return; }
public function testPrefixedAllowedActions() { $request = new CakeRequest('/admin/users/view/3'); $request->addParams(array('admin' => true, 'controller' => 'users', 'action' => 'admin_add', 3)); $response = $this->getMock('CakeRequest'); $this->Controller = new AclFilterTestController($request, $response); $this->Controller->constructClasses(); $user = array('id' => 3, 'role_id' => 3, 'username' => 'yvonne'); $this->Controller->Session->write('Auth.User', $user); $aro = array('Role' => array('id' => 3)); $aco = 'controllers/Users/admin_add'; // Role.3 has no access to Users/admin_add yet $allowed = $this->Controller->Acl->check($aro, $aco); $this->assertEquals(false, $allowed); // grant access to /admin/users/view to Role.3 $this->Controller->Acl->allow($aro, $aco); // new permission active $allowed = $this->Controller->Acl->check($aro, $aco); $this->assertEquals(true, $allowed); // and gets picked up by AclFilterComponent::auth() correctly $this->Controller->startupProcess(); $this->Controller->AclFilter->auth(); $result = $this->Controller->Auth->allowedActions; $this->assertEquals(array('admin_add'), $result); }
/** * construct method * * @param CakeRequest $request Current request. * @param CakeResponse $response Current request. */ public function __construct($request, $response) { $request->addParams(Router::parse('/auth_test')); $request->here = '/auth_test'; $request->webroot = '/'; Router::setRequestInfo($request); parent::__construct($request, $response); }
/** * test check() failing * * @return void */ public function testAuthorizeCheckFailure() { $request = new CakeRequest('posts/index', false); $request->addParams(array('controller' => 'posts', 'action' => 'index')); $user = array('User' => array('user' => 'mark')); $this->_mockAcl(); $this->Acl->expects($this->once())->method('check')->with($user, 'Posts', 'read')->will($this->returnValue(false)); $this->assertFalse($this->auth->authorize($user['User'], $request)); }
protected function _buildFakeRequest($controllerName, $action, $params = array()) { $url = '/' . $controllerName . '/' . $action; if (count($params) > 0) { $url .= '/' . join($params, '/'); } $request = new CakeRequest($url, false); $request->addParams(array('plugin' => null, 'controller' => $controllerName, 'action' => $action, 'pass' => $params)); return $request; }
/** * Tests the getResponses() method in combination with the 'extUpload' request parameter. If this parameter is true, * the response should not be JSON encoded but rather a valid HTML structure which contains the result inside a * <textarea>-element. * */ public function testGetResponses_extUpload() { $response1 = array('body' => array('message' => 'Hello World')); $request = new CakeRequest(); $request->addParams(array('controller' => 'foo', 'action' => 'bar', 'extUpload' => true)); $collection = new BanchaResponseCollection(); $collection->addResponse(2, new CakeResponse($response1), $request); $expected = '<html><body><textarea>[{"type":"rpc","tid":2,"action":"foo","method":"bar",' . '"result":' . json_encode($response1['body']) . ',"extUpload":true}]</textarea></body></html>'; $this->assertEquals($expected, $collection->getResponses()->body()); }
public function testLinkstringRuleWithQueryString() { $request = new CakeRequest(); $request->addParams(array('controller' => 'nodes', 'plugin' => 'nodes', 'action' => 'index', 'type' => 'blog')); $request->query = array('page' => '8'); $Filter = new VisibilityFilter($request); $blocks = $this->_testData(); Configure::write('foo', true); $results = $Filter->remove($blocks, array('model' => 'Block', 'field' => 'visibility_paths')); // exact match with query string $this->assertTrue(Hash::check($results, '{n}.Block[id=6]')); }
public function startTest($method) { Router::connect('/', array('controller' => 'document_tests', 'action' => 'index')); $request = new CakeRequest('/'); $request->addParams(Router::parse('/')); $this->Controller = new DocumentTestsController($request); $this->Controller->uses = array('Document'); if (array_search($method, array('testPersistence')) !== false) { $this->Controller->components = array('Session', 'Filter.Filter' => array('nopersist' => true)); } else { $this->Controller->components = array('Session', 'Filter.Filter'); } $this->Controller->constructClasses(); $this->Controller->Session->destroy(); $this->Controller->Components->trigger('initialize', array($this->Controller)); }
/** * Check to see if the currently logged in user is authorized to perform * an action on a certain controller (with certain params). * @param string $controller The name of the controller the user wants to act on. * @param string $action The action the user wants to perform. * @param array $params Any parameters for the action. * @return bool True if user is authorized to perform the action, false otherwise. */ public function isAuthorized($controller, $action, $params = array()) { // Build the url and CakeRequest $url = '/' . $controller . '/' . $action; if (count($params) > 0) { $url .= '/' . join($params, '/'); } $request = new CakeRequest($url, false); $request->addParams(array('plugin' => null, 'controller' => $controller, 'action' => $action, 'pass' => $params)); // Grab the controller, this may have to create it :( $controllerObj = $this->__getController($controller); // Have to call beforeFilter to set-up the auth properly $controllerObj->beforeFilter(); // First we need to check if the user must be logged in to do this action $allowedActions = $controllerObj->Auth->allowedActions; $isAllowed = $allowedActions == array('*') || in_array($action, array_map('strtolower', $allowedActions)); if ($isAllowed) { return true; } $user = AuthComponent::user(); return $controllerObj->Auth->isAuthorized($user, $request); }
/** * Takes parameter and path information back from the Dispatcher, sets these * parameters as the current request parameters that are merged with URL arrays * created later in the request. * * Nested requests will create a stack of requests. You can remove requests using * Router::popRequest(). This is done automatically when using Object::requestAction(). * * Will accept either a CakeRequest object or an array of arrays. Support for * accepting arrays may be removed in the future. * * @param CakeRequest|array $request Parameters and path information or a CakeRequest object. * @return void */ public static function setRequestInfo($request) { if ($request instanceof CakeRequest) { self::$_requests[] = $request; } else { $requestObj = new CakeRequest(); $request += array(array(), array()); $request[0] += array('controller' => false, 'action' => false, 'plugin' => null); $requestObj->addParams($request[0])->addPaths($request[1]); self::$_requests[] = $requestObj; } }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); $request = new CakeRequest('posts/index', false); $request->addParams(array('controller' => 'posts', 'action' => 'index')); $this->Controller = new SecurityTestController($request); $this->Controller->Components->init($this->Controller); $this->Controller->Security = $this->Controller->TestSecurity; $this->Controller->Security->blackHoleCallback = 'fail'; $this->Security = $this->Controller->Security; $this->Security->csrfCheck = false; Configure::write('Security.salt', 'foo!'); }
public function testIgnoreRequests() { $ignored = Configure::read('NewRelic.ignoreRoutes'); Configure::write('NewRelic.ignoreRoutes', array('/admin/:controller/:action/*', '/:controller/edit/*', '/new_relic_user_test/:action/5')); $testSucceed = array('/new_relic_test/index', '/new_relic_user_test/view/3'); foreach ($testSucceed as $testUrl) { $filter = $this->_getNewRelicMock(); $filter->expects($this->once())->method('hasNewRelic')->will($this->returnValue(true)); $filter->expects($this->never())->method('ignoreTransaction'); $response = $this->getMock('CakeResponse', array('_sendHeader')); $request = new CakeRequest($testUrl); $request->addParams(Router::parse($testUrl)); $event = new CakeEvent('Dispatcher.beforeRequest', $this, compact('request', 'response')); $this->assertTrue($filter->beforeDispatch($event)); $this->assertFalse($event->isStopped()); } $testFail = array('/admin/new_relic_test/index', '/new_relic_user_test/edit', '/new_relic_user_test/edit/3', '/new_relic_user_test/view/5'); foreach ($testFail as $testUrl) { $filter = $this->_getNewRelicMock(); $filter->expects($this->once())->method('hasNewRelic')->will($this->returnValue(true)); $filter->expects($this->once())->method('ignoreTransaction'); $response = $this->getMock('CakeResponse', array('_sendHeader')); $request = new CakeRequest($testUrl); $request->addParams(Router::parse($testUrl)); $event = new CakeEvent('Dispatcher.beforeRequest', $this, compact('request', 'response')); $this->assertTrue($filter->beforeDispatch($event)); $this->assertFalse($event->isStopped()); } Configure::write('NewRelic.ignoreRoutes', $ignored); }
/** * test addParams() method * * @return void */ function testAddParams() { $request = new CakeRequest('some/path'); $request->params = array('controller' => 'posts', 'action' => 'view'); $result = $request->addParams(array('plugin' => null, 'action' => 'index')); $this->assertIdentical($result, $request, 'Method did not return itself. %s'); $this->assertEqual($request->controller, 'posts'); $this->assertEqual($request->action, 'index'); $this->assertEqual($request->plugin, null); }
/** * test scope failure. * * @return void */ public function testAuthenticateFailReChallenge() { $this->auth->settings['scope'] = array('user' => 'nate'); $request = new CakeRequest('posts/index', false); $request->addParams(array('pass' => array(), 'named' => array())); $_SERVER['PHP_AUTH_USER'] = '******'; $_SERVER['PHP_AUTH_PW'] = 'password'; $this->response->expects($this->at(0))->method('header')->with('WWW-Authenticate: Basic realm="localhost"'); $this->response->expects($this->at(1))->method('statusCode')->with(401); $this->response->expects($this->at(2))->method('send'); $this->assertFalse($this->auth->authenticate($request, $this->response)); }
/** * test reversing parameter arrays back into strings. * * @return void */ function testRouterReverse() { $params = array('controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'named' => array(), 'url' => array(), 'autoRender' => 1, 'bare' => 1, 'return' => 1, 'requested' => 1); $result = Router::reverse($params); $this->assertEqual($result, '/posts/view/1'); $params = array('controller' => 'posts', 'action' => 'index', 'pass' => array(1), 'named' => array('page' => 1, 'sort' => 'Article.title', 'direction' => 'desc'), 'url' => array()); $result = Router::reverse($params); $this->assertEqual($result, '/posts/index/1/page:1/sort:Article.title/direction:desc'); Router::connect('/:lang/:controller/:action/*', array(), array('lang' => '[a-z]{3}')); $params = array('lang' => 'eng', 'controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'named' => array(), 'url' => array('url' => 'eng/posts/view/1')); $result = Router::reverse($params); $this->assertEqual($result, '/eng/posts/view/1'); $params = array('lang' => 'eng', 'controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'named' => array(), 'url' => array('url' => 'eng/posts/view/1', 'foo' => 'bar', 'baz' => 'quu'), 'paging' => array(), 'models' => array()); $result = Router::reverse($params); $this->assertEqual($result, '/eng/posts/view/1?foo=bar&baz=quu'); $request = new CakeRequest('/eng/posts/view/1'); $request->addParams(array('lang' => 'eng', 'controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'named' => array(), 'url' => array('url' => 'eng/posts/view/1'))); $result = Router::reverse($request); }
/** * Test Setup Component */ public function testSetupComponent() { $request = new CakeRequest('/api/v1.0/users'); $request->addParams(array('api' => 'api', 'prefix' => 'v1.0')); $controller = new TestAppController($request); $defaultComponents = $controller->components; $this->assertEmpty($controller->_apiComponents); $key = 'Hook.controller_properties.TestApp._apiComponents'; Configure::write($key, array('BogusApi')); Croogo::hookApiComponent('TestApp', 'Example.ImaginaryApi'); $expected = array('BogusApi' => array('className' => 'BogusApi', 'priority' => 8), 'ImaginaryApi' => array('className' => 'Example.ImaginaryApi', 'priority' => 8)); $controller = new TestAppController($request); $this->assertEquals($expected, $controller->_apiComponents); $merged = Hash::merge($defaultComponents, array('BogusApi'), array('Example.ImaginaryApi' => array('priority' => 8))); $this->assertEquals($merged, $controller->components); Configure::delete('Hook.controller_properties.TestApp'); }
/** * testNumbers method * * @return void */ public function testNumbers() { $this->Paginator->request->params['paging'] = array('Client' => array('page' => 8, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, 'options' => array('page' => 1), 'paramType' => 'named')); $result = $this->Paginator->numbers(); $expected = array(array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', ' | ', array('span' => array('class' => 'current')), '8', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span'); $this->assertTags($result, $expected); $result = $this->Paginator->numbers(array('tag' => 'li')); $expected = array(array('li' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/li', ' | ', array('li' => array('class' => 'current')), '8', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/li'); $this->assertTags($result, $expected); $result = $this->Paginator->numbers(array('tag' => 'li', 'separator' => false)); $expected = array(array('li' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/li', array('li' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/li', array('li' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/li', array('li' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/li', array('li' => array('class' => 'current')), '8', '/li', array('li' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/li', array('li' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/li', array('li' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/li', array('li' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/li'); $this->assertTags($result, $expected); $result = $this->Paginator->numbers(true); $expected = array(array('span' => array()), array('a' => array('href' => '/', 'rel' => 'first')), 'first', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', ' | ', array('span' => array('class' => 'current')), '8', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:15', 'rel' => 'last')), 'last', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging'] = array('Client' => array('page' => 1, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, 'options' => array('page' => 1), 'paramType' => 'named')); $result = $this->Paginator->numbers(); $expected = array(array('span' => array('class' => 'current')), '1', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging'] = array('Client' => array('page' => 14, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, 'options' => array('page' => 1), 'paramType' => 'named')); $result = $this->Paginator->numbers(); $expected = array(array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span', ' | ', array('span' => array('class' => 'current')), '14', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:15')), '15', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging'] = array('Client' => array('page' => 2, 'current' => 3, 'count' => 27, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 9, 'options' => array('page' => 1), 'paramType' => 'named')); $result = $this->Paginator->numbers(array('first' => 1, 'class' => 'page-link')); $expected = array(array('span' => array('class' => 'page-link')), array('a' => array('href' => '/')), '1', '/a', '/span', ' | ', array('span' => array('class' => 'current page-link')), '2', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span'); $this->assertTags($result, $expected); $result = $this->Paginator->numbers(array('first' => 1, 'currentClass' => 'active')); $expected = array(array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span', ' | ', array('span' => array('class' => 'active')), '2', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span'); $this->assertTags($result, $expected); $result = $this->Paginator->numbers(array('first' => 1, 'tag' => 'li', 'currentClass' => 'active', 'currentTag' => 'a')); $expected = array(array('li' => array()), array('a' => array('href' => '/')), '1', '/a', '/li', ' | ', array('li' => array('class' => 'active')), array('a' => array()), '2', '/a', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/li'); $this->assertTags($result, $expected); $result = $this->Paginator->numbers(array('first' => 1, 'class' => 'page-link', 'currentClass' => 'active')); $expected = array(array('span' => array('class' => 'page-link')), array('a' => array('href' => '/')), '1', '/a', '/span', ' | ', array('span' => array('class' => 'active page-link')), '2', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span'); $this->assertTags($result, $expected); $result = $this->Paginator->numbers(array('last' => 1)); $expected = array(array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span', ' | ', array('span' => array('class' => 'current')), '2', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging'] = array('Client' => array('page' => 15, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, 'options' => array('page' => 1), 'paramType' => 'named')); $result = $this->Paginator->numbers(array('first' => 1)); $expected = array(array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span', '...', array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:14')), '14', '/a', '/span', ' | ', array('span' => array('class' => 'current')), '15', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging'] = array('Client' => array('page' => 10, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, 'options' => array('page' => 1), 'paramType' => 'named')); $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1)); $expected = array(array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span', '...', array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span', ' | ', array('span' => array('class' => 'current')), '10', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:14')), '14', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:15')), '15', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging'] = array('Client' => array('page' => 6, 'current' => 15, 'count' => 623, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 42, 'options' => array('page' => 6), 'paramType' => 'named')); $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1)); $expected = array(array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', ' | ', array('span' => array('class' => 'current')), '6', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span', '...', array('span' => array()), array('a' => array('href' => '/index/page:42')), '42', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging'] = array('Client' => array('page' => 37, 'current' => 15, 'count' => 623, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 42, 'options' => array('page' => 37), 'paramType' => 'named')); $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1)); $expected = array(array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span', '...', array('span' => array()), array('a' => array('href' => '/index/page:33')), '33', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:34')), '34', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:35')), '35', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:36')), '36', '/a', '/span', ' | ', array('span' => array('class' => 'current')), '37', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:38')), '38', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:39')), '39', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:40')), '40', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:41')), '41', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:42')), '42', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging'] = array('Client' => array('page' => 1, 'current' => 10, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 3, 'options' => array('page' => 1), 'paramType' => 'named')); $options = array('modulus' => 10); $result = $this->Paginator->numbers($options); $expected = array(array('span' => array('class' => 'current')), '1', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span'); $this->assertTags($result, $expected); $result = $this->Paginator->numbers(array('modulus' => 3, 'currentTag' => 'span', 'tag' => 'li')); $expected = array(array('li' => array('class' => 'current')), array('span' => array()), '1', '/span', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/li', ' | ', array('li' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/li'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging'] = array('Client' => array('page' => 2, 'current' => 10, 'count' => 31, 'prevPage' => true, 'nextPage' => true, 'pageCount' => 4, 'options' => array('page' => 1, 'order' => array('Client.name' => 'DESC')), 'paramType' => 'named')); $result = $this->Paginator->numbers(array('class' => 'page-link')); $expected = array(array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/sort:Client.name/direction:DESC')), '1', '/a', '/span', ' | ', array('span' => array('class' => 'current page-link')), '2', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3/sort:Client.name/direction:DESC')), '3', '/a', '/span', ' | ', array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4/sort:Client.name/direction:DESC')), '4', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging'] = array('Client' => array('page' => 4895, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897, 'options' => array('page' => 4894), 'paramType' => 'named')); $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2)); $expected = array(array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', '...', array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span', ' | ', array('span' => array('class' => 'current')), '4895', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging']['Client']['page'] = 3; $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2)); $expected = array(array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', ' | ', array('span' => array('class' => 'current')), '3', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', '...', array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span'); $this->assertTags($result, $expected); $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2, 'separator' => ' - ')); $expected = array(array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', ' - ', array('span' => array('class' => 'current')), '3', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', '...', array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span'); $this->assertTags($result, $expected); $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 5, 'last' => 5, 'separator' => ' - ')); $expected = array(array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', ' - ', array('span' => array('class' => 'current')), '3', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', '...', array('span' => array()), array('a' => array('href' => '/index/page:4893')), '4893', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging']['Client']['page'] = 4893; $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - ')); $expected = array(array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', '...', array('span' => array()), array('a' => array('href' => '/index/page:4891')), '4891', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4892')), '4892', '/a', '/span', ' - ', array('span' => array('class' => 'current')), '4893', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging']['Client']['page'] = 58; $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - ')); $expected = array(array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', '...', array('span' => array()), array('a' => array('href' => '/index/page:56')), '56', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:57')), '57', '/a', '/span', ' - ', array('span' => array('class' => 'current')), '58', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:59')), '59', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:60')), '60', '/a', '/span', '...', array('span' => array()), array('a' => array('href' => '/index/page:4893')), '4893', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging']['Client']['page'] = 5; $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - ')); $expected = array(array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', ' - ', array('span' => array('class' => 'current')), '5', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', '...', array('span' => array()), array('a' => array('href' => '/index/page:4893')), '4893', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging']['Client']['page'] = 3; $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2, 'separator' => ' - ', 'ellipsis' => ' ~~~ ')); $expected = array(array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', ' - ', array('span' => array('class' => 'current')), '3', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', ' ~~~ ', array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging']['Client']['page'] = 3; $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2, 'separator' => ' - ', 'ellipsis' => '<span class="ellipsis">...</span>')); $expected = array(array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', ' - ', array('span' => array('class' => 'current')), '3', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', array('span' => array('class' => 'ellipsis')), '...', '/span', array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', ' - ', array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging'] = array('Client' => array('page' => 2, 'current' => 2, 'count' => 30, 'prevPage' => false, 'nextPage' => 3, 'pageCount' => 3, 'options' => array('page' => 1), 'paramType' => 'named')); $request = new CakeRequest(); $request->addParams(array('controller' => 'clients', 'action' => 'index', 'plugin' => null, 'page' => 2)); $request->base = ''; $request->here = '/clients/index/page:2'; $request->webroot = '/'; Router::setRequestInfo($request); $result = $this->Paginator->numbers(); $expected = array(array('span' => array()), array('a' => array('href' => '/clients')), '1', '/a', '/span', ' | ', array('span' => array('class' => 'current')), '2', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/clients/index/page:3')), '3', '/a', '/span'); $this->assertTags($result, $expected); $this->Paginator->request->params['paging'] = array('Client' => array('page' => 2, 'current' => 2, 'count' => 30, 'prevPage' => false, 'nextPage' => 3, 'pageCount' => 3, 'options' => array('page' => 1), 'paramType' => 'querystring')); $request = new CakeRequest(); $request->addParams(array('controller' => 'clients', 'action' => 'index', 'plugin' => null)); $request->base = ''; $request->here = '/clients?page=2'; $request->webroot = '/'; Router::setRequestInfo($request); $result = $this->Paginator->numbers(); $expected = array(array('span' => array()), array('a' => array('href' => '/clients')), '1', '/a', '/span', ' | ', array('span' => array('class' => 'current')), '2', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/clients?page=3')), '3', '/a', '/span'); $this->assertTags($result, $expected); }
/** * Test that Router::url() uses the first request */ public function testUrlWithRequestAction() { $firstRequest = new CakeRequest('/posts/index'); $firstRequest->addParams(array('plugin' => null, 'controller' => 'posts', 'action' => 'index'))->addPaths(array('base' => '')); $secondRequest = new CakeRequest('/posts/index'); $secondRequest->addParams(array('requested' => 1, 'plugin' => null, 'controller' => 'comments', 'action' => 'listing'))->addPaths(array('base' => '')); Router::setRequestInfo($firstRequest); Router::setRequestInfo($secondRequest); $result = Router::url(array('base' => false)); $this->assertEquals('/comments/listing', $result, 'with second requests, the last should win.'); Router::popRequest(); $result = Router::url(array('base' => false)); $this->assertEquals('/posts', $result, 'with second requests, the last should win.'); }
/** * test action() and plugins * * @return void */ public function testActionWithPlugin() { $request = new CakeRequest('/debug_kit/posts/index', false); $request->addParams(array('plugin' => 'debug_kit', 'controller' => 'posts', 'action' => 'index')); $result = $this->auth->action($request); $this->assertEquals('/controllers/DebugKit/Posts/index', $result); }
/** * Applies Routing and additionalParameters to the request to be dispatched. * If Routes have not been loaded they will be loaded, and app/Config/routes.php will be run. * * @param CakeRequest $request CakeRequest object to mine for parameter information. * @param array $additionalParams An array of additional parameters to set to the request. * Useful when Object::requestAction() is involved * @return CakeRequest The request object with routing params set. */ public function parseParams(CakeRequest $request, $additionalParams = array()) { if (count(Router::$routes) == 0) { $namedExpressions = Router::getNamedExpressions(); extract($namedExpressions); $this->_loadRoutes(); } $params = Router::parse($request->url); $request->addParams($params); if (!empty($additionalParams)) { $request->addParams($additionalParams); } return $request; }
/** * test scope failure. * * @expectedException UnauthorizedException * @expectedExceptionCode 401 * @return void */ public function testAuthenticateFailReChallenge() { $this->auth->settings['scope'] = array('user' => 'nate'); $request = new CakeRequest('posts/index', false); $request->addParams(array('pass' => array(), 'named' => array())); $_SERVER['PHP_AUTH_DIGEST'] = <<<DIGEST Digest username="******", realm="localhost", nonce="123", uri="/dir/index.html", qop=auth, nc=1, cnonce="123", response="6629fae49393a05397450978507c4ef1", opaque="123abc" DIGEST; $this->auth->unauthenticated($request, $this->response); }
/** * Test afterlayout element rendering * * @return void */ public function testAfterLayout() { $this->Controller->viewPath = 'Posts'; $request = new CakeRequest('/posts/index'); $request->addParams(Router::parse($request->url)); $request->addPaths(array('webroot' => '/', 'base' => '/', 'here' => '/posts/index')); $this->Controller->setRequest($request); $this->Controller->layout = 'default'; $this->Controller->uses = null; $this->Controller->components = array('DebugKit.Toolbar'); $this->Controller->constructClasses(); $this->Controller->Components->trigger('startup', array($this->Controller)); $this->Controller->Components->trigger('beforeRender', array($this->Controller)); $result = $this->Controller->render(); $this->assertNotRegExp('/debug-toolbar/', (string) $result); $result = $this->firecake->sentHeaders; $this->assertTrue(is_array($result)); }
/** * test invoking controller methods. * * @return void */ public function testInvokeActionReturnValue() { $url = new CakeRequest('test/returner/'); $url->addParams(array('controller' => 'test_controller', 'action' => 'returner', 'pass' => array())); $response = $this->getMock('CakeResponse'); $Controller = new TestController($url, $response); $result = $Controller->invokeAction($url); $this->assertEquals('I am from the controller.', $result); }
/** * testAuthenticateWithBlowfish * * @return void */ public function testAuthenticateWithBlowfish() { $hash = Security::hash('password', 'blowfish'); $this->skipIf(strpos($hash, '$2a$') === false, 'Skipping blowfish tests as hashing is not working'); $request = new CakeRequest('posts/index', false); $request->addParams(array('pass' => array(), 'named' => array())); $_SERVER['PHP_AUTH_USER'] = '******'; $_SERVER['PHP_AUTH_PW'] = 'password'; $User = ClassRegistry::init('User'); $User->updateAll(array('password' => $User->getDataSource()->value($hash)), array('User.user' => 'mariano')); $this->auth->settings['passwordHasher'] = 'Blowfish'; $result = $this->auth->authenticate($request, $this->response); $expected = array('id' => 1, 'user' => 'mariano', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'); $this->assertEquals($expected, $result); }
/** * Test is('requested') and isRequested() * * @return void */ public function testIsRequested() { $request = new CakeRequest('/posts/index'); $request->addParams(array('controller' => 'posts', 'action' => 'index', 'plugin' => null, 'requested' => 1)); $this->assertTrue($request->is('requested')); $this->assertTrue($request->isRequested()); $request = new CakeRequest('/posts/index'); $request->addParams(array('controller' => 'posts', 'action' => 'index', 'plugin' => null)); $this->assertFalse($request->is('requested')); $this->assertFalse($request->isRequested()); }
/** * test injection of javascript * * @return void **/ public function testJavascriptInjection() { $this->Controller->viewPath = 'posts'; $this->Controller->uses = null; $request = new CakeRequest('/posts/index'); $request->addParams(Router::parse($request->url)); $request->addPaths(array('webroot' => '/', 'base' => '/', 'here' => '/posts/index')); $this->Controller->setRequest($request); $this->Controller->helpers = array('Js', 'Html', 'Session'); $this->Controller->components = array('DebugKit.Toolbar'); $this->Controller->layout = 'default'; $this->Controller->constructClasses(); $this->Controller->Components->trigger('startup', array($this->Controller)); $this->Controller->Components->trigger('beforeRender', array($this->Controller)); $result = $this->Controller->render(); $result = str_replace(array("\n", "\r"), '', $result); $this->assertPattern('#<script\\s*type="text/javascript"\\s*src="/debug_kit/js/js_debug_toolbar.js(:?\\?\\d*?)?"\\s*>\\s?</script>#', $result); }
/** * loading test controller * * @param array $settings * @return Controller */ protected function _loadController($settings = array()) { $request = new CakeRequest($this->url); $request->addParams(Router::parse($this->url)); $this->Controller = new Controller($request); $this->Controller->uses = null; $this->Controller->components = array('Toolbar' => $settings + array('className' => 'TestToolbar')); $this->Controller->constructClasses(); $this->Controller->Components->trigger('initialize', array($this->Controller)); return $this->Controller; }
/** * Test that requests are still blackholed when controller has incorrect * visibility keyword in the blackhole callback * * @expectedException BadRequestException * @return void */ public function testBlackholeWithBrokenCallback() { $request = new CakeRequest('posts/index', false); $request->addParams(array('controller' => 'posts', 'action' => 'index')); $this->Controller = new BrokenCallbackController($request); $this->Controller->Components->init($this->Controller); $this->Controller->Security = $this->Controller->TestSecurity; $this->Controller->Security->blackHoleCallback = '_fail'; $this->Controller->Security->startup($this->Controller); $this->Controller->Security->blackHole($this->Controller, 'csrf'); }