2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* AclComponentTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller.Component
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5435
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-03-05 22:10:42 +00:00
|
|
|
App::uses('AclComponent', 'Controller/Component');
|
|
|
|
class_exists('AclComponent');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2011-09-14 01:25:50 +00:00
|
|
|
* Test Case for AclComponent
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller.Component
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class AclComponentTest extends CakeTestCase {
|
2012-03-12 02:20:25 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* setUp method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2010-09-26 01:36:49 +00:00
|
|
|
parent::setUp();
|
2010-06-11 00:47:35 +00:00
|
|
|
if (!class_exists('MockAclImplementation', false)) {
|
|
|
|
$this->getMock('AclInterface', array(), array(), 'MockAclImplementation');
|
|
|
|
}
|
2010-04-24 03:59:57 +00:00
|
|
|
Configure::write('Acl.classname', 'MockAclImplementation');
|
2010-07-04 22:41:08 +00:00
|
|
|
$Collection = new ComponentCollection();
|
|
|
|
$this->Acl = new AclComponent($Collection);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2010-09-26 01:36:49 +00:00
|
|
|
parent::tearDown();
|
2009-03-18 17:55:58 +00:00
|
|
|
unset($this->Acl);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-04-24 03:03:51 +00:00
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* test that constructor throws an exception when Acl.classname is a
|
|
|
|
* non-existent class
|
2010-04-24 03:03:51 +00:00
|
|
|
*
|
2010-12-12 00:01:07 +00:00
|
|
|
* @expectedException CakeException
|
2010-04-24 03:03:51 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testConstrutorException() {
|
2010-04-24 03:03:51 +00:00
|
|
|
Configure::write('Acl.classname', 'AclClassNameThatDoesNotExist');
|
2010-07-04 22:41:08 +00:00
|
|
|
$Collection = new ComponentCollection();
|
2013-01-23 12:45:50 +00:00
|
|
|
new AclComponent($Collection);
|
2010-04-24 03:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* test that adapter() allows control of the internal implementation AclComponent uses.
|
2010-04-24 03:03:51 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAdapter() {
|
2010-04-24 03:59:57 +00:00
|
|
|
$implementation = new MockAclImplementation();
|
2010-06-11 00:47:35 +00:00
|
|
|
$implementation->expects($this->once())->method('initialize')->with($this->Acl);
|
2010-04-24 03:03:51 +00:00
|
|
|
$this->assertNull($this->Acl->adapter($implementation));
|
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->Acl->adapter(), $implementation, 'Returned object is different %s');
|
2010-04-24 03:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that adapter() whines when the class is not an AclBase
|
|
|
|
*
|
2010-12-12 00:01:07 +00:00
|
|
|
* @expectedException CakeException
|
2010-04-24 03:03:51 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAdapterException() {
|
2010-04-24 03:03:51 +00:00
|
|
|
$thing = new StdClass();
|
|
|
|
$this->Acl->adapter($thing);
|
|
|
|
}
|
|
|
|
|
2010-04-24 03:52:36 +00:00
|
|
|
}
|