Refactoring Auth test, adding coverage, and enabling custom Ajax layouts (as specified by RequestHandler), fixes #5446

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7637 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-09-20 20:18:16 +00:00
parent 9482105abe
commit fc5b128d68
2 changed files with 32 additions and 7 deletions

View file

@ -286,8 +286,12 @@ class AuthComponent extends Object {
}
$url = Router::normalize($url);
$loginAction = Router::normalize($this->loginAction);
$isAllowed = (
$this->allowedActions == array('*') ||
in_array($controller->action, $this->allowedActions)
);
if ($loginAction != $url && ($this->allowedActions == array('*') || in_array($controller->action, $this->allowedActions))) {
if ($loginAction != $url && $isAllowed) {
return false;
}
@ -298,10 +302,12 @@ class AuthComponent extends Object {
}
return false;
}
$username = $controller->data[$this->userModel][$this->fields['username']];
$password = $controller->data[$this->userModel][$this->fields['password']];
$data = array(
$this->userModel . '.' . $this->fields['username'] => $controller->data[$this->userModel][$this->fields['username']],
$this->userModel . '.' . $this->fields['password'] => $controller->data[$this->userModel][$this->fields['password']]
$this->userModel . '.' . $this->fields['username'] => $username,
$this->userModel . '.' . $this->fields['password'] => $password
);
if ($this->login($data)) {
@ -323,7 +329,7 @@ class AuthComponent extends Object {
return false;
} elseif (!empty($this->ajaxLogin)) {
$controller->viewPath = 'elements';
echo $controller->render($this->ajaxLogin, 'ajax');
echo $controller->render($this->ajaxLogin, $this->RequestHandler->ajaxLayout);
$this->_stop();
return false;
} else {

View file

@ -45,6 +45,13 @@ class TestAuthComponent extends AuthComponent {
* @access public
*/
var $testStop = false;
/**
* Sets default login state
*
* @var bool true
* @access protected
*/
var $_loggedIn = true;
/**
* stop method
*
@ -271,7 +278,7 @@ class AuthTestController extends Controller {
* @access public
* @return void
*/
function redirect($url, $status, $exit) {
function redirect($url, $status = null, $exit = true) {
$this->testUrl = Router::url($url);
return false;
}
@ -332,6 +339,7 @@ class AjaxAuthController extends Controller {
function beforeFilter() {
$this->TestAuth->ajaxLogin = 'test_element';
$this->TestAuth->userModel = 'AuthUser';
$this->TestAuth->RequestHandler->ajaxLayout = 'ajax2';
}
/**
* add method
@ -882,8 +890,7 @@ class AuthTest extends CakeTestCase {
$Dispatcher =& new Dispatcher();
$Dispatcher->dispatch('/ajax_auth/add', array('return' => 1));
$result = ob_get_clean();
$this->assertPattern('/test element/', $result);
$this->assertNoPattern('/Added Record/', $result);
$this->assertEqual("Ajax!\nthis is the test element", $result);
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
}
/**
@ -922,6 +929,18 @@ class AuthTest extends CakeTestCase {
Configure::write('Routing.admin', $admin);
}
/**
* Tests that shutdown destroys the redirect session var
*
* @access public
* @return void
*/
function testShutDown() {
$this->Controller->Session->write('Auth.redirect', 'foo');
$this->Controller->Auth->_loggedIn = true;
$this->Controller->Auth->shutdown($this->Controller);
$this->assertFalse($this->Controller->Session->read('Auth.redirect'));
}
/**
* tearDown method
*