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