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
|
|
|
*
|
2017-06-10 22:15:34 +00:00
|
|
|
* CakePHP(tm) Tests <https://book.cakephp.org/2.0/en/development/testing.html>
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://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
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://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
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2013-05-30 22:11:14 +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();
|
2014-03-01 19:24:32 +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() {
|
2014-03-01 19:24:32 +00:00
|
|
|
$Adapter = $this->getMock('AclInterface');
|
|
|
|
$Adapter->expects($this->once())->method('initialize')->with($this->Acl);
|
2010-04-24 03:03:51 +00:00
|
|
|
|
2014-03-01 19:24:32 +00:00
|
|
|
$this->assertNull($this->Acl->adapter($Adapter));
|
|
|
|
$this->assertEquals($this->Acl->adapter(), $Adapter, 'Returned object is different %s');
|
2010-04-24 03:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-11 19:10:56 +00:00
|
|
|
* test that adapter() whines when the class does not implement AclInterface
|
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 testAdapterException() {
|
2010-04-24 03:03:51 +00:00
|
|
|
$thing = new StdClass();
|
|
|
|
$this->Acl->adapter($thing);
|
|
|
|
}
|
|
|
|
|
2010-04-24 03:52:36 +00:00
|
|
|
}
|