⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 auth.test.php

📁 Cake Framwork , Excellent
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/* SVN FILE: $Id: auth.test.php 7118 2008-06-04 20:49:29Z gwoo $ *//** * Short description for file. * * Long description for file * * PHP versions 4 and 5 * * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite> * Copyright 2005-2008, Cake Software Foundation, Inc. *								1785 E. Sahara Avenue, Suite 490-204 *								Las Vegas, Nevada 89104 * *  Licensed under The Open Group Test Suite License *  Redistributions of files must retain the above copyright notice. * * @filesource * @copyright		Copyright 2005-2008, Cake Software Foundation, Inc. * @link				https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests * @package			cake * @subpackage		cake.cake.tests.cases.libs.controller.components * @since			CakePHP(tm) v 1.2.0.5347 * @version			$Revision: 7118 $ * @modifiedby		$LastChangedBy: gwoo $ * @lastmodified	$Date: 2008-06-04 13:49:29 -0700 (Wed, 04 Jun 2008) $ * @license			http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */App::import(array('controller' . DS . 'components' . DS .'auth', 'controller' . DS . 'components' . DS .'acl'));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 {/** * testStop property *  * @var bool false * @access public */	var $testStop = false;/** * stop method *  * @access public * @return void */	function _stop() {		$this->testStop = true;	}}/*** Short description for class.** @package		cake.tests* @subpackage	cake.tests.cases.libs.controller.components*/class AuthUser extends CakeTestModel {/** * name property *  * @var string 'AuthUser' * @access public */	var $name = 'AuthUser';/** * useDbConfig property *  * @var string 'test_suite' * @access public */	var $useDbConfig = 'test_suite';/** * parentNode method *  * @access public * @return void */	function parentNode() {		return true;	}/** * bindNode method *  * @param mixed $object  * @access public * @return void */	function bindNode($object) {		return 'Roles/Admin';	}/** * isAuthorized method *  * @param mixed $user  * @param mixed $controller  * @param mixed $action  * @access public * @return void */	function isAuthorized($user, $controller = null, $action = null) {		if (!empty($user)) {			return true;		}		return false;	}}/*** Short description for class.** @package		cake.tests* @subpackage	cake.tests.cases.libs.controller.components*/class AuthTestController extends Controller {/** * name property *  * @var string 'AuthTest' * @access public */	var $name = 'AuthTest';/** * uses property *  * @var array * @access public */	var $uses = array('AuthUser');/** * components property *  * @var array * @access public */	var $components = array('Auth', 'Acl');/** * testUrl property *  * @var mixed null * @access public */	var $testUrl = null;/** * construct method *  * @access private * @return void */	function __construct() {		$this->params = Router::parse('/auth_test');		Router::setRequestInfo(array($this->params, array('base' => null, 'here' => '/auth_test', 'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array())));		parent::__construct();	}/** * beforeFilter method *  * @access public * @return void */	function beforeFilter() {	}/** * login method *  * @access public * @return void */	function login() {	}/** * admin_login method *  * @access public * @return void */	function admin_login() {	}/** * logout method *  * @access public * @return void */	function logout() {		//$this->redirect($this->Auth->logout());	}/** * add method *  * @access public * @return void */	function add() {		echo "add";	}/** * redirect method *  * @param mixed $url  * @param mixed $status  * @param mixed $exit  * @access public * @return void */	function redirect($url, $status, $exit) {		$this->testUrl = Router::url($url);		return false;	}/** * isAuthorized method *  * @access public * @return void */	function isAuthorized() {		if(isset($this->params['testControllerAuth'])) {			return false;		}		return true;	}}/** * AjaxAuthController class *  * @package              cake * @subpackage           cake.tests.cases.libs.controller.components */class AjaxAuthController extends Controller {/** * name property *  * @var string 'AjaxAuth' * @access public */	var $name = 'AjaxAuth';/** * components property *  * @var array * @access public */	var $components = array('TestAuth');/** * uses property *  * @var array * @access public */	var $uses = array();/** * testUrl property *  * @var mixed null * @access public */	var $testUrl = null;/** * beforeFilter method *  * @access public * @return void */	function beforeFilter() {		$this->TestAuth->ajaxLogin = 'test_element';		$this->TestAuth->userModel = 'AuthUser';	}/** * add method *  * @access public * @return void */	function add() {		if ($this->TestAuth->testStop !== true) {			echo 'Added Record';		}	}/** * redirect method *  * @param mixed $url  * @param mixed $status  * @param mixed $exit  * @access public * @return void */	function redirect($url, $status, $exit) {		$this->testUrl = Router::url($url);		return false;	}}/*** Short description for class.** @package		cake.tests* @subpackage	cake.tests.cases.libs.controller.components*/class AuthTest extends CakeTestCase {/** * name property *  * @var string 'Auth' * @access public */	var $name = 'Auth';/** * fixtures property *  * @var array * @access public */	var $fixtures = array('core.auth_user', 'core.aro', 'core.aco', 'core.aros_aco', 'core.aco_action');/** * initialized property *  * @var bool false * @access public */	var $initialized = false;/** * startTest method *  * @access public * @return void */	function startTest() {		if (!$this->initialized) {			Configure::write('Acl.database', 'test_suite');			Configure::write('Acl.classname', 'DbAcl');			if (isset($this->fixtures) && (!is_array($this->fixtures) || empty($this->fixtures))) {				unset($this->fixtures);			}			// Create records			if (isset($this->_fixtures) && isset($this->db)) {				foreach ($this->_fixtures as $fixture) {					$fixture->insert($this->db);				}			}		}		$this->Controller =& new AuthTestController();		$this->Controller->Component->init($this->Controller);		ClassRegistry::addObject('view', new View($this->Controller));		$this->Controller->Session->del('Auth');		$this->Controller->Session->del('Message.auth');		$this->initialized = true;	}/** * testNoAuth method *  * @access public * @return void */	function testNoAuth() {		$this->assertFalse($this->Controller->Auth->isAuthorized());	}/** * testLogin method *  * @access public * @return void */	function testLogin() {		$this->AuthUser =& new AuthUser();		$user['id'] = 1;		$user['username'] = 'mariano';		$user['password'] = Security::hash(Configure::read('Security.salt') . 'cake');		$this->AuthUser->save($user, false);		$authUser = $this->AuthUser->find();		$this->Controller->data['AuthUser']['username'] = $authUser['AuthUser']['username'];		$this->Controller->data['AuthUser']['password'] = 'cake';		$this->Controller->params['url']['url'] = 'auth_test/login';		$this->Controller->Auth->initialize($this->Controller);		$this->Controller->Auth->loginAction = 'auth_test/login';		$this->Controller->Auth->userModel = 'AuthUser';		$this->Controller->Auth->startup($this->Controller);		$user = $this->Controller->Auth->user();		$expected = array('AuthUser' => array(			'id' => 1, 'username' => 'mariano', 'created' => '2007-03-17 01:16:23', 'updated' => date('Y-m-d H:i:s')		));		$this->assertEqual($user, $expected);		$this->Controller->Session->del('Auth');		$this->Controller->data['AuthUser']['username'] = 'blah';		$this->Controller->data['AuthUser']['password'] = '';		$this->Controller->Auth->startup($this->Controller);		$user = $this->Controller->Auth->user();		$this->assertFalse($user);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -