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

📄 acl.test.php

📁 Cake Framwork , Excellent
💻 PHP
📖 第 1 页 / 共 2 页
字号:
	function testDbAclCheck()  {		$this->assertTrue($this->Acl->check('Samir', 'print', 'read'));		$this->assertTrue($this->Acl->check('Lumbergh', 'current', 'read'));		$this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));		$this->assertFalse($this->Acl->check('Milton', 'current', 'update'));		$this->expectError("DbAcl::check() - Failed ARO/ACO node lookup in permissions check.  Node references:\nAro: WRONG\nAco: tpsReports");		$this->assertFalse($this->Acl->check('WRONG', 'tpsReports', 'read'));		$this->expectError("ACO permissions key foobar does not exist in DbAcl::check()");		$this->assertFalse($this->Acl->check('Lumbergh', 'smash', 'foobar'));		//The next assertion should generate an error but only returns false.		//$this->expectError("DbAcl::check() - Failed ARO/ACO node lookup in permissions check.  Node references:\nAro: users\nAco: NonExistant");		$this->assertFalse($this->Acl->check('users', 'NonExistant', 'read'));		$this->assertFalse($this->Acl->check(null, 'printers', 'create'));		$this->assertFalse($this->Acl->check('managers', null, 'read'));		$this->assertTrue($this->Acl->check('Bobs', 'ROOT/tpsReports/view/current', 'read'));		$this->assertFalse($this->Acl->check('Samir', 'ROOT/tpsReports/update', 'read'));		$this->assertFalse($this->Acl->check('root/users/Milton', 'smash', 'delete'));	}/** * testDbAclCascadingDeny function * * Setup the acl permissions such that Bobs inherits from admin. * deny Admin delete access to a specific resource, check the permisssions are inherited. * * @access public * @return void */	function testDbAclCascadingDeny() {		$this->Acl->inherit('Bobs', 'ROOT', '*');		$this->assertTrue($this->Acl->check('admin', 'tpsReports', 'delete'));		$this->assertTrue($this->Acl->check('Bobs', 'tpsReports', 'delete'));		$this->Acl->deny('admin', 'tpsReports', 'delete');		$this->assertFalse($this->Acl->check('admin', 'tpsReports', 'delete'));		$this->assertFalse($this->Acl->check('Bobs', 'tpsReports', 'delete'));	}/** * testDbAclDeny method *  * @access public * @return void */	function testDbAclDeny() {		$this->assertTrue($this->Acl->check('Micheal', 'smash', 'delete'));		$this->Acl->deny('Micheal', 'smash', 'delete');		$this->assertFalse($this->Acl->check('Micheal', 'smash', 'delete'));		$this->assertTrue($this->Acl->check('Micheal', 'smash', 'read'));		$this->assertTrue($this->Acl->check('Micheal', 'smash', 'create'));		$this->assertTrue($this->Acl->check('Micheal', 'smash', 'update'));		$this->assertFalse($this->Acl->check('Micheal', 'smash', '*'));		$this->assertTrue($this->Acl->check('Samir', 'refill', '*'));		$this->Acl->deny('Samir', 'refill', '*');		$this->assertFalse($this->Acl->check('Samir', 'refill', 'create'));		$this->assertFalse($this->Acl->check('Samir', 'refill', 'update'));		$this->assertFalse($this->Acl->check('Samir', 'refill', 'read'));		$this->assertFalse($this->Acl->check('Samir', 'refill', 'delete'));		$result = $this->Acl->Aro->Permission->find('all', array('conditions' => array('AroTwoTest.alias' => 'Samir')));		$expected = '-1';		$this->assertEqual($result[0]['PermissionTwoTest']['_delete'], $expected);		$this->expectError('DbAcl::allow() - Invalid node');		$this->assertFalse($this->Acl->deny('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));	}/** * testAclNodeLookup method *  * @access public * @return void */	function testAclNodeLookup() {		$result = $this->Acl->Aro->node('root/users/Samir');		$expected = array(			array('AroTwoTest' => array('id' => '7', 'parent_id' => '4', 'model' => 'User', 'foreign_key' => 3, 'alias' => 'Samir')),			array('AroTwoTest' => array('id' => '4', 'parent_id' => '1', 'model' => 'Group', 'foreign_key' => 3, 'alias' => 'users')),			array('AroTwoTest' => array('id' => '1', 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'root'))		);		$this->assertEqual($result, $expected);		$result = $this->Acl->Aco->node('ROOT/tpsReports/view/current');		$expected = array(			array('AcoTwoTest' => array('id' => '4', 'parent_id' => '3', 'model' => null, 'foreign_key' => null, 'alias' => 'current')),			array('AcoTwoTest' => array('id' => '3', 'parent_id' => '2', 'model' => null, 'foreign_key' => null, 'alias' => 'view')),			array('AcoTwoTest' => array('id' => '2', 'parent_id' => '1', 'model' => null, 'foreign_key' => null, 'alias' => 'tpsReports')),			array('AcoTwoTest' => array('id' => '1', 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT')),		);		$this->assertEqual($result, $expected);	}/** * testDbInherit method *  * @access public * @return void */	function testDbInherit() {		//parent doesn't have access inherit should still deny		$this->assertFalse($this->Acl->check('Milton', 'smash', 'delete'));		$this->Acl->inherit('Milton', 'smash', 'delete');		$this->assertFalse($this->Acl->check('Milton', 'smash', 'delete'));		//inherit parent		$this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));		$this->Acl->inherit('Milton', 'smash', 'read');		$this->assertTrue($this->Acl->check('Milton', 'smash', 'read'));	}/** * testDbGrant method *  * @access public * @return void */	function testDbGrant() {		$this->assertFalse($this->Acl->check('Samir', 'tpsReports', 'create'));		$this->Acl->grant('Samir', 'tpsReports', 'create');		$this->assertTrue($this->Acl->check('Samir', 'tpsReports', 'create'));		$this->assertFalse($this->Acl->check('Micheal', 'view', 'read'));		$this->Acl->grant('Micheal', 'view', array('read', 'create', 'update'));		$this->assertTrue($this->Acl->check('Micheal', 'view', 'read'));		$this->assertTrue($this->Acl->check('Micheal', 'view', 'create'));		$this->assertTrue($this->Acl->check('Micheal', 'view', 'update'));		$this->assertFalse($this->Acl->check('Micheal', 'view', 'delete'));		$this->expectError('DbAcl::allow() - Invalid node');		$this->assertFalse($this->Acl->grant('Peter', 'ROOT/tpsReports/DoesNotExist', 'create'));	}/** * testDbRevoke method *  * @access public * @return void */	function testDbRevoke() {		$this->assertTrue($this->Acl->check('Bobs', 'tpsReports', 'read'));		$this->Acl->revoke('Bobs', 'tpsReports', 'read');		$this->assertFalse($this->Acl->check('Bobs', 'tpsReports', 'read'));		$this->assertTrue($this->Acl->check('users', 'printers', 'read'));		$this->Acl->revoke('users', 'printers', 'read');		$this->assertFalse($this->Acl->check('users', 'printers', 'read'));		$this->assertFalse($this->Acl->check('Samir', 'printers', 'read'));		$this->assertFalse($this->Acl->check('Peter', 'printers', 'read'));		$this->expectError('DbAcl::allow() - Invalid node');		$this->assertFalse($this->Acl->deny('Bobs', 'ROOT/printers/DoesNotExist', 'create'));	}	function testStartup() {		$controller = new Controller();		$this->assertTrue($this->Acl->startup($controller));	}/*	The following tests and AclComponent methods are not fully implemented yet	function testDbSetAro() {		//This method is not implemented in either IniAcl or DbAcl		//$result = $this->Acl->setAro('Samir');		//$this->assertEqual($result, $expected);	}	function testDbSetAco() {		//This method is not implemented in either IniAcl or DbAcl		//$result = $this->Acl->getAco('printers');		//$this->assertEqual($result, $expected);	}	function testDbGetAro() {		//This method is not implemented in either IniAcl or DbAcl		//$result = $this->Acl->getAro('Samir');		//$this->assertEqual($result, $expected);	}	function testDbGetAco() {		//This method is not implemented in either IniAcl or DbAcl		//$result = $this->Acl->getAco('tpsReports');		//$this->assertEqual($result, $expected);	}*/	function testIniReadConfigFile() {		Configure::write('Acl.classname', 'IniAclTest');		unset($this->Acl);		$this->Acl = new AclComponent();		$iniFile = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';		$result = $this->Acl->_Instance->readConfigFile($iniFile);		$expected = array(			'admin' => array(				'groups' => 'administrators',				'allow' => '',				'deny' => 'ads',			),			'paul' => array(				'groups' => 'users',				'allow' =>'',				'deny' => '',			),			'jenny' => array(				'groups' => 'users',				'allow' => 'ads',				'deny' => 'images, files',			),			'nobody' => array(				'groups' => 'anonymous',				'allow' => '',				'deny' => '',			),			'administrators' => array(				'deny' => '',				'allow' => 'posts, comments, images, files, stats, ads',			),			'users' => array(				'allow' => 'posts, comments, images, files',				'deny' => 'stats, ads',			),			'anonymous' => array(				'allow' => '',				'deny' => 'posts, comments, images, files, stats, ads',			),		);		$this->assertEqual($result, $expected);	}	function testIniCheck() {		Configure::write('Acl.classname', 'IniAclTest');		unset($this->Acl);		$iniFile = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';		$this->Acl = new AclComponent();		$this->Acl->_Instance->config= $this->Acl->_Instance->readConfigFile($iniFile);		$this->assertFalse($this->Acl->check('admin', 'ads'));		$this->assertTrue($this->Acl->check('admin', 'posts'));		$this->assertTrue($this->Acl->check('jenny', 'posts'));		$this->assertTrue($this->Acl->check('jenny', 'ads'));		$this->assertTrue($this->Acl->check('paul', 'posts'));		$this->assertFalse($this->Acl->check('paul', 'ads'));		$this->assertFalse($this->Acl->check('nobody', 'comments'));	}	function tearDown() {		unset($this->Acl);	}/** * debug function - to help editing/creating test cases for the ACL component * * To check the overal ACL status at any time call $this->__debug(); * Generates a list of the current aro and aco structures and a grid dump of the permissions that are defined * Only designed to work with the db based ACL * * @param bool $treesToo * @access private * @return void */	function __debug ($printTreesToo = false) {		$this->Acl->Aro->displayField = 'alias';		$this->Acl->Aco->displayField = 'alias';		$aros = $this->Acl->Aro->find('list', array('order' => 'lft'));		$acos = $this->Acl->Aco->find('list', array('order' => 'lft'));		$rights = array('*', 'create', 'read', 'update', 'delete');		$permissions['Aros v Acos >'] = $acos;		foreach ($aros as $aro) {			$row = array();			foreach ($acos as $aco) {				$perms = '';				foreach ($rights as $right) {					if ($this->Acl->check($aro, $aco, $right)) {						if ($right == '*') {							$perms .= '****';							break;						}						$perms .= $right[0];					} elseif ($right != '*') {						$perms .= ' ';					}				}				$row[] = $perms;			}			$permissions[$aro] = $row;		}		foreach ($permissions as $key => $values) {			array_unshift($values, $key);			$values = array_map(array(&$this, '__pad'), $values);			$permissions[$key] = implode (' ', $values);		}		$permisssions = array_map(array(&$this, '__pad'), $permissions);		array_unshift($permissions, 'Current Permissions :');		if ($printTreesToo) {			debug (array('aros' => $this->Acl->Aro->generateTreeList(), 'acos' => $this->Acl->Aco->generateTreeList()));		}		debug (implode("\r\n", $permissions));	}/** * pad function * Used by debug to format strings used in the data dump * * @param string $string * @param int $len * @access private * @return void */	function __pad($string = '', $len = 14) {		return str_pad($string, $len);	}}?>

⌨️ 快捷键说明

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