diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index 3d257a094..9c2a88337 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -242,7 +242,7 @@ class AuthComponent extends Object { )); } if (Configure::read() > 0) { - uses('debugger'); + App::import('Debugger'); Debugger::checkSessionKey(); } } @@ -318,6 +318,7 @@ class AuthComponent extends Object { } elseif (!empty($this->ajaxLogin)) { $controller->viewPath = 'elements'; echo $controller->render($this->ajaxLogin, 'ajax'); + $this->stop(); return false; } } diff --git a/cake/libs/object.php b/cake/libs/object.php index c52f7928a..8a5469d82 100644 --- a/cake/libs/object.php +++ b/cake/libs/object.php @@ -127,6 +127,16 @@ class Object { break; } } +/** + * Stop execution of the current script + * + * @param $status see http://php.net/exit for values + * @return void + * @access public + */ + function stop($status = 0) { + exit($status); + } /** * API for logging events. * diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index b88d91261..226ddf6d2 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -30,6 +30,21 @@ App::import(array('controller' . DS . 'components' . DS .'auth', 'controller' . App::import(array('controller'.DS.'components'.DS.'acl', 'model'.DS.'db_acl')); Configure::write('Security.salt', 'JfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi'); +/** +* Short description for class. +* +* @package cake.tests +* @subpackage cake.tests.cases.libs.controller.components +*/ +class TestAuthComponent extends AuthComponent { + + var $testStop = false; + + function stop() { + $this->testStop = true; + } +} + /** * Short description for class. * @@ -106,16 +121,18 @@ class AuthTestController extends Controller { class AjaxAuthController extends Controller { var $name = 'AjaxAuth'; - var $components = array('Auth'); + var $components = array('TestAuth'); var $uses = array(); var $testUrl = null; - + function beforeFilter() { - $this->Auth->ajaxLogin = 'test_element'; - $this->Auth->userModel = 'AuthUser'; + $this->TestAuth->ajaxLogin = 'test_element'; + $this->TestAuth->userModel = 'AuthUser'; } function add() { - echo 'Added Record'; + if ($this->TestAuth->testStop !== true) { + echo 'Added Record'; + } } function redirect($url, $status, $exit) { $this->testUrl = Router::url($url); @@ -490,37 +507,17 @@ class AuthTest extends CakeTestCase { Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)); $_SERVER['HTTP_X_REQUESTED_WITH'] = "XMLHttpRequest"; - $url = '/auth_test/add'; - $this->Controller->params = Router::parse($url); - Router::setRequestInfo(array($this->Controller->passedArgs, array('base' => null, 'here' => $url, 'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array()))); - - $this->Controller->Auth->RequestHandler->startup($this->Controller); - $this->Controller->Auth->initialize($this->Controller); - - $this->Controller->Auth->loginAction = array('controller' => 'auth_test', 'action' => 'login'); - $this->Controller->Auth->userModel = 'AuthUser'; - - $this->Controller->Auth->ajaxLogin = 'test_element'; - - ob_start(); - $this->Controller->Auth->startup($this->Controller); - $result = ob_get_clean(); - - $this->assertPattern('/test element/', $result); - $this->assertNoPattern('/add/', $result); - if (!class_exists('dispatcher')) { require CAKE . 'dispatcher.php'; - } - + } + Configure::write('test', true); ob_start(); - $Dispatcher =& new Dispatcher(); + $Dispatcher =& new Dispatcher(); $Dispatcher->dispatch('/ajax_auth/add', array('return' => 1)); $result = ob_get_clean(); - $this->assertPattern('/test element/', $result); + $this->assertPattern('/test element/', $result); $this->assertNoPattern('/Added Record/', $result); - unset($_SERVER['HTTP_X_REQUESTED_WITH']); }