adding Object::stop(), updating auth and auth.test to use

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6901 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-05-16 15:23:00 +00:00
parent 3d251e4145
commit 8a236492a0
3 changed files with 38 additions and 30 deletions

View file

@ -242,7 +242,7 @@ class AuthComponent extends Object {
)); ));
} }
if (Configure::read() > 0) { if (Configure::read() > 0) {
uses('debugger'); App::import('Debugger');
Debugger::checkSessionKey(); Debugger::checkSessionKey();
} }
} }
@ -318,6 +318,7 @@ class AuthComponent extends Object {
} elseif (!empty($this->ajaxLogin)) { } elseif (!empty($this->ajaxLogin)) {
$controller->viewPath = 'elements'; $controller->viewPath = 'elements';
echo $controller->render($this->ajaxLogin, 'ajax'); echo $controller->render($this->ajaxLogin, 'ajax');
$this->stop();
return false; return false;
} }
} }

View file

@ -127,6 +127,16 @@ class Object {
break; 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. * API for logging events.
* *

View file

@ -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')); App::import(array('controller'.DS.'components'.DS.'acl', 'model'.DS.'db_acl'));
Configure::write('Security.salt', 'JfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi'); 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. * Short description for class.
* *
@ -106,17 +121,19 @@ class AuthTestController extends Controller {
class AjaxAuthController extends Controller { class AjaxAuthController extends Controller {
var $name = 'AjaxAuth'; var $name = 'AjaxAuth';
var $components = array('Auth'); var $components = array('TestAuth');
var $uses = array(); var $uses = array();
var $testUrl = null; var $testUrl = null;
function beforeFilter() { function beforeFilter() {
$this->Auth->ajaxLogin = 'test_element'; $this->TestAuth->ajaxLogin = 'test_element';
$this->Auth->userModel = 'AuthUser'; $this->TestAuth->userModel = 'AuthUser';
} }
function add() { function add() {
if ($this->TestAuth->testStop !== true) {
echo 'Added Record'; echo 'Added Record';
} }
}
function redirect($url, $status, $exit) { function redirect($url, $status, $exit) {
$this->testUrl = Router::url($url); $this->testUrl = Router::url($url);
return false; return false;
@ -490,25 +507,6 @@ class AuthTest extends CakeTestCase {
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)); Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
$_SERVER['HTTP_X_REQUESTED_WITH'] = "XMLHttpRequest"; $_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')) { if (!class_exists('dispatcher')) {
require CAKE . 'dispatcher.php'; require CAKE . 'dispatcher.php';
} }
@ -520,7 +518,6 @@ class AuthTest extends CakeTestCase {
$result = ob_get_clean(); $result = ob_get_clean();
$this->assertPattern('/test element/', $result); $this->assertPattern('/test element/', $result);
$this->assertNoPattern('/Added Record/', $result); $this->assertNoPattern('/Added Record/', $result);
unset($_SERVER['HTTP_X_REQUESTED_WITH']); unset($_SERVER['HTTP_X_REQUESTED_WITH']);
} }