統計
| ブランチ: | リビジョン:

pictcode / lib / Cake / Test / Case / View / HelperCollectionTest.php @ 635eef61

履歴 | 表示 | アノテート | ダウンロード (5.137 KB)

1 635eef61 spyder1211
<?php
2
/**
3
 * HelperCollectionTest file
4
 *
5
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
6
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
7
 *
8
 * Licensed under The MIT License
9
 * For full copyright and license information, please see the LICENSE.txt
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
13
 * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
14
 * @package       Cake.Test.Case.View
15
 * @since         CakePHP(tm) v 2.0
16
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
17
 */
18
19
App::uses('HelperCollection', 'View');
20
App::uses('HtmlHelper', 'View/Helper');
21
App::uses('View', 'View');
22
23
/**
24
 * Extended HtmlHelper
25
 */
26
class HtmlAliasHelper extends HtmlHelper {
27
}
28
29
/**
30
 * Class HelperCollectionTest
31
 *
32
 * @package       Cake.Test.Case.View
33
 */
34
class HelperCollectionTest extends CakeTestCase {
35
36
/**
37
 * setUp
38
 *
39
 * @return void
40
 */
41
        public function setUp() {
42
                parent::setUp();
43
                $this->View = $this->getMock('View', array(), array(null));
44
                $this->Helpers = new HelperCollection($this->View);
45
        }
46
47
/**
48
 * tearDown
49
 *
50
 * @return void
51
 */
52
        public function tearDown() {
53
                CakePlugin::unload();
54
                unset($this->Helpers, $this->View);
55
                parent::tearDown();
56
        }
57
58
/**
59
 * test triggering callbacks on loaded helpers
60
 *
61
 * @return void
62
 */
63
        public function testLoad() {
64
                $result = $this->Helpers->load('Html');
65
                $this->assertInstanceOf('HtmlHelper', $result);
66
                $this->assertInstanceOf('HtmlHelper', $this->Helpers->Html);
67
68
                $result = $this->Helpers->loaded();
69
                $this->assertEquals(array('Html'), $result, 'loaded() results are wrong.');
70
71
                $this->assertTrue($this->Helpers->enabled('Html'));
72
        }
73
74
/**
75
 * test lazy loading of helpers
76
 *
77
 * @return void
78
 */
79
        public function testLazyLoad() {
80
                $result = $this->Helpers->Html;
81
                $this->assertInstanceOf('HtmlHelper', $result);
82
83
                $result = $this->Helpers->Form;
84
                $this->assertInstanceOf('FormHelper', $result);
85
86
                App::build(array('Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)));
87
                $this->View->plugin = 'TestPlugin';
88
                CakePlugin::load(array('TestPlugin'));
89
                $result = $this->Helpers->OtherHelper;
90
                $this->assertInstanceOf('OtherHelperHelper', $result);
91
        }
92
93
/**
94
 * test lazy loading of helpers
95
 *
96
 * @expectedException MissingHelperException
97
 * @return void
98
 */
99
        public function testLazyLoadException() {
100
                $this->Helpers->NotAHelper;
101
        }
102
103
/**
104
 * Tests loading as an alias
105
 *
106
 * @return void
107
 */
108
        public function testLoadWithAlias() {
109
                $result = $this->Helpers->load('Html', array('className' => 'HtmlAlias'));
110
                $this->assertInstanceOf('HtmlAliasHelper', $result);
111
                $this->assertInstanceOf('HtmlAliasHelper', $this->Helpers->Html);
112
113
                $result = $this->Helpers->loaded();
114
                $this->assertEquals(array('Html'), $result, 'loaded() results are wrong.');
115
116
                $this->assertTrue($this->Helpers->enabled('Html'));
117
118
                $result = $this->Helpers->load('Html');
119
                $this->assertInstanceOf('HtmlAliasHelper', $result);
120
121
                App::build(array('Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)));
122
                CakePlugin::load(array('TestPlugin'));
123
                $result = $this->Helpers->load('SomeOther', array('className' => 'TestPlugin.OtherHelper'));
124
                $this->assertInstanceOf('OtherHelperHelper', $result);
125
                $this->assertInstanceOf('OtherHelperHelper', $this->Helpers->SomeOther);
126
127
                $result = $this->Helpers->loaded();
128
                $this->assertEquals(array('Html', 'SomeOther'), $result, 'loaded() results are wrong.');
129
                App::build();
130
        }
131
132
/**
133
 * test that the enabled setting disables the helper.
134
 *
135
 * @return void
136
 */
137
        public function testLoadWithEnabledFalse() {
138
                $result = $this->Helpers->load('Html', array('enabled' => false));
139
                $this->assertInstanceOf('HtmlHelper', $result);
140
                $this->assertInstanceOf('HtmlHelper', $this->Helpers->Html);
141
142
                $this->assertFalse($this->Helpers->enabled('Html'), 'Html should be disabled');
143
        }
144
145
/**
146
 * test missinghelper exception
147
 *
148
 * @expectedException MissingHelperException
149
 * @return void
150
 */
151
        public function testLoadMissingHelper() {
152
                $this->Helpers->load('ThisHelperShouldAlwaysBeMissing');
153
        }
154
155
/**
156
 * test loading a plugin helper.
157
 *
158
 * @return void
159
 */
160
        public function testLoadPluginHelper() {
161
                App::build(array(
162
                        'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
163
                ));
164
                CakePlugin::load(array('TestPlugin'));
165
                $result = $this->Helpers->load('TestPlugin.OtherHelper');
166
                $this->assertInstanceOf('OtherHelperHelper', $result, 'Helper class is wrong.');
167
                $this->assertInstanceOf('OtherHelperHelper', $this->Helpers->OtherHelper, 'Class is wrong');
168
169
                App::build();
170
        }
171
172
/**
173
 * test unload()
174
 *
175
 * @return void
176
 */
177
        public function testUnload() {
178
                $this->Helpers->load('Form');
179
                $this->Helpers->load('Html');
180
181
                $result = $this->Helpers->loaded();
182
                $this->assertEquals(array('Form', 'Html'), $result, 'loaded helpers is wrong');
183
184
                $this->Helpers->unload('Html');
185
                $this->assertNotContains('Html', $this->Helpers->loaded());
186
                $this->assertContains('Form', $this->Helpers->loaded());
187
188
                $result = $this->Helpers->loaded();
189
                $this->assertEquals(array('Form'), $result, 'loaded helpers is wrong');
190
        }
191
192
}