cakephp2-php8/lib/Cake/Test/Case/Controller/Component/AclComponentTest.php

91 lines
2.4 KiB
PHP
Raw Normal View History

<?php
/**
* AclComponentTest file
*
* PHP 5
*
2010-05-19 01:15:13 +00:00
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
2011-05-29 21:31:39 +00:00
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
2011-05-29 21:31:39 +00:00
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
2010-05-19 01:15:13 +00:00
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package Cake.Test.Case.Controller.Component
* @since CakePHP(tm) v 1.2.0.5435
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('AclComponent', 'Controller/Component');
class_exists('AclComponent');
/**
* Test Case for AclComponent
*
* @package Cake.Test.Case.Controller.Component
*/
class AclComponentTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
2010-06-11 00:47:35 +00:00
if (!class_exists('MockAclImplementation', false)) {
$this->getMock('AclInterface', array(), array(), 'MockAclImplementation');
}
Configure::write('Acl.classname', 'MockAclImplementation');
$Collection = new ComponentCollection();
$this->Acl = new AclComponent($Collection);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Acl);
}
/**
2012-02-23 23:29:53 +00:00
* test that constructor throws an exception when Acl.classname is a
* non-existent class
*
* @expectedException CakeException
* @return void
*/
public function testConstrutorException() {
Configure::write('Acl.classname', 'AclClassNameThatDoesNotExist');
$Collection = new ComponentCollection();
$acl = new AclComponent($Collection);
}
/**
2012-02-23 23:29:53 +00:00
* test that adapter() allows control of the internal implementation AclComponent uses.
*
* @return void
*/
public function testAdapter() {
$implementation = new MockAclImplementation();
2010-06-11 00:47:35 +00:00
$implementation->expects($this->once())->method('initialize')->with($this->Acl);
$this->assertNull($this->Acl->adapter($implementation));
$this->assertEquals($this->Acl->adapter(), $implementation, 'Returned object is different %s');
}
/**
* test that adapter() whines when the class is not an AclBase
*
* @expectedException CakeException
* @return void
*/
public function testAdapterException() {
$thing = new StdClass();
$this->Acl->adapter($thing);
}
}