1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
<?php
/**
* AclComponentTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html 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();
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);
}
/**
* 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);
}
/**
* test that adapter() allows control of the internal implementation AclComponent uses.
*
* @return void
*/
public function testAdapter() {
$implementation = new MockAclImplementation();
$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);
}
}
|