| 12345 |
anikendra |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* HtmlHelperTest file
|
|
|
4 |
*
|
|
|
5 |
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
|
|
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.Helper
|
|
|
15 |
* @since CakePHP(tm) v 1.2.0.4206
|
|
|
16 |
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
App::uses('Controller', 'Controller');
|
|
|
20 |
App::uses('Helper', 'View');
|
|
|
21 |
App::uses('AppHelper', 'View/Helper');
|
|
|
22 |
App::uses('HtmlHelper', 'View/Helper');
|
|
|
23 |
App::uses('FormHelper', 'View/Helper');
|
|
|
24 |
App::uses('ClassRegistry', 'Utility');
|
|
|
25 |
App::uses('Folder', 'Utility');
|
|
|
26 |
App::uses('CakePlugin', 'Core');
|
|
|
27 |
|
|
|
28 |
if (!defined('FULL_BASE_URL')) {
|
|
|
29 |
define('FULL_BASE_URL', 'http://cakephp.org');
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* TheHtmlTestController class
|
|
|
34 |
*
|
|
|
35 |
* @package Cake.Test.Case.View.Helper
|
|
|
36 |
*/
|
|
|
37 |
class TheHtmlTestController extends Controller {
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* name property
|
|
|
41 |
*
|
|
|
42 |
* @var string
|
|
|
43 |
*/
|
|
|
44 |
public $name = 'TheTest';
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* uses property
|
|
|
48 |
*
|
|
|
49 |
* @var mixed
|
|
|
50 |
*/
|
|
|
51 |
public $uses = null;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
class TestHtmlHelper extends HtmlHelper {
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* expose a method as public
|
|
|
58 |
*
|
|
|
59 |
* @param string $options
|
|
|
60 |
* @param string $exclude
|
|
|
61 |
* @param string $insertBefore
|
|
|
62 |
* @param string $insertAfter
|
|
|
63 |
* @return void
|
|
|
64 |
*/
|
|
|
65 |
public function parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
|
|
|
66 |
return $this->_parseAttributes($options, $exclude, $insertBefore, $insertAfter);
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Get a protected attribute value
|
|
|
71 |
*
|
|
|
72 |
* @param string $attribute
|
|
|
73 |
* @return mixed
|
|
|
74 |
*/
|
|
|
75 |
public function getAttribute($attribute) {
|
|
|
76 |
if (!isset($this->{$attribute})) {
|
|
|
77 |
return null;
|
|
|
78 |
}
|
|
|
79 |
return $this->{$attribute};
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
* Html5TestHelper class
|
|
|
86 |
*
|
|
|
87 |
* @package Cake.Test.Case.View.Helper
|
|
|
88 |
*/
|
|
|
89 |
class Html5TestHelper extends TestHtmlHelper {
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* Minimized
|
|
|
93 |
*
|
|
|
94 |
* @var array
|
|
|
95 |
*/
|
|
|
96 |
protected $_minimizedAttributes = array('require', 'checked');
|
|
|
97 |
|
|
|
98 |
/**
|
|
|
99 |
* Allow compact use in HTML
|
|
|
100 |
*
|
|
|
101 |
* @var string
|
|
|
102 |
*/
|
|
|
103 |
protected $_minimizedAttributeFormat = '%s';
|
|
|
104 |
|
|
|
105 |
/**
|
|
|
106 |
* Test to attribute format
|
|
|
107 |
*
|
|
|
108 |
* @var string
|
|
|
109 |
*/
|
|
|
110 |
protected $_attributeFormat = 'data-%s="%s"';
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
/**
|
|
|
114 |
* HtmlHelperTest class
|
|
|
115 |
*
|
|
|
116 |
* @package Cake.Test.Case.View.Helper
|
|
|
117 |
*/
|
|
|
118 |
class HtmlHelperTest extends CakeTestCase {
|
|
|
119 |
|
|
|
120 |
/**
|
|
|
121 |
* Regexp for CDATA start block
|
|
|
122 |
*
|
|
|
123 |
* @var string
|
|
|
124 |
*/
|
|
|
125 |
public $cDataStart = 'preg:/^\/\/<!\[CDATA\[[\n\r]*/';
|
|
|
126 |
|
|
|
127 |
/**
|
|
|
128 |
* Regexp for CDATA end block
|
|
|
129 |
*
|
|
|
130 |
* @var string
|
|
|
131 |
*/
|
|
|
132 |
public $cDataEnd = 'preg:/[^\]]*\]\]\>[\s\r\n]*/';
|
|
|
133 |
|
|
|
134 |
/**
|
|
|
135 |
* html property
|
|
|
136 |
*
|
|
|
137 |
* @var object
|
|
|
138 |
*/
|
|
|
139 |
public $Html = null;
|
|
|
140 |
|
|
|
141 |
/**
|
|
|
142 |
* setUp method
|
|
|
143 |
*
|
|
|
144 |
* @return void
|
|
|
145 |
*/
|
|
|
146 |
public function setUp() {
|
|
|
147 |
parent::setUp();
|
|
|
148 |
$this->View = $this->getMock('View', array('append'), array(new TheHtmlTestController()));
|
|
|
149 |
$this->Html = new TestHtmlHelper($this->View);
|
|
|
150 |
$this->Html->request = new CakeRequest(null, false);
|
|
|
151 |
$this->Html->request->webroot = '';
|
|
|
152 |
|
|
|
153 |
App::build(array(
|
|
|
154 |
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
155 |
));
|
|
|
156 |
|
|
|
157 |
Configure::write('Asset.timestamp', false);
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
/**
|
|
|
161 |
* tearDown method
|
|
|
162 |
*
|
|
|
163 |
* @return void
|
|
|
164 |
*/
|
|
|
165 |
public function tearDown() {
|
|
|
166 |
parent::tearDown();
|
|
|
167 |
unset($this->Html, $this->View);
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
/**
|
|
|
171 |
* testDocType method
|
|
|
172 |
*
|
|
|
173 |
* @return void
|
|
|
174 |
*/
|
|
|
175 |
public function testDocType() {
|
|
|
176 |
$result = $this->Html->docType();
|
|
|
177 |
$expected = '<!DOCTYPE html>';
|
|
|
178 |
$this->assertEquals($expected, $result);
|
|
|
179 |
|
|
|
180 |
$result = $this->Html->docType('html4-strict');
|
|
|
181 |
$expected = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
|
|
|
182 |
$this->assertEquals($expected, $result);
|
|
|
183 |
|
|
|
184 |
$this->assertNull($this->Html->docType('non-existing-doctype'));
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
/**
|
|
|
188 |
* testLink method
|
|
|
189 |
*
|
|
|
190 |
* @return void
|
|
|
191 |
*/
|
|
|
192 |
public function testLink() {
|
|
|
193 |
Router::connect('/:controller/:action/*');
|
|
|
194 |
|
|
|
195 |
$this->Html->request->webroot = '';
|
|
|
196 |
|
|
|
197 |
$result = $this->Html->link('/home');
|
|
|
198 |
$expected = array('a' => array('href' => '/home'), 'preg:/\/home/', '/a');
|
|
|
199 |
$this->assertTags($result, $expected);
|
|
|
200 |
|
|
|
201 |
$result = $this->Html->link(array('action' => 'login', '<[You]>'));
|
|
|
202 |
$expected = array(
|
|
|
203 |
'a' => array('href' => '/login/%3C%5BYou%5D%3E'),
|
|
|
204 |
'preg:/\/login\/<\[You\]>/',
|
|
|
205 |
'/a'
|
|
|
206 |
);
|
|
|
207 |
$this->assertTags($result, $expected);
|
|
|
208 |
|
|
|
209 |
Router::reload();
|
|
|
210 |
|
|
|
211 |
$result = $this->Html->link('Posts', array('controller' => 'posts', 'action' => 'index', 'full_base' => true));
|
|
|
212 |
$expected = array('a' => array('href' => Router::fullBaseUrl() . '/posts'), 'Posts', '/a');
|
|
|
213 |
$this->assertTags($result, $expected);
|
|
|
214 |
|
|
|
215 |
$result = $this->Html->link('Home', '/home', array('confirm' => 'Are you sure you want to do this?'));
|
|
|
216 |
$expected = array(
|
|
|
217 |
'a' => array('href' => '/home', 'onclick' => 'if (confirm("Are you sure you want to do this?")) { return true; } return false;'),
|
|
|
218 |
'Home',
|
|
|
219 |
'/a'
|
|
|
220 |
);
|
|
|
221 |
$this->assertTags($result, $expected);
|
|
|
222 |
|
|
|
223 |
$result = $this->Html->link('Home', '/home', array('escape' => false, 'confirm' => 'Confirm\'s "nightmares"'));
|
|
|
224 |
$expected = array(
|
|
|
225 |
'a' => array('href' => '/home', 'onclick' => 'if (confirm("Confirm's \"nightmares\"")) { return true; } return false;'),
|
|
|
226 |
'Home',
|
|
|
227 |
'/a'
|
|
|
228 |
);
|
|
|
229 |
$this->assertTags($result, $expected);
|
|
|
230 |
|
|
|
231 |
$result = $this->Html->link('Home', '/home', array('default' => false));
|
|
|
232 |
$expected = array(
|
|
|
233 |
'a' => array('href' => '/home', 'onclick' => 'event.returnValue = false; return false;'),
|
|
|
234 |
'Home',
|
|
|
235 |
'/a'
|
|
|
236 |
);
|
|
|
237 |
$this->assertTags($result, $expected);
|
|
|
238 |
|
|
|
239 |
$result = $this->Html->link('Home', '/home', array('default' => false, 'onclick' => 'someFunction();'));
|
|
|
240 |
$expected = array(
|
|
|
241 |
'a' => array('href' => '/home', 'onclick' => 'someFunction(); event.returnValue = false; return false;'),
|
|
|
242 |
'Home',
|
|
|
243 |
'/a'
|
|
|
244 |
);
|
|
|
245 |
$this->assertTags($result, $expected);
|
|
|
246 |
|
|
|
247 |
$result = $this->Html->link('Next >', '#');
|
|
|
248 |
$expected = array(
|
|
|
249 |
'a' => array('href' => '#'),
|
|
|
250 |
'Next >',
|
|
|
251 |
'/a'
|
|
|
252 |
);
|
|
|
253 |
$this->assertTags($result, $expected);
|
|
|
254 |
|
|
|
255 |
$result = $this->Html->link('Next >', '#', array('escape' => true));
|
|
|
256 |
$expected = array(
|
|
|
257 |
'a' => array('href' => '#'),
|
|
|
258 |
'Next >',
|
|
|
259 |
'/a'
|
|
|
260 |
);
|
|
|
261 |
$this->assertTags($result, $expected);
|
|
|
262 |
|
|
|
263 |
$result = $this->Html->link('Next >', '#', array('escape' => 'utf-8'));
|
|
|
264 |
$expected = array(
|
|
|
265 |
'a' => array('href' => '#'),
|
|
|
266 |
'Next >',
|
|
|
267 |
'/a'
|
|
|
268 |
);
|
|
|
269 |
$this->assertTags($result, $expected);
|
|
|
270 |
|
|
|
271 |
$result = $this->Html->link('Next >', '#', array('escape' => false));
|
|
|
272 |
$expected = array(
|
|
|
273 |
'a' => array('href' => '#'),
|
|
|
274 |
'Next >',
|
|
|
275 |
'/a'
|
|
|
276 |
);
|
|
|
277 |
$this->assertTags($result, $expected);
|
|
|
278 |
|
|
|
279 |
$result = $this->Html->link('Next >', '#', array(
|
|
|
280 |
'title' => 'to escape … or not escape?',
|
|
|
281 |
'escape' => false
|
|
|
282 |
));
|
|
|
283 |
$expected = array(
|
|
|
284 |
'a' => array('href' => '#', 'title' => 'to escape … or not escape?'),
|
|
|
285 |
'Next >',
|
|
|
286 |
'/a'
|
|
|
287 |
);
|
|
|
288 |
$this->assertTags($result, $expected);
|
|
|
289 |
|
|
|
290 |
$result = $this->Html->link('Next >', '#', array(
|
|
|
291 |
'title' => 'to escape … or not escape?',
|
|
|
292 |
'escape' => true
|
|
|
293 |
));
|
|
|
294 |
$expected = array(
|
|
|
295 |
'a' => array('href' => '#', 'title' => 'to escape &#8230; or not escape?'),
|
|
|
296 |
'Next >',
|
|
|
297 |
'/a'
|
|
|
298 |
);
|
|
|
299 |
$this->assertTags($result, $expected);
|
|
|
300 |
|
|
|
301 |
$result = $this->Html->link('Next >', '#', array(
|
|
|
302 |
'title' => 'Next >',
|
|
|
303 |
'escapeTitle' => false
|
|
|
304 |
));
|
|
|
305 |
$expected = array(
|
|
|
306 |
'a' => array('href' => '#', 'title' => 'Next >'),
|
|
|
307 |
'Next >',
|
|
|
308 |
'/a'
|
|
|
309 |
);
|
|
|
310 |
$this->assertTags($result, $expected);
|
|
|
311 |
|
|
|
312 |
$result = $this->Html->link('Original size', array(
|
|
|
313 |
'controller' => 'images', 'action' => 'view', 3, '?' => array('height' => 100, 'width' => 200)
|
|
|
314 |
));
|
|
|
315 |
$expected = array(
|
|
|
316 |
'a' => array('href' => '/images/view/3?height=100&width=200'),
|
|
|
317 |
'Original size',
|
|
|
318 |
'/a'
|
|
|
319 |
);
|
|
|
320 |
$this->assertTags($result, $expected);
|
|
|
321 |
|
|
|
322 |
Configure::write('Asset.timestamp', false);
|
|
|
323 |
|
|
|
324 |
$result = $this->Html->link($this->Html->image('test.gif'), '#', array('escape' => false));
|
|
|
325 |
$expected = array(
|
|
|
326 |
'a' => array('href' => '#'),
|
|
|
327 |
'img' => array('src' => 'img/test.gif', 'alt' => ''),
|
|
|
328 |
'/a'
|
|
|
329 |
);
|
|
|
330 |
$this->assertTags($result, $expected);
|
|
|
331 |
|
|
|
332 |
$result = $this->Html->link($this->Html->image('test.gif'), '#', array(
|
|
|
333 |
'title' => 'hey "howdy"',
|
|
|
334 |
'escapeTitle' => false
|
|
|
335 |
));
|
|
|
336 |
$expected = array(
|
|
|
337 |
'a' => array('href' => '#', 'title' => 'hey "howdy"'),
|
|
|
338 |
'img' => array('src' => 'img/test.gif', 'alt' => ''),
|
|
|
339 |
'/a'
|
|
|
340 |
);
|
|
|
341 |
$this->assertTags($result, $expected);
|
|
|
342 |
|
|
|
343 |
$result = $this->Html->image('test.gif', array('url' => '#'));
|
|
|
344 |
$expected = array(
|
|
|
345 |
'a' => array('href' => '#'),
|
|
|
346 |
'img' => array('src' => 'img/test.gif', 'alt' => ''),
|
|
|
347 |
'/a'
|
|
|
348 |
);
|
|
|
349 |
$this->assertTags($result, $expected);
|
|
|
350 |
|
|
|
351 |
$result = $this->Html->link($this->Html->image('../favicon.ico'), '#', array('escape' => false));
|
|
|
352 |
$expected = array(
|
|
|
353 |
'a' => array('href' => '#'),
|
|
|
354 |
'img' => array('src' => 'img/../favicon.ico', 'alt' => ''),
|
|
|
355 |
'/a'
|
|
|
356 |
);
|
|
|
357 |
$this->assertTags($result, $expected);
|
|
|
358 |
|
|
|
359 |
$result = $this->Html->image('../favicon.ico', array('url' => '#'));
|
|
|
360 |
$expected = array(
|
|
|
361 |
'a' => array('href' => '#'),
|
|
|
362 |
'img' => array('src' => 'img/../favicon.ico', 'alt' => ''),
|
|
|
363 |
'/a'
|
|
|
364 |
);
|
|
|
365 |
$this->assertTags($result, $expected);
|
|
|
366 |
|
|
|
367 |
$result = $this->Html->link('http://www.example.org?param1=value1¶m2=value2');
|
|
|
368 |
$expected = array('a' => array('href' => 'http://www.example.org?param1=value1&param2=value2'), 'http://www.example.org?param1=value1&param2=value2', '/a');
|
|
|
369 |
$this->assertTags($result, $expected);
|
|
|
370 |
|
|
|
371 |
$result = $this->Html->link('alert', 'javascript:alert(\'cakephp\');');
|
|
|
372 |
$expected = array('a' => array('href' => 'javascript:alert('cakephp');'), 'alert', '/a');
|
|
|
373 |
$this->assertTags($result, $expected);
|
|
|
374 |
|
|
|
375 |
$result = $this->Html->link('write me', 'mailto:example@cakephp.org');
|
|
|
376 |
$expected = array('a' => array('href' => 'mailto:example@cakephp.org'), 'write me', '/a');
|
|
|
377 |
$this->assertTags($result, $expected);
|
|
|
378 |
|
|
|
379 |
$result = $this->Html->link('call me on 0123465-798', 'tel:0123465-798');
|
|
|
380 |
$expected = array('a' => array('href' => 'tel:0123465-798'), 'call me on 0123465-798', '/a');
|
|
|
381 |
$this->assertTags($result, $expected);
|
|
|
382 |
|
|
|
383 |
$result = $this->Html->link('text me on 0123465-798', 'sms:0123465-798');
|
|
|
384 |
$expected = array('a' => array('href' => 'sms:0123465-798'), 'text me on 0123465-798', '/a');
|
|
|
385 |
$this->assertTags($result, $expected);
|
|
|
386 |
|
|
|
387 |
$result = $this->Html->link('say hello to 0123465-798', 'sms:0123465-798?body=hello there');
|
|
|
388 |
$expected = array('a' => array('href' => 'sms:0123465-798?body=hello there'), 'say hello to 0123465-798', '/a');
|
|
|
389 |
$this->assertTags($result, $expected);
|
|
|
390 |
|
|
|
391 |
$result = $this->Html->link('say hello to 0123465-798', 'sms:0123465-798?body=hello "cakephp"');
|
|
|
392 |
$expected = array('a' => array('href' => 'sms:0123465-798?body=hello "cakephp"'), 'say hello to 0123465-798', '/a');
|
|
|
393 |
$this->assertTags($result, $expected);
|
|
|
394 |
}
|
|
|
395 |
|
|
|
396 |
/**
|
|
|
397 |
* testImageTag method
|
|
|
398 |
*
|
|
|
399 |
* @return void
|
|
|
400 |
*/
|
|
|
401 |
public function testImageTag() {
|
|
|
402 |
$this->Html->request->webroot = '';
|
|
|
403 |
|
|
|
404 |
$result = $this->Html->image('test.gif');
|
|
|
405 |
$this->assertTags($result, array('img' => array('src' => 'img/test.gif', 'alt' => '')));
|
|
|
406 |
|
|
|
407 |
$result = $this->Html->image('http://google.com/logo.gif');
|
|
|
408 |
$this->assertTags($result, array('img' => array('src' => 'http://google.com/logo.gif', 'alt' => '')));
|
|
|
409 |
|
|
|
410 |
$result = $this->Html->image('//google.com/logo.gif');
|
|
|
411 |
$this->assertTags($result, array('img' => array('src' => '//google.com/logo.gif', 'alt' => '')));
|
|
|
412 |
|
|
|
413 |
$result = $this->Html->image(array('controller' => 'test', 'action' => 'view', 1, 'ext' => 'gif'));
|
|
|
414 |
$this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => '')));
|
|
|
415 |
|
|
|
416 |
$result = $this->Html->image('/test/view/1.gif');
|
|
|
417 |
$this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => '')));
|
|
|
418 |
}
|
|
|
419 |
|
|
|
420 |
/**
|
|
|
421 |
* Test image() with query strings.
|
|
|
422 |
*
|
|
|
423 |
* @return void
|
|
|
424 |
*/
|
|
|
425 |
public function testImageQueryString() {
|
|
|
426 |
$result = $this->Html->image('test.gif?one=two&three=four');
|
|
|
427 |
$this->assertTags($result, array('img' => array('src' => 'img/test.gif?one=two&three=four', 'alt' => '')));
|
|
|
428 |
|
|
|
429 |
$result = $this->Html->image(array(
|
|
|
430 |
'controller' => 'images',
|
|
|
431 |
'action' => 'display',
|
|
|
432 |
'test',
|
|
|
433 |
'?' => array('one' => 'two', 'three' => 'four')
|
|
|
434 |
));
|
|
|
435 |
$this->assertTags($result, array('img' => array('src' => '/images/display/test?one=two&three=four', 'alt' => '')));
|
|
|
436 |
}
|
|
|
437 |
|
|
|
438 |
/**
|
|
|
439 |
* Test that image works with pathPrefix.
|
|
|
440 |
*
|
|
|
441 |
* @return void
|
|
|
442 |
*/
|
|
|
443 |
public function testImagePathPrefix() {
|
|
|
444 |
$result = $this->Html->image('test.gif', array('pathPrefix' => '/my/custom/path/'));
|
|
|
445 |
$this->assertTags($result, array('img' => array('src' => '/my/custom/path/test.gif', 'alt' => '')));
|
|
|
446 |
|
|
|
447 |
$result = $this->Html->image('test.gif', array('pathPrefix' => 'http://cakephp.org/assets/img/'));
|
|
|
448 |
$this->assertTags($result, array('img' => array('src' => 'http://cakephp.org/assets/img/test.gif', 'alt' => '')));
|
|
|
449 |
|
|
|
450 |
$result = $this->Html->image('test.gif', array('pathPrefix' => '//cakephp.org/assets/img/'));
|
|
|
451 |
$this->assertTags($result, array('img' => array('src' => '//cakephp.org/assets/img/test.gif', 'alt' => '')));
|
|
|
452 |
|
|
|
453 |
$previousConfig = Configure::read('App.imageBaseUrl');
|
|
|
454 |
Configure::write('App.imageBaseUrl', '//cdn.cakephp.org/img/');
|
|
|
455 |
$result = $this->Html->image('test.gif');
|
|
|
456 |
$this->assertTags($result, array('img' => array('src' => '//cdn.cakephp.org/img/test.gif', 'alt' => '')));
|
|
|
457 |
Configure::write('App.imageBaseUrl', $previousConfig);
|
|
|
458 |
}
|
|
|
459 |
|
|
|
460 |
/**
|
|
|
461 |
* Test that image() works with fullBase and a webroot not equal to /
|
|
|
462 |
*
|
|
|
463 |
* @return void
|
|
|
464 |
*/
|
|
|
465 |
public function testImageWithFullBase() {
|
|
|
466 |
$result = $this->Html->image('test.gif', array('fullBase' => true));
|
|
|
467 |
$here = $this->Html->url('/', true);
|
|
|
468 |
$this->assertTags($result, array('img' => array('src' => $here . 'img/test.gif', 'alt' => '')));
|
|
|
469 |
|
|
|
470 |
$result = $this->Html->image('sub/test.gif', array('fullBase' => true));
|
|
|
471 |
$here = $this->Html->url('/', true);
|
|
|
472 |
$this->assertTags($result, array('img' => array('src' => $here . 'img/sub/test.gif', 'alt' => '')));
|
|
|
473 |
|
|
|
474 |
$request = $this->Html->request;
|
|
|
475 |
$request->webroot = '/myproject/';
|
|
|
476 |
$request->base = '/myproject';
|
|
|
477 |
Router::setRequestInfo($request);
|
|
|
478 |
|
|
|
479 |
$result = $this->Html->image('sub/test.gif', array('fullBase' => true));
|
|
|
480 |
$here = $this->Html->url('/', true);
|
|
|
481 |
$this->assertTags($result, array('img' => array('src' => $here . 'img/sub/test.gif', 'alt' => '')));
|
|
|
482 |
}
|
|
|
483 |
|
|
|
484 |
/**
|
|
|
485 |
* test image() with Asset.timestamp
|
|
|
486 |
*
|
|
|
487 |
* @return void
|
|
|
488 |
*/
|
|
|
489 |
public function testImageWithTimestampping() {
|
|
|
490 |
Configure::write('Asset.timestamp', 'force');
|
|
|
491 |
|
|
|
492 |
$this->Html->request->webroot = '/';
|
|
|
493 |
$result = $this->Html->image('cake.icon.png');
|
|
|
494 |
$this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
|
|
|
495 |
|
|
|
496 |
Configure::write('debug', 0);
|
|
|
497 |
Configure::write('Asset.timestamp', 'force');
|
|
|
498 |
|
|
|
499 |
$result = $this->Html->image('cake.icon.png');
|
|
|
500 |
$this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
|
|
|
501 |
|
|
|
502 |
$this->Html->request->webroot = '/testing/longer/';
|
|
|
503 |
$result = $this->Html->image('cake.icon.png');
|
|
|
504 |
$expected = array(
|
|
|
505 |
'img' => array('src' => 'preg:/\/testing\/longer\/img\/cake\.icon\.png\?[0-9]+/', 'alt' => '')
|
|
|
506 |
);
|
|
|
507 |
$this->assertTags($result, $expected);
|
|
|
508 |
}
|
|
|
509 |
|
|
|
510 |
/**
|
|
|
511 |
* Tests creation of an image tag using a theme and asset timestamping
|
|
|
512 |
*
|
|
|
513 |
* @return void
|
|
|
514 |
*/
|
|
|
515 |
public function testImageTagWithTheme() {
|
|
|
516 |
$this->skipIf(!is_writable(WWW_ROOT), 'Cannot write to webroot.');
|
|
|
517 |
$themeExists = is_dir(WWW_ROOT . 'theme');
|
|
|
518 |
|
|
|
519 |
App::uses('File', 'Utility');
|
|
|
520 |
|
|
|
521 |
$testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'img' . DS . '__cake_test_image.gif';
|
|
|
522 |
new File($testfile, true);
|
|
|
523 |
|
|
|
524 |
App::build(array(
|
|
|
525 |
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
|
|
526 |
));
|
|
|
527 |
Configure::write('Asset.timestamp', true);
|
|
|
528 |
Configure::write('debug', 1);
|
|
|
529 |
|
|
|
530 |
$this->Html->request->webroot = '/';
|
|
|
531 |
$this->Html->theme = 'test_theme';
|
|
|
532 |
$result = $this->Html->image('__cake_test_image.gif');
|
|
|
533 |
$this->assertTags($result, array(
|
|
|
534 |
'img' => array(
|
|
|
535 |
'src' => 'preg:/\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
|
|
|
536 |
'alt' => ''
|
|
|
537 |
)));
|
|
|
538 |
|
|
|
539 |
$this->Html->request->webroot = '/testing/';
|
|
|
540 |
$result = $this->Html->image('__cake_test_image.gif');
|
|
|
541 |
|
|
|
542 |
$this->assertTags($result, array(
|
|
|
543 |
'img' => array(
|
|
|
544 |
'src' => 'preg:/\/testing\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
|
|
|
545 |
'alt' => ''
|
|
|
546 |
)));
|
|
|
547 |
|
|
|
548 |
$dir = new Folder(WWW_ROOT . 'theme' . DS . 'test_theme');
|
|
|
549 |
$dir->delete();
|
|
|
550 |
if (!$themeExists) {
|
|
|
551 |
$dir = new Folder(WWW_ROOT . 'theme');
|
|
|
552 |
$dir->delete();
|
|
|
553 |
}
|
|
|
554 |
}
|
|
|
555 |
|
|
|
556 |
/**
|
|
|
557 |
* test theme assets in main webroot path
|
|
|
558 |
*
|
|
|
559 |
* @return void
|
|
|
560 |
*/
|
|
|
561 |
public function testThemeAssetsInMainWebrootPath() {
|
|
|
562 |
App::build(array(
|
|
|
563 |
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
|
|
564 |
));
|
|
|
565 |
$webRoot = Configure::read('App.www_root');
|
|
|
566 |
Configure::write('App.www_root', CAKE . 'Test' . DS . 'test_app' . DS . 'webroot' . DS);
|
|
|
567 |
|
|
|
568 |
$this->Html->theme = 'test_theme';
|
|
|
569 |
$result = $this->Html->css('webroot_test');
|
|
|
570 |
$expected = array(
|
|
|
571 |
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*theme\/test_theme\/css\/webroot_test\.css/')
|
|
|
572 |
);
|
|
|
573 |
$this->assertTags($result, $expected);
|
|
|
574 |
|
|
|
575 |
$this->Html->theme = 'test_theme';
|
|
|
576 |
$result = $this->Html->css('theme_webroot');
|
|
|
577 |
$expected = array(
|
|
|
578 |
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*theme\/test_theme\/css\/theme_webroot\.css/')
|
|
|
579 |
);
|
|
|
580 |
$this->assertTags($result, $expected);
|
|
|
581 |
|
|
|
582 |
Configure::write('App.www_root', $webRoot);
|
|
|
583 |
}
|
|
|
584 |
|
|
|
585 |
/**
|
|
|
586 |
* testStyle method
|
|
|
587 |
*
|
|
|
588 |
* @return void
|
|
|
589 |
*/
|
|
|
590 |
public function testStyle() {
|
|
|
591 |
$result = $this->Html->style('display: none;');
|
|
|
592 |
$this->assertEquals('display: none;', $result);
|
|
|
593 |
|
|
|
594 |
$result = $this->Html->style(array('display' => 'none', 'margin' => '10px'));
|
|
|
595 |
$expected = 'display:none; margin:10px;';
|
|
|
596 |
$this->assertRegExp('/^display\s*:\s*none\s*;\s*margin\s*:\s*10px\s*;?$/', $expected);
|
|
|
597 |
|
|
|
598 |
$result = $this->Html->style(array('display' => 'none', 'margin' => '10px'), false);
|
|
|
599 |
$lines = explode("\n", $result);
|
|
|
600 |
$this->assertRegExp('/^\s*display\s*:\s*none\s*;\s*$/', $lines[0]);
|
|
|
601 |
$this->assertRegExp('/^\s*margin\s*:\s*10px\s*;?$/', $lines[1]);
|
|
|
602 |
}
|
|
|
603 |
|
|
|
604 |
/**
|
|
|
605 |
* testCssLink method
|
|
|
606 |
*
|
|
|
607 |
* @return void
|
|
|
608 |
*/
|
|
|
609 |
public function testCssLink() {
|
|
|
610 |
Configure::write('Asset.filter.css', false);
|
|
|
611 |
|
|
|
612 |
$result = $this->Html->css('screen');
|
|
|
613 |
$expected = array(
|
|
|
614 |
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*css\/screen\.css/')
|
|
|
615 |
);
|
|
|
616 |
$this->assertTags($result, $expected);
|
|
|
617 |
|
|
|
618 |
$result = $this->Html->css('screen.css');
|
|
|
619 |
$this->assertTags($result, $expected);
|
|
|
620 |
|
|
|
621 |
CakePlugin::load('TestPlugin');
|
|
|
622 |
$result = $this->Html->css('TestPlugin.style', array('plugin' => false));
|
|
|
623 |
$expected['link']['href'] = 'preg:/.*css\/TestPlugin\.style\.css/';
|
|
|
624 |
$this->assertTags($result, $expected);
|
|
|
625 |
CakePlugin::unload('TestPlugin');
|
|
|
626 |
|
|
|
627 |
$result = $this->Html->css('my.css.library');
|
|
|
628 |
$expected['link']['href'] = 'preg:/.*css\/my\.css\.library\.css/';
|
|
|
629 |
$this->assertTags($result, $expected);
|
|
|
630 |
|
|
|
631 |
$result = $this->Html->css('screen.css?1234');
|
|
|
632 |
$expected['link']['href'] = 'preg:/.*css\/screen\.css\?1234/';
|
|
|
633 |
$this->assertTags($result, $expected);
|
|
|
634 |
|
|
|
635 |
$result = $this->Html->css('screen.css?with=param&other=param');
|
|
|
636 |
$expected['link']['href'] = 'css/screen.css?with=param&other=param';
|
|
|
637 |
$this->assertTags($result, $expected);
|
|
|
638 |
|
|
|
639 |
$result = $this->Html->css('http://whatever.com/screen.css?1234');
|
|
|
640 |
$expected['link']['href'] = 'preg:/http:\/\/.*\/screen\.css\?1234/';
|
|
|
641 |
$this->assertTags($result, $expected);
|
|
|
642 |
|
|
|
643 |
$result = $this->Html->css('cake.generic', array('pathPrefix' => '/my/custom/path/'));
|
|
|
644 |
$expected['link']['href'] = '/my/custom/path/cake.generic.css';
|
|
|
645 |
$this->assertTags($result, $expected);
|
|
|
646 |
|
|
|
647 |
$result = $this->Html->css('cake.generic', array('pathPrefix' => 'http://cakephp.org/assets/css/'));
|
|
|
648 |
$expected['link']['href'] = 'http://cakephp.org/assets/css/cake.generic.css';
|
|
|
649 |
$this->assertTags($result, $expected);
|
|
|
650 |
|
|
|
651 |
$previousConfig = Configure::read('App.cssBaseUrl');
|
|
|
652 |
Configure::write('App.cssBaseUrl', '//cdn.cakephp.org/css/');
|
|
|
653 |
$result = $this->Html->css('cake.generic');
|
|
|
654 |
$expected['link']['href'] = '//cdn.cakephp.org/css/cake.generic.css';
|
|
|
655 |
$this->assertTags($result, $expected);
|
|
|
656 |
Configure::write('App.cssBaseUrl', $previousConfig);
|
|
|
657 |
|
|
|
658 |
Configure::write('Asset.filter.css', 'css.php');
|
|
|
659 |
$result = $this->Html->css('cake.generic');
|
|
|
660 |
$expected['link']['href'] = 'preg:/.*ccss\/cake\.generic\.css/';
|
|
|
661 |
$this->assertTags($result, $expected);
|
|
|
662 |
|
|
|
663 |
$result = $this->Html->css('//example.com/css/cake.generic.css');
|
|
|
664 |
$expected['link']['href'] = 'preg:/.*example\.com\/css\/cake\.generic\.css/';
|
|
|
665 |
$this->assertTags($result, $expected);
|
|
|
666 |
|
|
|
667 |
Configure::write('Asset.filter.css', false);
|
|
|
668 |
|
|
|
669 |
$result = explode("\n", trim($this->Html->css(array('cake.generic', 'vendor.generic'))));
|
|
|
670 |
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/';
|
|
|
671 |
$this->assertTags($result[0], $expected);
|
|
|
672 |
$expected['link']['href'] = 'preg:/.*css\/vendor\.generic\.css/';
|
|
|
673 |
$this->assertTags($result[1], $expected);
|
|
|
674 |
$this->assertEquals(2, count($result));
|
|
|
675 |
|
|
|
676 |
$this->View->expects($this->at(0))
|
|
|
677 |
->method('append')
|
|
|
678 |
->with('css', $this->matchesRegularExpression('/css_in_head.css/'));
|
|
|
679 |
|
|
|
680 |
$this->View->expects($this->at(1))
|
|
|
681 |
->method('append')
|
|
|
682 |
->with('css', $this->matchesRegularExpression('/more_css_in_head.css/'));
|
|
|
683 |
|
|
|
684 |
$result = $this->Html->css('css_in_head', array('inline' => false));
|
|
|
685 |
$this->assertNull($result);
|
|
|
686 |
|
|
|
687 |
$result = $this->Html->css('more_css_in_head', array('inline' => false));
|
|
|
688 |
$this->assertNull($result);
|
|
|
689 |
|
|
|
690 |
$result = $this->Html->css('screen', array('rel' => 'import'));
|
|
|
691 |
$expected = array(
|
|
|
692 |
'style' => array('type' => 'text/css'),
|
|
|
693 |
'preg:/@import url\(.*css\/screen\.css\);/',
|
|
|
694 |
'/style'
|
|
|
695 |
);
|
|
|
696 |
$this->assertTags($result, $expected);
|
|
|
697 |
}
|
|
|
698 |
|
|
|
699 |
/**
|
|
|
700 |
* Test css link BC usage
|
|
|
701 |
*
|
|
|
702 |
* @return void
|
|
|
703 |
*/
|
|
|
704 |
public function testCssLinkBC() {
|
|
|
705 |
Configure::write('Asset.filter.css', false);
|
|
|
706 |
|
|
|
707 |
CakePlugin::load('TestPlugin');
|
|
|
708 |
$result = $this->Html->css('TestPlugin.style', null, array('plugin' => false));
|
|
|
709 |
$expected = array(
|
|
|
710 |
'link' => array(
|
|
|
711 |
'rel' => 'stylesheet',
|
|
|
712 |
'type' => 'text/css',
|
|
|
713 |
'href' => 'preg:/.*css\/TestPlugin\.style\.css/'
|
|
|
714 |
)
|
|
|
715 |
);
|
|
|
716 |
$this->assertTags($result, $expected);
|
|
|
717 |
CakePlugin::unload('TestPlugin');
|
|
|
718 |
|
|
|
719 |
$result = $this->Html->css('screen', 'import');
|
|
|
720 |
$expected = array(
|
|
|
721 |
'style' => array('type' => 'text/css'),
|
|
|
722 |
'preg:/@import url\(.*css\/screen\.css\);/',
|
|
|
723 |
'/style'
|
|
|
724 |
);
|
|
|
725 |
$this->assertTags($result, $expected);
|
|
|
726 |
|
|
|
727 |
$result = $this->Html->css('css_in_head', null, array('inline' => false));
|
|
|
728 |
$this->assertNull($result);
|
|
|
729 |
|
|
|
730 |
$result = $this->Html->css('more_css_in_head', null, array('inline' => false));
|
|
|
731 |
$this->assertNull($result);
|
|
|
732 |
}
|
|
|
733 |
|
|
|
734 |
/**
|
|
|
735 |
* testCssWithFullBase method
|
|
|
736 |
*
|
|
|
737 |
* @return void
|
|
|
738 |
*/
|
|
|
739 |
public function testCssWithFullBase() {
|
|
|
740 |
Configure::write('Asset.filter.css', false);
|
|
|
741 |
$here = $this->Html->url('/', true);
|
|
|
742 |
|
|
|
743 |
$result = $this->Html->css('screen', null, array('fullBase' => true));
|
|
|
744 |
$expected = array(
|
|
|
745 |
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => $here . 'css/screen.css')
|
|
|
746 |
);
|
|
|
747 |
$this->assertTags($result, $expected);
|
|
|
748 |
}
|
|
|
749 |
|
|
|
750 |
/**
|
|
|
751 |
* testPluginCssLink method
|
|
|
752 |
*
|
|
|
753 |
* @return void
|
|
|
754 |
*/
|
|
|
755 |
public function testPluginCssLink() {
|
|
|
756 |
Configure::write('Asset.filter.css', false);
|
|
|
757 |
CakePlugin::load('TestPlugin');
|
|
|
758 |
|
|
|
759 |
$result = $this->Html->css('TestPlugin.test_plugin_asset');
|
|
|
760 |
$expected = array(
|
|
|
761 |
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*test_plugin\/css\/test_plugin_asset\.css/')
|
|
|
762 |
);
|
|
|
763 |
$this->assertTags($result, $expected);
|
|
|
764 |
|
|
|
765 |
$result = $this->Html->css('TestPlugin.test_plugin_asset.css');
|
|
|
766 |
$this->assertTags($result, $expected);
|
|
|
767 |
|
|
|
768 |
$result = $this->Html->css('TestPlugin.my.css.library');
|
|
|
769 |
$expected['link']['href'] = 'preg:/.*test_plugin\/css\/my\.css\.library\.css/';
|
|
|
770 |
$this->assertTags($result, $expected);
|
|
|
771 |
|
|
|
772 |
$result = $this->Html->css('TestPlugin.test_plugin_asset.css?1234');
|
|
|
773 |
$expected['link']['href'] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css\?1234/';
|
|
|
774 |
$this->assertTags($result, $expected);
|
|
|
775 |
|
|
|
776 |
Configure::write('Asset.filter.css', 'css.php');
|
|
|
777 |
$result = $this->Html->css('TestPlugin.test_plugin_asset');
|
|
|
778 |
$expected['link']['href'] = 'preg:/.*test_plugin\/ccss\/test_plugin_asset\.css/';
|
|
|
779 |
$this->assertTags($result, $expected);
|
|
|
780 |
|
|
|
781 |
Configure::write('Asset.filter.css', false);
|
|
|
782 |
|
|
|
783 |
$result = explode("\n", trim($this->Html->css(array('TestPlugin.test_plugin_asset', 'TestPlugin.vendor.generic'))));
|
|
|
784 |
$expected['link']['href'] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css/';
|
|
|
785 |
$this->assertTags($result[0], $expected);
|
|
|
786 |
$expected['link']['href'] = 'preg:/.*test_plugin\/css\/vendor\.generic\.css/';
|
|
|
787 |
$this->assertTags($result[1], $expected);
|
|
|
788 |
$this->assertEquals(2, count($result));
|
|
|
789 |
|
|
|
790 |
CakePlugin::unload('TestPlugin');
|
|
|
791 |
}
|
|
|
792 |
|
|
|
793 |
/**
|
|
|
794 |
* test use of css() and timestamping
|
|
|
795 |
*
|
|
|
796 |
* @return void
|
|
|
797 |
*/
|
|
|
798 |
public function testCssTimestamping() {
|
|
|
799 |
Configure::write('debug', 2);
|
|
|
800 |
Configure::write('Asset.timestamp', true);
|
|
|
801 |
|
|
|
802 |
$expected = array(
|
|
|
803 |
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => '')
|
|
|
804 |
);
|
|
|
805 |
|
|
|
806 |
$result = $this->Html->css('cake.generic');
|
|
|
807 |
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
|
|
|
808 |
$this->assertTags($result, $expected);
|
|
|
809 |
|
|
|
810 |
Configure::write('debug', 0);
|
|
|
811 |
|
|
|
812 |
$result = $this->Html->css('cake.generic');
|
|
|
813 |
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/';
|
|
|
814 |
$this->assertTags($result, $expected);
|
|
|
815 |
|
|
|
816 |
Configure::write('Asset.timestamp', 'force');
|
|
|
817 |
|
|
|
818 |
$result = $this->Html->css('cake.generic');
|
|
|
819 |
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
|
|
|
820 |
$this->assertTags($result, $expected);
|
|
|
821 |
|
|
|
822 |
$this->Html->request->webroot = '/testing/';
|
|
|
823 |
$result = $this->Html->css('cake.generic');
|
|
|
824 |
$expected['link']['href'] = 'preg:/\/testing\/css\/cake\.generic\.css\?[0-9]+/';
|
|
|
825 |
$this->assertTags($result, $expected);
|
|
|
826 |
|
|
|
827 |
$this->Html->request->webroot = '/testing/longer/';
|
|
|
828 |
$result = $this->Html->css('cake.generic');
|
|
|
829 |
$expected['link']['href'] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?[0-9]+/';
|
|
|
830 |
$this->assertTags($result, $expected);
|
|
|
831 |
}
|
|
|
832 |
|
|
|
833 |
/**
|
|
|
834 |
* test use of css() and timestamping with plugin syntax
|
|
|
835 |
*
|
|
|
836 |
* @return void
|
|
|
837 |
*/
|
|
|
838 |
public function testPluginCssTimestamping() {
|
|
|
839 |
CakePlugin::load('TestPlugin');
|
|
|
840 |
|
|
|
841 |
Configure::write('debug', 2);
|
|
|
842 |
Configure::write('Asset.timestamp', true);
|
|
|
843 |
|
|
|
844 |
$expected = array(
|
|
|
845 |
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => '')
|
|
|
846 |
);
|
|
|
847 |
|
|
|
848 |
$result = $this->Html->css('TestPlugin.test_plugin_asset');
|
|
|
849 |
$expected['link']['href'] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css\?[0-9]+/';
|
|
|
850 |
$this->assertTags($result, $expected);
|
|
|
851 |
|
|
|
852 |
Configure::write('debug', 0);
|
|
|
853 |
|
|
|
854 |
$result = $this->Html->css('TestPlugin.test_plugin_asset');
|
|
|
855 |
$expected['link']['href'] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css/';
|
|
|
856 |
$this->assertTags($result, $expected);
|
|
|
857 |
|
|
|
858 |
Configure::write('Asset.timestamp', 'force');
|
|
|
859 |
|
|
|
860 |
$result = $this->Html->css('TestPlugin.test_plugin_asset');
|
|
|
861 |
$expected['link']['href'] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css\?[0-9]+/';
|
|
|
862 |
$this->assertTags($result, $expected);
|
|
|
863 |
|
|
|
864 |
$this->Html->request->webroot = '/testing/';
|
|
|
865 |
$result = $this->Html->css('TestPlugin.test_plugin_asset');
|
|
|
866 |
$expected['link']['href'] = 'preg:/\/testing\/test_plugin\/css\/test_plugin_asset\.css\?[0-9]+/';
|
|
|
867 |
$this->assertTags($result, $expected);
|
|
|
868 |
|
|
|
869 |
$this->Html->request->webroot = '/testing/longer/';
|
|
|
870 |
$result = $this->Html->css('TestPlugin.test_plugin_asset');
|
|
|
871 |
$expected['link']['href'] = 'preg:/\/testing\/longer\/test_plugin\/css\/test_plugin_asset\.css\?[0-9]+/';
|
|
|
872 |
$this->assertTags($result, $expected);
|
|
|
873 |
|
|
|
874 |
CakePlugin::unload('TestPlugin');
|
|
|
875 |
}
|
|
|
876 |
|
|
|
877 |
/**
|
|
|
878 |
* test timestamp enforcement for script tags.
|
|
|
879 |
*
|
|
|
880 |
* @return void
|
|
|
881 |
*/
|
|
|
882 |
public function testScriptTimestamping() {
|
|
|
883 |
$this->skipIf(!is_writable(WWW_ROOT . 'js'), 'webroot/js is not Writable, timestamp testing has been skipped.');
|
|
|
884 |
|
|
|
885 |
Configure::write('debug', 2);
|
|
|
886 |
Configure::write('Asset.timestamp', true);
|
|
|
887 |
|
|
|
888 |
touch(WWW_ROOT . 'js' . DS . '__cake_js_test.js');
|
|
|
889 |
$timestamp = substr(strtotime('now'), 0, 8);
|
|
|
890 |
|
|
|
891 |
$result = $this->Html->script('__cake_js_test', array('inline' => true, 'once' => false));
|
|
|
892 |
$this->assertRegExp('/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result, 'Timestamp value not found %s');
|
|
|
893 |
|
|
|
894 |
Configure::write('debug', 0);
|
|
|
895 |
Configure::write('Asset.timestamp', 'force');
|
|
|
896 |
$result = $this->Html->script('__cake_js_test', array('inline' => true, 'once' => false));
|
|
|
897 |
$this->assertRegExp('/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result, 'Timestamp value not found %s');
|
|
|
898 |
unlink(WWW_ROOT . 'js' . DS . '__cake_js_test.js');
|
|
|
899 |
Configure::write('Asset.timestamp', false);
|
|
|
900 |
}
|
|
|
901 |
|
|
|
902 |
/**
|
|
|
903 |
* test timestamp enforcement for script tags with plugin syntax.
|
|
|
904 |
*
|
|
|
905 |
* @return void
|
|
|
906 |
*/
|
|
|
907 |
public function testPluginScriptTimestamping() {
|
|
|
908 |
CakePlugin::load('TestPlugin');
|
|
|
909 |
|
|
|
910 |
$pluginPath = CakePlugin::path('TestPlugin');
|
|
|
911 |
$pluginJsPath = $pluginPath . 'webroot/js';
|
|
|
912 |
$this->skipIf(!is_writable($pluginJsPath), $pluginJsPath . ' is not Writable, timestamp testing has been skipped.');
|
|
|
913 |
|
|
|
914 |
Configure::write('debug', 2);
|
|
|
915 |
Configure::write('Asset.timestamp', true);
|
|
|
916 |
|
|
|
917 |
touch($pluginJsPath . DS . '__cake_js_test.js');
|
|
|
918 |
$timestamp = substr(strtotime('now'), 0, 8);
|
|
|
919 |
|
|
|
920 |
$result = $this->Html->script('TestPlugin.__cake_js_test', array('inline' => true, 'once' => false));
|
|
|
921 |
$this->assertRegExp('/test_plugin\/js\/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result, 'Timestamp value not found %s');
|
|
|
922 |
|
|
|
923 |
Configure::write('debug', 0);
|
|
|
924 |
Configure::write('Asset.timestamp', 'force');
|
|
|
925 |
$result = $this->Html->script('TestPlugin.__cake_js_test', array('inline' => true, 'once' => false));
|
|
|
926 |
$this->assertRegExp('/test_plugin\/js\/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result, 'Timestamp value not found %s');
|
|
|
927 |
unlink($pluginJsPath . DS . '__cake_js_test.js');
|
|
|
928 |
Configure::write('Asset.timestamp', false);
|
|
|
929 |
|
|
|
930 |
CakePlugin::unload('TestPlugin');
|
|
|
931 |
}
|
|
|
932 |
|
|
|
933 |
/**
|
|
|
934 |
* test that scripts added with uses() are only ever included once.
|
|
|
935 |
* test script tag generation
|
|
|
936 |
*
|
|
|
937 |
* @return void
|
|
|
938 |
*/
|
|
|
939 |
public function testScript() {
|
|
|
940 |
$result = $this->Html->script('foo');
|
|
|
941 |
$expected = array(
|
|
|
942 |
'script' => array('type' => 'text/javascript', 'src' => 'js/foo.js')
|
|
|
943 |
);
|
|
|
944 |
$this->assertTags($result, $expected);
|
|
|
945 |
|
|
|
946 |
$result = $this->Html->script(array('foobar', 'bar'));
|
|
|
947 |
$expected = array(
|
|
|
948 |
array('script' => array('type' => 'text/javascript', 'src' => 'js/foobar.js')),
|
|
|
949 |
'/script',
|
|
|
950 |
array('script' => array('type' => 'text/javascript', 'src' => 'js/bar.js')),
|
|
|
951 |
'/script',
|
|
|
952 |
);
|
|
|
953 |
$this->assertTags($result, $expected);
|
|
|
954 |
|
|
|
955 |
$result = $this->Html->script('jquery-1.3');
|
|
|
956 |
$expected = array(
|
|
|
957 |
'script' => array('type' => 'text/javascript', 'src' => 'js/jquery-1.3.js')
|
|
|
958 |
);
|
|
|
959 |
$this->assertTags($result, $expected);
|
|
|
960 |
|
|
|
961 |
$result = $this->Html->script('test.json');
|
|
|
962 |
$expected = array(
|
|
|
963 |
'script' => array('type' => 'text/javascript', 'src' => 'js/test.json.js')
|
|
|
964 |
);
|
|
|
965 |
$this->assertTags($result, $expected);
|
|
|
966 |
|
|
|
967 |
$result = $this->Html->script('http://example.com/test.json');
|
|
|
968 |
$expected = array(
|
|
|
969 |
'script' => array('type' => 'text/javascript', 'src' => 'http://example.com/test.json')
|
|
|
970 |
);
|
|
|
971 |
$this->assertTags($result, $expected);
|
|
|
972 |
|
|
|
973 |
$result = $this->Html->script('/plugin/js/jquery-1.3.2.js?someparam=foo');
|
|
|
974 |
$expected = array(
|
|
|
975 |
'script' => array('type' => 'text/javascript', 'src' => '/plugin/js/jquery-1.3.2.js?someparam=foo')
|
|
|
976 |
);
|
|
|
977 |
$this->assertTags($result, $expected);
|
|
|
978 |
|
|
|
979 |
$result = $this->Html->script('test.json.js?foo=bar');
|
|
|
980 |
$expected = array(
|
|
|
981 |
'script' => array('type' => 'text/javascript', 'src' => 'js/test.json.js?foo=bar')
|
|
|
982 |
);
|
|
|
983 |
$this->assertTags($result, $expected);
|
|
|
984 |
|
|
|
985 |
$result = $this->Html->script('test.json.js?foo=bar&other=test');
|
|
|
986 |
$expected = array(
|
|
|
987 |
'script' => array('type' => 'text/javascript', 'src' => 'js/test.json.js?foo=bar&other=test')
|
|
|
988 |
);
|
|
|
989 |
$this->assertTags($result, $expected);
|
|
|
990 |
|
|
|
991 |
$result = $this->Html->script('foo2', array('pathPrefix' => '/my/custom/path/'));
|
|
|
992 |
$expected = array(
|
|
|
993 |
'script' => array('type' => 'text/javascript', 'src' => '/my/custom/path/foo2.js')
|
|
|
994 |
);
|
|
|
995 |
$this->assertTags($result, $expected);
|
|
|
996 |
|
|
|
997 |
$result = $this->Html->script('foo3', array('pathPrefix' => 'http://cakephp.org/assets/js/'));
|
|
|
998 |
$expected = array(
|
|
|
999 |
'script' => array('type' => 'text/javascript', 'src' => 'http://cakephp.org/assets/js/foo3.js')
|
|
|
1000 |
);
|
|
|
1001 |
$this->assertTags($result, $expected);
|
|
|
1002 |
|
|
|
1003 |
$previousConfig = Configure::read('App.jsBaseUrl');
|
|
|
1004 |
Configure::write('App.jsBaseUrl', '//cdn.cakephp.org/js/');
|
|
|
1005 |
$result = $this->Html->script('foo4');
|
|
|
1006 |
$expected = array(
|
|
|
1007 |
'script' => array('type' => 'text/javascript', 'src' => '//cdn.cakephp.org/js/foo4.js')
|
|
|
1008 |
);
|
|
|
1009 |
$this->assertTags($result, $expected);
|
|
|
1010 |
Configure::write('App.jsBaseUrl', $previousConfig);
|
|
|
1011 |
|
|
|
1012 |
$result = $this->Html->script('foo');
|
|
|
1013 |
$this->assertNull($result, 'Script returned upon duplicate inclusion %s');
|
|
|
1014 |
|
|
|
1015 |
$result = $this->Html->script(array('foo', 'bar', 'baz'));
|
|
|
1016 |
$this->assertNotRegExp('/foo.js/', $result);
|
|
|
1017 |
|
|
|
1018 |
$result = $this->Html->script('foo', array('inline' => true, 'once' => false));
|
|
|
1019 |
$this->assertNotNull($result);
|
|
|
1020 |
|
|
|
1021 |
$result = $this->Html->script('jquery-1.3.2', array('defer' => true, 'encoding' => 'utf-8'));
|
|
|
1022 |
$expected = array(
|
|
|
1023 |
'script' => array('type' => 'text/javascript', 'src' => 'js/jquery-1.3.2.js', 'defer' => 'defer', 'encoding' => 'utf-8')
|
|
|
1024 |
);
|
|
|
1025 |
$this->assertTags($result, $expected);
|
|
|
1026 |
}
|
|
|
1027 |
|
|
|
1028 |
/**
|
|
|
1029 |
* test that plugin scripts added with uses() are only ever included once.
|
|
|
1030 |
* test script tag generation with plugin syntax
|
|
|
1031 |
*
|
|
|
1032 |
* @return void
|
|
|
1033 |
*/
|
|
|
1034 |
public function testPluginScript() {
|
|
|
1035 |
CakePlugin::load('TestPlugin');
|
|
|
1036 |
|
|
|
1037 |
$result = $this->Html->script('TestPlugin.foo');
|
|
|
1038 |
$expected = array(
|
|
|
1039 |
'script' => array('type' => 'text/javascript', 'src' => 'test_plugin/js/foo.js')
|
|
|
1040 |
);
|
|
|
1041 |
$this->assertTags($result, $expected);
|
|
|
1042 |
|
|
|
1043 |
$result = $this->Html->script(array('TestPlugin.foobar', 'TestPlugin.bar'));
|
|
|
1044 |
$expected = array(
|
|
|
1045 |
array('script' => array('type' => 'text/javascript', 'src' => 'test_plugin/js/foobar.js')),
|
|
|
1046 |
'/script',
|
|
|
1047 |
array('script' => array('type' => 'text/javascript', 'src' => 'test_plugin/js/bar.js')),
|
|
|
1048 |
'/script',
|
|
|
1049 |
);
|
|
|
1050 |
$this->assertTags($result, $expected);
|
|
|
1051 |
|
|
|
1052 |
$result = $this->Html->script('TestPlugin.jquery-1.3');
|
|
|
1053 |
$expected = array(
|
|
|
1054 |
'script' => array('type' => 'text/javascript', 'src' => 'test_plugin/js/jquery-1.3.js')
|
|
|
1055 |
);
|
|
|
1056 |
$this->assertTags($result, $expected);
|
|
|
1057 |
|
|
|
1058 |
$result = $this->Html->script('TestPlugin.test.json');
|
|
|
1059 |
$expected = array(
|
|
|
1060 |
'script' => array('type' => 'text/javascript', 'src' => 'test_plugin/js/test.json.js')
|
|
|
1061 |
);
|
|
|
1062 |
$this->assertTags($result, $expected);
|
|
|
1063 |
|
|
|
1064 |
$result = $this->Html->script('TestPlugin./jquery-1.3.2.js?someparam=foo');
|
|
|
1065 |
$expected = array(
|
|
|
1066 |
'script' => array('type' => 'text/javascript', 'src' => 'test_plugin/jquery-1.3.2.js?someparam=foo')
|
|
|
1067 |
);
|
|
|
1068 |
$this->assertTags($result, $expected);
|
|
|
1069 |
|
|
|
1070 |
$result = $this->Html->script('TestPlugin.test.json.js?foo=bar');
|
|
|
1071 |
$expected = array(
|
|
|
1072 |
'script' => array('type' => 'text/javascript', 'src' => 'test_plugin/js/test.json.js?foo=bar')
|
|
|
1073 |
);
|
|
|
1074 |
$this->assertTags($result, $expected);
|
|
|
1075 |
|
|
|
1076 |
$result = $this->Html->script('TestPlugin.foo');
|
|
|
1077 |
$this->assertNull($result, 'Script returned upon duplicate inclusion %s');
|
|
|
1078 |
|
|
|
1079 |
$result = $this->Html->script(array('TestPlugin.foo', 'TestPlugin.bar', 'TestPlugin.baz'));
|
|
|
1080 |
$this->assertNotRegExp('/test_plugin\/js\/foo.js/', $result);
|
|
|
1081 |
|
|
|
1082 |
$result = $this->Html->script('TestPlugin.foo', array('inline' => true, 'once' => false));
|
|
|
1083 |
$this->assertNotNull($result);
|
|
|
1084 |
|
|
|
1085 |
$result = $this->Html->script('TestPlugin.jquery-1.3.2', array('defer' => true, 'encoding' => 'utf-8'));
|
|
|
1086 |
$expected = array(
|
|
|
1087 |
'script' => array('type' => 'text/javascript', 'src' => 'test_plugin/js/jquery-1.3.2.js', 'defer' => 'defer', 'encoding' => 'utf-8')
|
|
|
1088 |
);
|
|
|
1089 |
$this->assertTags($result, $expected);
|
|
|
1090 |
|
|
|
1091 |
CakePlugin::unload('TestPlugin');
|
|
|
1092 |
}
|
|
|
1093 |
|
|
|
1094 |
/**
|
|
|
1095 |
* test that script() works with blocks.
|
|
|
1096 |
*
|
|
|
1097 |
* @return void
|
|
|
1098 |
*/
|
|
|
1099 |
public function testScriptWithBlocks() {
|
|
|
1100 |
$this->View->expects($this->at(0))
|
|
|
1101 |
->method('append')
|
|
|
1102 |
->with('script', $this->matchesRegularExpression('/script_in_head.js/'));
|
|
|
1103 |
|
|
|
1104 |
$this->View->expects($this->at(1))
|
|
|
1105 |
->method('append')
|
|
|
1106 |
->with('script', $this->matchesRegularExpression('/bool_false.js/'));
|
|
|
1107 |
|
|
|
1108 |
$this->View->expects($this->at(2))
|
|
|
1109 |
->method('append')
|
|
|
1110 |
->with('headScripts', $this->matchesRegularExpression('/second_script.js/'));
|
|
|
1111 |
|
|
|
1112 |
$result = $this->Html->script('script_in_head', array('inline' => false));
|
|
|
1113 |
$this->assertNull($result);
|
|
|
1114 |
|
|
|
1115 |
$result = $this->Html->script('bool_false', false);
|
|
|
1116 |
$this->assertNull($result);
|
|
|
1117 |
|
|
|
1118 |
$result = $this->Html->script('second_script', array('block' => 'headScripts'));
|
|
|
1119 |
$this->assertNull($result);
|
|
|
1120 |
}
|
|
|
1121 |
|
|
|
1122 |
/**
|
|
|
1123 |
* Test that Asset.filter.js works.
|
|
|
1124 |
*
|
|
|
1125 |
* @return void
|
|
|
1126 |
*/
|
|
|
1127 |
public function testScriptAssetFilter() {
|
|
|
1128 |
Configure::write('Asset.filter.js', 'js.php');
|
|
|
1129 |
|
|
|
1130 |
$result = $this->Html->script('jquery-1.3');
|
|
|
1131 |
$expected = array(
|
|
|
1132 |
'script' => array('type' => 'text/javascript', 'src' => 'cjs/jquery-1.3.js')
|
|
|
1133 |
);
|
|
|
1134 |
$this->assertTags($result, $expected);
|
|
|
1135 |
|
|
|
1136 |
$result = $this->Html->script('//example.com/js/jquery-1.3.js');
|
|
|
1137 |
$expected = array(
|
|
|
1138 |
'script' => array('type' => 'text/javascript', 'src' => '//example.com/js/jquery-1.3.js')
|
|
|
1139 |
);
|
|
|
1140 |
$this->assertTags($result, $expected);
|
|
|
1141 |
}
|
|
|
1142 |
|
|
|
1143 |
/**
|
|
|
1144 |
* testScriptWithFullBase method
|
|
|
1145 |
*
|
|
|
1146 |
* @return void
|
|
|
1147 |
*/
|
|
|
1148 |
public function testScriptWithFullBase() {
|
|
|
1149 |
$here = $this->Html->url('/', true);
|
|
|
1150 |
|
|
|
1151 |
$result = $this->Html->script('foo', array('fullBase' => true));
|
|
|
1152 |
$expected = array(
|
|
|
1153 |
'script' => array('type' => 'text/javascript', 'src' => $here . 'js/foo.js')
|
|
|
1154 |
);
|
|
|
1155 |
$this->assertTags($result, $expected);
|
|
|
1156 |
|
|
|
1157 |
$result = $this->Html->script(array('foobar', 'bar'), array('fullBase' => true));
|
|
|
1158 |
$expected = array(
|
|
|
1159 |
array('script' => array('type' => 'text/javascript', 'src' => $here . 'js/foobar.js')),
|
|
|
1160 |
'/script',
|
|
|
1161 |
array('script' => array('type' => 'text/javascript', 'src' => $here . 'js/bar.js')),
|
|
|
1162 |
'/script',
|
|
|
1163 |
);
|
|
|
1164 |
$this->assertTags($result, $expected);
|
|
|
1165 |
}
|
|
|
1166 |
|
|
|
1167 |
/**
|
|
|
1168 |
* test a script file in the webroot/theme dir.
|
|
|
1169 |
*
|
|
|
1170 |
* @return void
|
|
|
1171 |
*/
|
|
|
1172 |
public function testScriptInTheme() {
|
|
|
1173 |
$this->skipIf(!is_writable(WWW_ROOT), 'Cannot write to webroot.');
|
|
|
1174 |
$themeExists = is_dir(WWW_ROOT . 'theme');
|
|
|
1175 |
|
|
|
1176 |
App::uses('File', 'Utility');
|
|
|
1177 |
|
|
|
1178 |
$testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'js' . DS . '__test_js.js';
|
|
|
1179 |
new File($testfile, true);
|
|
|
1180 |
|
|
|
1181 |
App::build(array(
|
|
|
1182 |
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
|
|
1183 |
));
|
|
|
1184 |
|
|
|
1185 |
$this->Html->webroot = '/';
|
|
|
1186 |
$this->Html->theme = 'test_theme';
|
|
|
1187 |
$result = $this->Html->script('__test_js.js');
|
|
|
1188 |
$expected = array(
|
|
|
1189 |
'script' => array('src' => '/theme/test_theme/js/__test_js.js', 'type' => 'text/javascript')
|
|
|
1190 |
);
|
|
|
1191 |
$this->assertTags($result, $expected);
|
|
|
1192 |
|
|
|
1193 |
$Folder = new Folder(WWW_ROOT . 'theme' . DS . 'test_theme');
|
|
|
1194 |
$Folder->delete();
|
|
|
1195 |
|
|
|
1196 |
if (!$themeExists) {
|
|
|
1197 |
$dir = new Folder(WWW_ROOT . 'theme');
|
|
|
1198 |
$dir->delete();
|
|
|
1199 |
}
|
|
|
1200 |
}
|
|
|
1201 |
|
|
|
1202 |
/**
|
|
|
1203 |
* test Script block generation
|
|
|
1204 |
*
|
|
|
1205 |
* @return void
|
|
|
1206 |
*/
|
|
|
1207 |
public function testScriptBlock() {
|
|
|
1208 |
$result = $this->Html->scriptBlock('window.foo = 2;');
|
|
|
1209 |
$expected = array(
|
|
|
1210 |
'script' => array('type' => 'text/javascript'),
|
|
|
1211 |
$this->cDataStart,
|
|
|
1212 |
'window.foo = 2;',
|
|
|
1213 |
$this->cDataEnd,
|
|
|
1214 |
'/script',
|
|
|
1215 |
);
|
|
|
1216 |
$this->assertTags($result, $expected);
|
|
|
1217 |
|
|
|
1218 |
$result = $this->Html->scriptBlock('window.foo = 2;', array('type' => 'text/x-handlebars-template'));
|
|
|
1219 |
$expected = array(
|
|
|
1220 |
'script' => array('type' => 'text/x-handlebars-template'),
|
|
|
1221 |
$this->cDataStart,
|
|
|
1222 |
'window.foo = 2;',
|
|
|
1223 |
$this->cDataEnd,
|
|
|
1224 |
'/script',
|
|
|
1225 |
);
|
|
|
1226 |
$this->assertTags($result, $expected);
|
|
|
1227 |
|
|
|
1228 |
$result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false));
|
|
|
1229 |
$expected = array(
|
|
|
1230 |
'script' => array('type' => 'text/javascript'),
|
|
|
1231 |
'window.foo = 2;',
|
|
|
1232 |
'/script',
|
|
|
1233 |
);
|
|
|
1234 |
$this->assertTags($result, $expected);
|
|
|
1235 |
|
|
|
1236 |
$result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => true));
|
|
|
1237 |
$expected = array(
|
|
|
1238 |
'script' => array('type' => 'text/javascript'),
|
|
|
1239 |
$this->cDataStart,
|
|
|
1240 |
'window.foo = 2;',
|
|
|
1241 |
$this->cDataEnd,
|
|
|
1242 |
'/script',
|
|
|
1243 |
);
|
|
|
1244 |
$this->assertTags($result, $expected);
|
|
|
1245 |
|
|
|
1246 |
$this->View->expects($this->at(0))
|
|
|
1247 |
->method('append')
|
|
|
1248 |
->with('script', $this->matchesRegularExpression('/window\.foo\s\=\s2;/'));
|
|
|
1249 |
|
|
|
1250 |
$this->View->expects($this->at(1))
|
|
|
1251 |
->method('append')
|
|
|
1252 |
->with('scriptTop', $this->stringContains('alert('));
|
|
|
1253 |
|
|
|
1254 |
$result = $this->Html->scriptBlock('window.foo = 2;', array('inline' => false));
|
|
|
1255 |
$this->assertNull($result);
|
|
|
1256 |
|
|
|
1257 |
$result = $this->Html->scriptBlock('alert("hi")', array('block' => 'scriptTop'));
|
|
|
1258 |
$this->assertNull($result);
|
|
|
1259 |
|
|
|
1260 |
$result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false, 'encoding' => 'utf-8'));
|
|
|
1261 |
$expected = array(
|
|
|
1262 |
'script' => array('type' => 'text/javascript', 'encoding' => 'utf-8'),
|
|
|
1263 |
'window.foo = 2;',
|
|
|
1264 |
'/script',
|
|
|
1265 |
);
|
|
|
1266 |
$this->assertTags($result, $expected);
|
|
|
1267 |
}
|
|
|
1268 |
|
|
|
1269 |
/**
|
|
|
1270 |
* test script tag output buffering when using scriptStart() and scriptEnd();
|
|
|
1271 |
*
|
|
|
1272 |
* @return void
|
|
|
1273 |
*/
|
|
|
1274 |
public function testScriptStartAndScriptEnd() {
|
|
|
1275 |
$result = $this->Html->scriptStart(array('safe' => true));
|
|
|
1276 |
$this->assertNull($result);
|
|
|
1277 |
echo 'this is some javascript';
|
|
|
1278 |
|
|
|
1279 |
$result = $this->Html->scriptEnd();
|
|
|
1280 |
$expected = array(
|
|
|
1281 |
'script' => array('type' => 'text/javascript'),
|
|
|
1282 |
$this->cDataStart,
|
|
|
1283 |
'this is some javascript',
|
|
|
1284 |
$this->cDataEnd,
|
|
|
1285 |
'/script'
|
|
|
1286 |
);
|
|
|
1287 |
$this->assertTags($result, $expected);
|
|
|
1288 |
|
|
|
1289 |
$result = $this->Html->scriptStart(array('safe' => false));
|
|
|
1290 |
$this->assertNull($result);
|
|
|
1291 |
echo 'this is some javascript';
|
|
|
1292 |
|
|
|
1293 |
$result = $this->Html->scriptEnd();
|
|
|
1294 |
$expected = array(
|
|
|
1295 |
'script' => array('type' => 'text/javascript'),
|
|
|
1296 |
'this is some javascript',
|
|
|
1297 |
'/script'
|
|
|
1298 |
);
|
|
|
1299 |
$this->assertTags($result, $expected);
|
|
|
1300 |
|
|
|
1301 |
$result = $this->Html->scriptStart(array('safe' => true, 'type' => 'text/x-handlebars-template'));
|
|
|
1302 |
$this->assertNull($result);
|
|
|
1303 |
echo 'this is some template';
|
|
|
1304 |
|
|
|
1305 |
$result = $this->Html->scriptEnd();
|
|
|
1306 |
$expected = array(
|
|
|
1307 |
'script' => array('type' => 'text/x-handlebars-template'),
|
|
|
1308 |
$this->cDataStart,
|
|
|
1309 |
'this is some template',
|
|
|
1310 |
$this->cDataEnd,
|
|
|
1311 |
'/script'
|
|
|
1312 |
);
|
|
|
1313 |
$this->assertTags($result, $expected);
|
|
|
1314 |
|
|
|
1315 |
$this->View->expects($this->once())
|
|
|
1316 |
->method('append');
|
|
|
1317 |
$result = $this->Html->scriptStart(array('safe' => false, 'inline' => false));
|
|
|
1318 |
$this->assertNull($result);
|
|
|
1319 |
echo 'this is some javascript';
|
|
|
1320 |
|
|
|
1321 |
$result = $this->Html->scriptEnd();
|
|
|
1322 |
$this->assertNull($result);
|
|
|
1323 |
}
|
|
|
1324 |
|
|
|
1325 |
/**
|
|
|
1326 |
* testCharsetTag method
|
|
|
1327 |
*
|
|
|
1328 |
* @return void
|
|
|
1329 |
*/
|
|
|
1330 |
public function testCharsetTag() {
|
|
|
1331 |
Configure::write('App.encoding', null);
|
|
|
1332 |
$result = $this->Html->charset();
|
|
|
1333 |
$this->assertTags($result, array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=utf-8')));
|
|
|
1334 |
|
|
|
1335 |
Configure::write('App.encoding', 'ISO-8859-1');
|
|
|
1336 |
$result = $this->Html->charset();
|
|
|
1337 |
$this->assertTags($result, array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=iso-8859-1')));
|
|
|
1338 |
|
|
|
1339 |
$result = $this->Html->charset('UTF-7');
|
|
|
1340 |
$this->assertTags($result, array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=UTF-7')));
|
|
|
1341 |
}
|
|
|
1342 |
|
|
|
1343 |
/**
|
|
|
1344 |
* testGetCrumb and addCrumb method
|
|
|
1345 |
*
|
|
|
1346 |
* @return void
|
|
|
1347 |
*/
|
|
|
1348 |
public function testBreadcrumb() {
|
|
|
1349 |
$this->assertNull($this->Html->getCrumbs());
|
|
|
1350 |
|
|
|
1351 |
$this->Html->addCrumb('First', '#first');
|
|
|
1352 |
$this->Html->addCrumb('Second', '#second');
|
|
|
1353 |
$this->Html->addCrumb('Third', '#third');
|
|
|
1354 |
|
|
|
1355 |
$result = $this->Html->getCrumbs();
|
|
|
1356 |
$expected = array(
|
|
|
1357 |
array('a' => array('href' => '#first')),
|
|
|
1358 |
'First',
|
|
|
1359 |
'/a',
|
|
|
1360 |
'»',
|
|
|
1361 |
array('a' => array('href' => '#second')),
|
|
|
1362 |
'Second',
|
|
|
1363 |
'/a',
|
|
|
1364 |
'»',
|
|
|
1365 |
array('a' => array('href' => '#third')),
|
|
|
1366 |
'Third',
|
|
|
1367 |
'/a',
|
|
|
1368 |
);
|
|
|
1369 |
$this->assertTags($result, $expected);
|
|
|
1370 |
|
|
|
1371 |
$result = $this->Html->getCrumbs(' > ');
|
|
|
1372 |
$expected = array(
|
|
|
1373 |
array('a' => array('href' => '#first')),
|
|
|
1374 |
'First',
|
|
|
1375 |
'/a',
|
|
|
1376 |
' > ',
|
|
|
1377 |
array('a' => array('href' => '#second')),
|
|
|
1378 |
'Second',
|
|
|
1379 |
'/a',
|
|
|
1380 |
' > ',
|
|
|
1381 |
array('a' => array('href' => '#third')),
|
|
|
1382 |
'Third',
|
|
|
1383 |
'/a',
|
|
|
1384 |
);
|
|
|
1385 |
$this->assertTags($result, $expected);
|
|
|
1386 |
|
|
|
1387 |
$this->Html->addCrumb('Fourth', null);
|
|
|
1388 |
|
|
|
1389 |
$result = $this->Html->getCrumbs();
|
|
|
1390 |
$expected = array(
|
|
|
1391 |
array('a' => array('href' => '#first')),
|
|
|
1392 |
'First',
|
|
|
1393 |
'/a',
|
|
|
1394 |
'»',
|
|
|
1395 |
array('a' => array('href' => '#second')),
|
|
|
1396 |
'Second',
|
|
|
1397 |
'/a',
|
|
|
1398 |
'»',
|
|
|
1399 |
array('a' => array('href' => '#third')),
|
|
|
1400 |
'Third',
|
|
|
1401 |
'/a',
|
|
|
1402 |
'»',
|
|
|
1403 |
'Fourth'
|
|
|
1404 |
);
|
|
|
1405 |
$this->assertTags($result, $expected);
|
|
|
1406 |
|
|
|
1407 |
$result = $this->Html->getCrumbs('-', 'Start');
|
|
|
1408 |
$expected = array(
|
|
|
1409 |
array('a' => array('href' => '/')),
|
|
|
1410 |
'Start',
|
|
|
1411 |
'/a',
|
|
|
1412 |
'-',
|
|
|
1413 |
array('a' => array('href' => '#first')),
|
|
|
1414 |
'First',
|
|
|
1415 |
'/a',
|
|
|
1416 |
'-',
|
|
|
1417 |
array('a' => array('href' => '#second')),
|
|
|
1418 |
'Second',
|
|
|
1419 |
'/a',
|
|
|
1420 |
'-',
|
|
|
1421 |
array('a' => array('href' => '#third')),
|
|
|
1422 |
'Third',
|
|
|
1423 |
'/a',
|
|
|
1424 |
'-',
|
|
|
1425 |
'Fourth'
|
|
|
1426 |
);
|
|
|
1427 |
$this->assertTags($result, $expected);
|
|
|
1428 |
}
|
|
|
1429 |
|
|
|
1430 |
/**
|
|
|
1431 |
* Test the array form of $startText
|
|
|
1432 |
*
|
|
|
1433 |
* @return void
|
|
|
1434 |
*/
|
|
|
1435 |
public function testGetCrumbFirstLink() {
|
|
|
1436 |
$result = $this->Html->getCrumbList(null, 'Home');
|
|
|
1437 |
$this->assertTags(
|
|
|
1438 |
$result,
|
|
|
1439 |
array(
|
|
|
1440 |
'<ul',
|
|
|
1441 |
array('li' => array('class' => 'first')),
|
|
|
1442 |
array('a' => array('href' => '/')), 'Home', '/a',
|
|
|
1443 |
'/li',
|
|
|
1444 |
'/ul'
|
|
|
1445 |
)
|
|
|
1446 |
);
|
|
|
1447 |
|
|
|
1448 |
$this->Html->addCrumb('First', '#first');
|
|
|
1449 |
$this->Html->addCrumb('Second', '#second');
|
|
|
1450 |
|
|
|
1451 |
$result = $this->Html->getCrumbs(' - ', array('url' => '/home', 'text' => '<img src="/home.png" />', 'escape' => false));
|
|
|
1452 |
$expected = array(
|
|
|
1453 |
array('a' => array('href' => '/home')),
|
|
|
1454 |
'img' => array('src' => '/home.png'),
|
|
|
1455 |
'/a',
|
|
|
1456 |
' - ',
|
|
|
1457 |
array('a' => array('href' => '#first')),
|
|
|
1458 |
'First',
|
|
|
1459 |
'/a',
|
|
|
1460 |
' - ',
|
|
|
1461 |
array('a' => array('href' => '#second')),
|
|
|
1462 |
'Second',
|
|
|
1463 |
'/a',
|
|
|
1464 |
);
|
|
|
1465 |
$this->assertTags($result, $expected);
|
|
|
1466 |
}
|
|
|
1467 |
|
|
|
1468 |
/**
|
|
|
1469 |
* testNestedList method
|
|
|
1470 |
*
|
|
|
1471 |
* @return void
|
|
|
1472 |
*/
|
|
|
1473 |
public function testNestedList() {
|
|
|
1474 |
$list = array(
|
|
|
1475 |
'Item 1',
|
|
|
1476 |
'Item 2' => array(
|
|
|
1477 |
'Item 2.1'
|
|
|
1478 |
),
|
|
|
1479 |
'Item 3',
|
|
|
1480 |
'Item 4' => array(
|
|
|
1481 |
'Item 4.1',
|
|
|
1482 |
'Item 4.2',
|
|
|
1483 |
'Item 4.3' => array(
|
|
|
1484 |
'Item 4.3.1',
|
|
|
1485 |
'Item 4.3.2'
|
|
|
1486 |
)
|
|
|
1487 |
),
|
|
|
1488 |
'Item 5' => array(
|
|
|
1489 |
'Item 5.1',
|
|
|
1490 |
'Item 5.2'
|
|
|
1491 |
)
|
|
|
1492 |
);
|
|
|
1493 |
|
|
|
1494 |
$result = $this->Html->nestedList($list);
|
|
|
1495 |
$expected = array(
|
|
|
1496 |
'<ul',
|
|
|
1497 |
'<li', 'Item 1', '/li',
|
|
|
1498 |
'<li', 'Item 2',
|
|
|
1499 |
'<ul', '<li', 'Item 2.1', '/li', '/ul',
|
|
|
1500 |
'/li',
|
|
|
1501 |
'<li', 'Item 3', '/li',
|
|
|
1502 |
'<li', 'Item 4',
|
|
|
1503 |
'<ul',
|
|
|
1504 |
'<li', 'Item 4.1', '/li',
|
|
|
1505 |
'<li', 'Item 4.2', '/li',
|
|
|
1506 |
'<li', 'Item 4.3',
|
|
|
1507 |
'<ul',
|
|
|
1508 |
'<li', 'Item 4.3.1', '/li',
|
|
|
1509 |
'<li', 'Item 4.3.2', '/li',
|
|
|
1510 |
'/ul',
|
|
|
1511 |
'/li',
|
|
|
1512 |
'/ul',
|
|
|
1513 |
'/li',
|
|
|
1514 |
'<li', 'Item 5',
|
|
|
1515 |
'<ul',
|
|
|
1516 |
'<li', 'Item 5.1', '/li',
|
|
|
1517 |
'<li', 'Item 5.2', '/li',
|
|
|
1518 |
'/ul',
|
|
|
1519 |
'/li',
|
|
|
1520 |
'/ul'
|
|
|
1521 |
);
|
|
|
1522 |
$this->assertTags($result, $expected);
|
|
|
1523 |
|
|
|
1524 |
$result = $this->Html->nestedList($list, null);
|
|
|
1525 |
$this->assertTags($result, $expected);
|
|
|
1526 |
|
|
|
1527 |
$result = $this->Html->nestedList($list, array(), array(), 'ol');
|
|
|
1528 |
$expected = array(
|
|
|
1529 |
'<ol',
|
|
|
1530 |
'<li', 'Item 1', '/li',
|
|
|
1531 |
'<li', 'Item 2',
|
|
|
1532 |
'<ol', '<li', 'Item 2.1', '/li', '/ol',
|
|
|
1533 |
'/li',
|
|
|
1534 |
'<li', 'Item 3', '/li',
|
|
|
1535 |
'<li', 'Item 4',
|
|
|
1536 |
'<ol',
|
|
|
1537 |
'<li', 'Item 4.1', '/li',
|
|
|
1538 |
'<li', 'Item 4.2', '/li',
|
|
|
1539 |
'<li', 'Item 4.3',
|
|
|
1540 |
'<ol',
|
|
|
1541 |
'<li', 'Item 4.3.1', '/li',
|
|
|
1542 |
'<li', 'Item 4.3.2', '/li',
|
|
|
1543 |
'/ol',
|
|
|
1544 |
'/li',
|
|
|
1545 |
'/ol',
|
|
|
1546 |
'/li',
|
|
|
1547 |
'<li', 'Item 5',
|
|
|
1548 |
'<ol',
|
|
|
1549 |
'<li', 'Item 5.1', '/li',
|
|
|
1550 |
'<li', 'Item 5.2', '/li',
|
|
|
1551 |
'/ol',
|
|
|
1552 |
'/li',
|
|
|
1553 |
'/ol'
|
|
|
1554 |
);
|
|
|
1555 |
$this->assertTags($result, $expected);
|
|
|
1556 |
|
|
|
1557 |
$result = $this->Html->nestedList($list, 'ol');
|
|
|
1558 |
$this->assertTags($result, $expected);
|
|
|
1559 |
|
|
|
1560 |
$result = $this->Html->nestedList($list, array('class' => 'list'));
|
|
|
1561 |
$expected = array(
|
|
|
1562 |
array('ul' => array('class' => 'list')),
|
|
|
1563 |
'<li', 'Item 1', '/li',
|
|
|
1564 |
'<li', 'Item 2',
|
|
|
1565 |
array('ul' => array('class' => 'list')), '<li', 'Item 2.1', '/li', '/ul',
|
|
|
1566 |
'/li',
|
|
|
1567 |
'<li', 'Item 3', '/li',
|
|
|
1568 |
'<li', 'Item 4',
|
|
|
1569 |
array('ul' => array('class' => 'list')),
|
|
|
1570 |
'<li', 'Item 4.1', '/li',
|
|
|
1571 |
'<li', 'Item 4.2', '/li',
|
|
|
1572 |
'<li', 'Item 4.3',
|
|
|
1573 |
array('ul' => array('class' => 'list')),
|
|
|
1574 |
'<li', 'Item 4.3.1', '/li',
|
|
|
1575 |
'<li', 'Item 4.3.2', '/li',
|
|
|
1576 |
'/ul',
|
|
|
1577 |
'/li',
|
|
|
1578 |
'/ul',
|
|
|
1579 |
'/li',
|
|
|
1580 |
'<li', 'Item 5',
|
|
|
1581 |
array('ul' => array('class' => 'list')),
|
|
|
1582 |
'<li', 'Item 5.1', '/li',
|
|
|
1583 |
'<li', 'Item 5.2', '/li',
|
|
|
1584 |
'/ul',
|
|
|
1585 |
'/li',
|
|
|
1586 |
'/ul'
|
|
|
1587 |
);
|
|
|
1588 |
$this->assertTags($result, $expected);
|
|
|
1589 |
|
|
|
1590 |
$result = $this->Html->nestedList($list, array(), array('class' => 'item'));
|
|
|
1591 |
$expected = array(
|
|
|
1592 |
'<ul',
|
|
|
1593 |
array('li' => array('class' => 'item')), 'Item 1', '/li',
|
|
|
1594 |
array('li' => array('class' => 'item')), 'Item 2',
|
|
|
1595 |
'<ul', array('li' => array('class' => 'item')), 'Item 2.1', '/li', '/ul',
|
|
|
1596 |
'/li',
|
|
|
1597 |
array('li' => array('class' => 'item')), 'Item 3', '/li',
|
|
|
1598 |
array('li' => array('class' => 'item')), 'Item 4',
|
|
|
1599 |
'<ul',
|
|
|
1600 |
array('li' => array('class' => 'item')), 'Item 4.1', '/li',
|
|
|
1601 |
array('li' => array('class' => 'item')), 'Item 4.2', '/li',
|
|
|
1602 |
array('li' => array('class' => 'item')), 'Item 4.3',
|
|
|
1603 |
'<ul',
|
|
|
1604 |
array('li' => array('class' => 'item')), 'Item 4.3.1', '/li',
|
|
|
1605 |
array('li' => array('class' => 'item')), 'Item 4.3.2', '/li',
|
|
|
1606 |
'/ul',
|
|
|
1607 |
'/li',
|
|
|
1608 |
'/ul',
|
|
|
1609 |
'/li',
|
|
|
1610 |
array('li' => array('class' => 'item')), 'Item 5',
|
|
|
1611 |
'<ul',
|
|
|
1612 |
array('li' => array('class' => 'item')), 'Item 5.1', '/li',
|
|
|
1613 |
array('li' => array('class' => 'item')), 'Item 5.2', '/li',
|
|
|
1614 |
'/ul',
|
|
|
1615 |
'/li',
|
|
|
1616 |
'/ul'
|
|
|
1617 |
);
|
|
|
1618 |
$this->assertTags($result, $expected);
|
|
|
1619 |
|
|
|
1620 |
$result = $this->Html->nestedList($list, array(), array('even' => 'even', 'odd' => 'odd'));
|
|
|
1621 |
$expected = array(
|
|
|
1622 |
'<ul',
|
|
|
1623 |
array('li' => array('class' => 'odd')), 'Item 1', '/li',
|
|
|
1624 |
array('li' => array('class' => 'even')), 'Item 2',
|
|
|
1625 |
'<ul', array('li' => array('class' => 'odd')), 'Item 2.1', '/li', '/ul',
|
|
|
1626 |
'/li',
|
|
|
1627 |
array('li' => array('class' => 'odd')), 'Item 3', '/li',
|
|
|
1628 |
array('li' => array('class' => 'even')), 'Item 4',
|
|
|
1629 |
'<ul',
|
|
|
1630 |
array('li' => array('class' => 'odd')), 'Item 4.1', '/li',
|
|
|
1631 |
array('li' => array('class' => 'even')), 'Item 4.2', '/li',
|
|
|
1632 |
array('li' => array('class' => 'odd')), 'Item 4.3',
|
|
|
1633 |
'<ul',
|
|
|
1634 |
array('li' => array('class' => 'odd')), 'Item 4.3.1', '/li',
|
|
|
1635 |
array('li' => array('class' => 'even')), 'Item 4.3.2', '/li',
|
|
|
1636 |
'/ul',
|
|
|
1637 |
'/li',
|
|
|
1638 |
'/ul',
|
|
|
1639 |
'/li',
|
|
|
1640 |
array('li' => array('class' => 'odd')), 'Item 5',
|
|
|
1641 |
'<ul',
|
|
|
1642 |
array('li' => array('class' => 'odd')), 'Item 5.1', '/li',
|
|
|
1643 |
array('li' => array('class' => 'even')), 'Item 5.2', '/li',
|
|
|
1644 |
'/ul',
|
|
|
1645 |
'/li',
|
|
|
1646 |
'/ul'
|
|
|
1647 |
);
|
|
|
1648 |
$this->assertTags($result, $expected);
|
|
|
1649 |
|
|
|
1650 |
$result = $this->Html->nestedList($list, array('class' => 'list'), array('class' => 'item'));
|
|
|
1651 |
$expected = array(
|
|
|
1652 |
array('ul' => array('class' => 'list')),
|
|
|
1653 |
array('li' => array('class' => 'item')), 'Item 1', '/li',
|
|
|
1654 |
array('li' => array('class' => 'item')), 'Item 2',
|
|
|
1655 |
array('ul' => array('class' => 'list')), array('li' => array('class' => 'item')), 'Item 2.1', '/li', '/ul',
|
|
|
1656 |
'/li',
|
|
|
1657 |
array('li' => array('class' => 'item')), 'Item 3', '/li',
|
|
|
1658 |
array('li' => array('class' => 'item')), 'Item 4',
|
|
|
1659 |
array('ul' => array('class' => 'list')),
|
|
|
1660 |
array('li' => array('class' => 'item')), 'Item 4.1', '/li',
|
|
|
1661 |
array('li' => array('class' => 'item')), 'Item 4.2', '/li',
|
|
|
1662 |
array('li' => array('class' => 'item')), 'Item 4.3',
|
|
|
1663 |
array('ul' => array('class' => 'list')),
|
|
|
1664 |
array('li' => array('class' => 'item')), 'Item 4.3.1', '/li',
|
|
|
1665 |
array('li' => array('class' => 'item')), 'Item 4.3.2', '/li',
|
|
|
1666 |
'/ul',
|
|
|
1667 |
'/li',
|
|
|
1668 |
'/ul',
|
|
|
1669 |
'/li',
|
|
|
1670 |
array('li' => array('class' => 'item')), 'Item 5',
|
|
|
1671 |
array('ul' => array('class' => 'list')),
|
|
|
1672 |
array('li' => array('class' => 'item')), 'Item 5.1', '/li',
|
|
|
1673 |
array('li' => array('class' => 'item')), 'Item 5.2', '/li',
|
|
|
1674 |
'/ul',
|
|
|
1675 |
'/li',
|
|
|
1676 |
'/ul'
|
|
|
1677 |
);
|
|
|
1678 |
$this->assertTags($result, $expected);
|
|
|
1679 |
}
|
|
|
1680 |
|
|
|
1681 |
/**
|
|
|
1682 |
* testMeta method
|
|
|
1683 |
*
|
|
|
1684 |
* @return void
|
|
|
1685 |
*/
|
|
|
1686 |
public function testMeta() {
|
|
|
1687 |
$result = $this->Html->meta('this is an rss feed', array('controller' => 'posts', 'ext' => 'rss'));
|
|
|
1688 |
$this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed')));
|
|
|
1689 |
|
|
|
1690 |
$result = $this->Html->meta('rss', array('controller' => 'posts', 'ext' => 'rss'), array('title' => 'this is an rss feed'));
|
|
|
1691 |
$this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed')));
|
|
|
1692 |
|
|
|
1693 |
$result = $this->Html->meta('atom', array('controller' => 'posts', 'ext' => 'xml'));
|
|
|
1694 |
$this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xml/', 'type' => 'application/atom+xml', 'title' => 'atom')));
|
|
|
1695 |
|
|
|
1696 |
$result = $this->Html->meta('non-existing');
|
|
|
1697 |
$this->assertTags($result, array('<meta'));
|
|
|
1698 |
|
|
|
1699 |
$result = $this->Html->meta('non-existing', '/posts.xpp');
|
|
|
1700 |
$this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xpp/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'non-existing')));
|
|
|
1701 |
|
|
|
1702 |
$result = $this->Html->meta('non-existing', '/posts.xpp', array('type' => 'atom'));
|
|
|
1703 |
$this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xpp/', 'type' => 'application/atom+xml', 'title' => 'non-existing')));
|
|
|
1704 |
|
|
|
1705 |
$result = $this->Html->meta('atom', array('controller' => 'posts', 'ext' => 'xml'), array('link' => '/articles.rss'));
|
|
|
1706 |
$this->assertTags($result, array('link' => array('href' => 'preg:/.*\/articles\.rss/', 'type' => 'application/atom+xml', 'title' => 'atom')));
|
|
|
1707 |
|
|
|
1708 |
$result = $this->Html->meta(array('link' => 'favicon.ico', 'rel' => 'icon'));
|
|
|
1709 |
$expected = array(
|
|
|
1710 |
'link' => array('href' => 'preg:/.*favicon\.ico/', 'rel' => 'icon'),
|
|
|
1711 |
array('link' => array('href' => 'preg:/.*favicon\.ico/', 'rel' => 'shortcut icon'))
|
|
|
1712 |
);
|
|
|
1713 |
$this->assertTags($result, $expected);
|
|
|
1714 |
|
|
|
1715 |
$result = $this->Html->meta('keywords', 'these, are, some, meta, keywords');
|
|
|
1716 |
$this->assertTags($result, array('meta' => array('name' => 'keywords', 'content' => 'these, are, some, meta, keywords')));
|
|
|
1717 |
$this->assertRegExp('/\s+\/>$/', $result);
|
|
|
1718 |
|
|
|
1719 |
$result = $this->Html->meta('description', 'this is the meta description');
|
|
|
1720 |
$this->assertTags($result, array('meta' => array('name' => 'description', 'content' => 'this is the meta description')));
|
|
|
1721 |
|
|
|
1722 |
$result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'));
|
|
|
1723 |
$this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));
|
|
|
1724 |
}
|
|
|
1725 |
|
|
|
1726 |
/**
|
|
|
1727 |
* Test generating favicon's with meta()
|
|
|
1728 |
*
|
|
|
1729 |
* @return void
|
|
|
1730 |
*/
|
|
|
1731 |
public function testMetaIcon() {
|
|
|
1732 |
$result = $this->Html->meta('icon', 'favicon.ico');
|
|
|
1733 |
$expected = array(
|
|
|
1734 |
'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
|
|
|
1735 |
array('link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
|
|
|
1736 |
);
|
|
|
1737 |
$this->assertTags($result, $expected);
|
|
|
1738 |
|
|
|
1739 |
$result = $this->Html->meta('icon');
|
|
|
1740 |
$expected = array(
|
|
|
1741 |
'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
|
|
|
1742 |
array('link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
|
|
|
1743 |
);
|
|
|
1744 |
$this->assertTags($result, $expected);
|
|
|
1745 |
|
|
|
1746 |
$result = $this->Html->meta('icon', '/favicon.png?one=two&three=four');
|
|
|
1747 |
$url = '/favicon.png?one=two&three=four';
|
|
|
1748 |
$expected = array(
|
|
|
1749 |
'link' => array(
|
|
|
1750 |
'href' => $url,
|
|
|
1751 |
'type' => 'image/x-icon',
|
|
|
1752 |
'rel' => 'icon'
|
|
|
1753 |
),
|
|
|
1754 |
array(
|
|
|
1755 |
'link' => array(
|
|
|
1756 |
'href' => $url,
|
|
|
1757 |
'type' => 'image/x-icon',
|
|
|
1758 |
'rel' => 'shortcut icon'
|
|
|
1759 |
)
|
|
|
1760 |
)
|
|
|
1761 |
);
|
|
|
1762 |
$this->assertTags($result, $expected);
|
|
|
1763 |
|
|
|
1764 |
$this->Html->request->webroot = '/testing/';
|
|
|
1765 |
$result = $this->Html->meta('icon');
|
|
|
1766 |
$expected = array(
|
|
|
1767 |
'link' => array('href' => '/testing/favicon.ico', 'type' => 'image/x-icon', 'rel' => 'icon'),
|
|
|
1768 |
array('link' => array('href' => '/testing/favicon.ico', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
|
|
|
1769 |
);
|
|
|
1770 |
$this->assertTags($result, $expected);
|
|
|
1771 |
}
|
|
|
1772 |
|
|
|
1773 |
/**
|
|
|
1774 |
* Test the inline and block options for meta()
|
|
|
1775 |
*
|
|
|
1776 |
* @return void
|
|
|
1777 |
*/
|
|
|
1778 |
public function testMetaWithBlocks() {
|
|
|
1779 |
$this->View->expects($this->at(0))
|
|
|
1780 |
->method('append')
|
|
|
1781 |
->with('meta', $this->stringContains('ROBOTS'));
|
|
|
1782 |
|
|
|
1783 |
$this->View->expects($this->at(1))
|
|
|
1784 |
->method('append')
|
|
|
1785 |
->with('metaTags', $this->stringContains('favicon.ico'));
|
|
|
1786 |
|
|
|
1787 |
$result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'), null, array('inline' => false));
|
|
|
1788 |
$this->assertNull($result);
|
|
|
1789 |
|
|
|
1790 |
$result = $this->Html->meta('icon', 'favicon.ico', array('block' => 'metaTags'));
|
|
|
1791 |
$this->assertNull($result);
|
|
|
1792 |
}
|
|
|
1793 |
|
|
|
1794 |
/**
|
|
|
1795 |
* testTableHeaders method
|
|
|
1796 |
*
|
|
|
1797 |
* @return void
|
|
|
1798 |
*/
|
|
|
1799 |
public function testTableHeaders() {
|
|
|
1800 |
$result = $this->Html->tableHeaders(array('ID', 'Name', 'Date'));
|
|
|
1801 |
$expected = array('<tr', '<th', 'ID', '/th', '<th', 'Name', '/th', '<th', 'Date', '/th', '/tr');
|
|
|
1802 |
$this->assertTags($result, $expected);
|
|
|
1803 |
|
|
|
1804 |
$result = $this->Html->tableHeaders(array('ID', array('Name' => array('class' => 'highlight')), 'Date'));
|
|
|
1805 |
$expected = array('<tr', '<th', 'ID', '/th', '<th class="highlight"', 'Name', '/th', '<th', 'Date', '/th', '/tr');
|
|
|
1806 |
$this->assertTags($result, $expected);
|
|
|
1807 |
|
|
|
1808 |
$result = $this->Html->tableHeaders(array('ID', array('Name' => array('class' => 'highlight', 'width' => '120px')), 'Date'));
|
|
|
1809 |
$expected = array('<tr', '<th', 'ID', '/th', '<th class="highlight" width="120px"', 'Name', '/th', '<th', 'Date', '/th', '/tr');
|
|
|
1810 |
$this->assertTags($result, $expected);
|
|
|
1811 |
|
|
|
1812 |
$result = $this->Html->tableHeaders(array('ID', array('Name' => array()), 'Date'));
|
|
|
1813 |
$expected = array('<tr', '<th', 'ID', '/th', '<th', 'Name', '/th', '<th', 'Date', '/th', '/tr');
|
|
|
1814 |
$this->assertTags($result, $expected);
|
|
|
1815 |
}
|
|
|
1816 |
|
|
|
1817 |
/**
|
|
|
1818 |
* testTableCells method
|
|
|
1819 |
*
|
|
|
1820 |
* @return void
|
|
|
1821 |
*/
|
|
|
1822 |
public function testTableCells() {
|
|
|
1823 |
$tr = array(
|
|
|
1824 |
'td content 1',
|
|
|
1825 |
array('td content 2', array("width" => "100px")),
|
|
|
1826 |
array('td content 3', "width=100px")
|
|
|
1827 |
);
|
|
|
1828 |
$result = $this->Html->tableCells($tr);
|
|
|
1829 |
$expected = array(
|
|
|
1830 |
'<tr',
|
|
|
1831 |
'<td', 'td content 1', '/td',
|
|
|
1832 |
array('td' => array('width' => '100px')), 'td content 2', '/td',
|
|
|
1833 |
array('td' => array('width' => 'preg:/100px/')), 'td content 3', '/td',
|
|
|
1834 |
'/tr'
|
|
|
1835 |
);
|
|
|
1836 |
$this->assertTags($result, $expected);
|
|
|
1837 |
|
|
|
1838 |
$tr = array('td content 1', 'td content 2', 'td content 3');
|
|
|
1839 |
$result = $this->Html->tableCells($tr, null, null, true);
|
|
|
1840 |
$expected = array(
|
|
|
1841 |
'<tr',
|
|
|
1842 |
array('td' => array('class' => 'column-1')), 'td content 1', '/td',
|
|
|
1843 |
array('td' => array('class' => 'column-2')), 'td content 2', '/td',
|
|
|
1844 |
array('td' => array('class' => 'column-3')), 'td content 3', '/td',
|
|
|
1845 |
'/tr'
|
|
|
1846 |
);
|
|
|
1847 |
$this->assertTags($result, $expected);
|
|
|
1848 |
|
|
|
1849 |
$tr = array('td content 1', 'td content 2', 'td content 3');
|
|
|
1850 |
$result = $this->Html->tableCells($tr, true);
|
|
|
1851 |
$expected = array(
|
|
|
1852 |
'<tr',
|
|
|
1853 |
array('td' => array('class' => 'column-1')), 'td content 1', '/td',
|
|
|
1854 |
array('td' => array('class' => 'column-2')), 'td content 2', '/td',
|
|
|
1855 |
array('td' => array('class' => 'column-3')), 'td content 3', '/td',
|
|
|
1856 |
'/tr'
|
|
|
1857 |
);
|
|
|
1858 |
$this->assertTags($result, $expected);
|
|
|
1859 |
|
|
|
1860 |
$tr = array(
|
|
|
1861 |
array('td content 1', 'td content 2', 'td content 3'),
|
|
|
1862 |
array('td content 1', 'td content 2', 'td content 3'),
|
|
|
1863 |
array('td content 1', 'td content 2', 'td content 3')
|
|
|
1864 |
);
|
|
|
1865 |
$result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
|
|
|
1866 |
$expected = "<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
|
|
|
1867 |
$this->assertEquals($expected, $result);
|
|
|
1868 |
|
|
|
1869 |
$tr = array(
|
|
|
1870 |
array('td content 1', 'td content 2', 'td content 3'),
|
|
|
1871 |
array('td content 1', 'td content 2', 'td content 3'),
|
|
|
1872 |
array('td content 1', 'td content 2', 'td content 3'),
|
|
|
1873 |
array('td content 1', 'td content 2', 'td content 3')
|
|
|
1874 |
);
|
|
|
1875 |
$result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
|
|
|
1876 |
$expected = "<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
|
|
|
1877 |
$this->assertEquals($expected, $result);
|
|
|
1878 |
|
|
|
1879 |
$tr = array(
|
|
|
1880 |
array('td content 1', 'td content 2', 'td content 3'),
|
|
|
1881 |
array('td content 1', 'td content 2', 'td content 3'),
|
|
|
1882 |
array('td content 1', 'td content 2', 'td content 3')
|
|
|
1883 |
);
|
|
|
1884 |
$this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
|
|
|
1885 |
$result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'), false, false);
|
|
|
1886 |
$expected = "<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
|
|
|
1887 |
$this->assertEquals($expected, $result);
|
|
|
1888 |
}
|
|
|
1889 |
|
|
|
1890 |
/**
|
|
|
1891 |
* testTag method
|
|
|
1892 |
*
|
|
|
1893 |
* @return void
|
|
|
1894 |
*/
|
|
|
1895 |
public function testTag() {
|
|
|
1896 |
$result = $this->Html->tag('div');
|
|
|
1897 |
$this->assertTags($result, '<div');
|
|
|
1898 |
|
|
|
1899 |
$result = $this->Html->tag('div', 'text');
|
|
|
1900 |
$this->assertTags($result, '<div', 'text', '/div');
|
|
|
1901 |
|
|
|
1902 |
$result = $this->Html->tag('div', '<text>', array('class' => 'class-name', 'escape' => true));
|
|
|
1903 |
$this->assertTags($result, array('div' => array('class' => 'class-name'), '<text>', '/div'));
|
|
|
1904 |
|
|
|
1905 |
$result = $this->Html->tag(false, '<em>stuff</em>');
|
|
|
1906 |
$this->assertEquals('<em>stuff</em>', $result);
|
|
|
1907 |
|
|
|
1908 |
$result = $this->Html->tag(null, '<em>stuff</em>');
|
|
|
1909 |
$this->assertEquals('<em>stuff</em>', $result);
|
|
|
1910 |
|
|
|
1911 |
$result = $this->Html->tag('', '<em>stuff</em>');
|
|
|
1912 |
$this->assertEquals('<em>stuff</em>', $result);
|
|
|
1913 |
}
|
|
|
1914 |
|
|
|
1915 |
/**
|
|
|
1916 |
* testUseTag method
|
|
|
1917 |
*
|
|
|
1918 |
* @return void
|
|
|
1919 |
*/
|
|
|
1920 |
public function testUseTag() {
|
|
|
1921 |
$result = $this->Html->useTag('unknowntag');
|
|
|
1922 |
$this->assertEquals('', $result);
|
|
|
1923 |
|
|
|
1924 |
$result = $this->Html->useTag('formend');
|
|
|
1925 |
$this->assertTags($result, '/form');
|
|
|
1926 |
|
|
|
1927 |
$result = $this->Html->useTag('form', 'url', ' test');
|
|
|
1928 |
$this->assertEquals('<form action="url" test>', $result);
|
|
|
1929 |
|
|
|
1930 |
$result = $this->Html->useTag('form', 'example.com', array('test' => 'ok'));
|
|
|
1931 |
$this->assertTags($result, array('form' => array('test' => 'ok', 'action' => 'example.com')));
|
|
|
1932 |
}
|
|
|
1933 |
|
|
|
1934 |
/**
|
|
|
1935 |
* testDiv method
|
|
|
1936 |
*
|
|
|
1937 |
* @return void
|
|
|
1938 |
*/
|
|
|
1939 |
public function testDiv() {
|
|
|
1940 |
$result = $this->Html->div('class-name');
|
|
|
1941 |
$this->assertTags($result, array('div' => array('class' => 'class-name')));
|
|
|
1942 |
|
|
|
1943 |
$result = $this->Html->div('class-name', 'text');
|
|
|
1944 |
$this->assertTags($result, array('div' => array('class' => 'class-name'), 'text', '/div'));
|
|
|
1945 |
|
|
|
1946 |
$result = $this->Html->div('class-name', '<text>', array('escape' => true));
|
|
|
1947 |
$this->assertTags($result, array('div' => array('class' => 'class-name'), '<text>', '/div'));
|
|
|
1948 |
}
|
|
|
1949 |
|
|
|
1950 |
/**
|
|
|
1951 |
* testPara method
|
|
|
1952 |
*
|
|
|
1953 |
* @return void
|
|
|
1954 |
*/
|
|
|
1955 |
public function testPara() {
|
|
|
1956 |
$result = $this->Html->para('class-name', '');
|
|
|
1957 |
$this->assertTags($result, array('p' => array('class' => 'class-name')));
|
|
|
1958 |
|
|
|
1959 |
$result = $this->Html->para('class-name', 'text');
|
|
|
1960 |
$this->assertTags($result, array('p' => array('class' => 'class-name'), 'text', '/p'));
|
|
|
1961 |
|
|
|
1962 |
$result = $this->Html->para('class-name', '<text>', array('escape' => true));
|
|
|
1963 |
$this->assertTags($result, array('p' => array('class' => 'class-name'), '<text>', '/p'));
|
|
|
1964 |
}
|
|
|
1965 |
|
|
|
1966 |
/**
|
|
|
1967 |
* testMedia method
|
|
|
1968 |
*
|
|
|
1969 |
* @return void
|
|
|
1970 |
*/
|
|
|
1971 |
public function testMedia() {
|
|
|
1972 |
$result = $this->Html->media('video.webm');
|
|
|
1973 |
$expected = array('video' => array('src' => 'files/video.webm'), '/video');
|
|
|
1974 |
$this->assertTags($result, $expected);
|
|
|
1975 |
|
|
|
1976 |
$result = $this->Html->media('video.webm', array(
|
|
|
1977 |
'text' => 'Your browser does not support the HTML5 Video element.'
|
|
|
1978 |
));
|
|
|
1979 |
$expected = array('video' => array('src' => 'files/video.webm'), 'Your browser does not support the HTML5 Video element.', '/video');
|
|
|
1980 |
$this->assertTags($result, $expected);
|
|
|
1981 |
|
|
|
1982 |
$result = $this->Html->media('video.webm', array('autoload', 'muted' => 'muted'));
|
|
|
1983 |
$expected = array(
|
|
|
1984 |
'video' => array(
|
|
|
1985 |
'src' => 'files/video.webm',
|
|
|
1986 |
'autoload' => 'autoload',
|
|
|
1987 |
'muted' => 'muted'
|
|
|
1988 |
),
|
|
|
1989 |
'/video'
|
|
|
1990 |
);
|
|
|
1991 |
$this->assertTags($result, $expected);
|
|
|
1992 |
|
|
|
1993 |
$result = $this->Html->media(
|
|
|
1994 |
array('video.webm', array('src' => 'video.ogv', 'type' => "video/ogg; codecs='theora, vorbis'")),
|
|
|
1995 |
array('pathPrefix' => 'videos/', 'poster' => 'poster.jpg', 'text' => 'Your browser does not support the HTML5 Video element.')
|
|
|
1996 |
);
|
|
|
1997 |
$expected = array(
|
|
|
1998 |
'video' => array('poster' => Configure::read('App.imageBaseUrl') . 'poster.jpg'),
|
|
|
1999 |
array('source' => array('src' => 'videos/video.webm', 'type' => 'video/webm')),
|
|
|
2000 |
array('source' => array('src' => 'videos/video.ogv', 'type' => 'video/ogg; codecs='theora, vorbis'')),
|
|
|
2001 |
'Your browser does not support the HTML5 Video element.',
|
|
|
2002 |
'/video'
|
|
|
2003 |
);
|
|
|
2004 |
$this->assertTags($result, $expected);
|
|
|
2005 |
|
|
|
2006 |
$result = $this->Html->media('video.ogv', array('tag' => 'video'));
|
|
|
2007 |
$expected = array('video' => array('src' => 'files/video.ogv'), '/video');
|
|
|
2008 |
$this->assertTags($result, $expected);
|
|
|
2009 |
|
|
|
2010 |
$result = $this->Html->media('audio.mp3');
|
|
|
2011 |
$expected = array('audio' => array('src' => 'files/audio.mp3'), '/audio');
|
|
|
2012 |
$this->assertTags($result, $expected);
|
|
|
2013 |
|
|
|
2014 |
$result = $this->Html->media(
|
|
|
2015 |
array(array('src' => 'video.mov', 'type' => 'video/mp4'), 'video.webm')
|
|
|
2016 |
);
|
|
|
2017 |
$expected = array(
|
|
|
2018 |
'<video',
|
|
|
2019 |
array('source' => array('src' => 'files/video.mov', 'type' => 'video/mp4')),
|
|
|
2020 |
array('source' => array('src' => 'files/video.webm', 'type' => 'video/webm')),
|
|
|
2021 |
'/video'
|
|
|
2022 |
);
|
|
|
2023 |
$this->assertTags($result, $expected);
|
|
|
2024 |
|
|
|
2025 |
$result = $this->Html->media(null, array('src' => 'video.webm'));
|
|
|
2026 |
$expected = array(
|
|
|
2027 |
'video' => array('src' => 'files/video.webm'),
|
|
|
2028 |
'/video'
|
|
|
2029 |
);
|
|
|
2030 |
$this->assertTags($result, $expected);
|
|
|
2031 |
}
|
|
|
2032 |
|
|
|
2033 |
/**
|
|
|
2034 |
* testCrumbList method
|
|
|
2035 |
*
|
|
|
2036 |
* @return void
|
|
|
2037 |
*/
|
|
|
2038 |
public function testCrumbList() {
|
|
|
2039 |
$this->assertNull($this->Html->getCrumbList());
|
|
|
2040 |
|
|
|
2041 |
$this->Html->addCrumb('Home', '/', array('class' => 'home'));
|
|
|
2042 |
$this->Html->addCrumb('Some page', '/some_page');
|
|
|
2043 |
$this->Html->addCrumb('Another page');
|
|
|
2044 |
$result = $this->Html->getCrumbList(
|
|
|
2045 |
array('class' => 'breadcrumbs')
|
|
|
2046 |
);
|
|
|
2047 |
$this->assertTags(
|
|
|
2048 |
$result,
|
|
|
2049 |
array(
|
|
|
2050 |
array('ul' => array('class' => 'breadcrumbs')),
|
|
|
2051 |
array('li' => array('class' => 'first')),
|
|
|
2052 |
array('a' => array('class' => 'home', 'href' => '/')), 'Home', '/a',
|
|
|
2053 |
'/li',
|
|
|
2054 |
'<li',
|
|
|
2055 |
array('a' => array('href' => '/some_page')), 'Some page', '/a',
|
|
|
2056 |
'/li',
|
|
|
2057 |
array('li' => array('class' => 'last')),
|
|
|
2058 |
'Another page',
|
|
|
2059 |
'/li',
|
|
|
2060 |
'/ul'
|
|
|
2061 |
)
|
|
|
2062 |
);
|
|
|
2063 |
}
|
|
|
2064 |
|
|
|
2065 |
/**
|
|
|
2066 |
* Test getCrumbList startText
|
|
|
2067 |
*
|
|
|
2068 |
* @return void
|
|
|
2069 |
*/
|
|
|
2070 |
public function testCrumbListFirstLink() {
|
|
|
2071 |
$this->Html->addCrumb('First', '#first');
|
|
|
2072 |
$this->Html->addCrumb('Second', '#second');
|
|
|
2073 |
|
|
|
2074 |
$result = $this->Html->getCrumbList(null, 'Home');
|
|
|
2075 |
$this->assertTags(
|
|
|
2076 |
$result,
|
|
|
2077 |
array(
|
|
|
2078 |
'<ul',
|
|
|
2079 |
array('li' => array('class' => 'first')),
|
|
|
2080 |
array('a' => array('href' => '/')), 'Home', '/a',
|
|
|
2081 |
'/li',
|
|
|
2082 |
'<li',
|
|
|
2083 |
array('a' => array('href' => '#first')), 'First', '/a',
|
|
|
2084 |
'/li',
|
|
|
2085 |
array('li' => array('class' => 'last')),
|
|
|
2086 |
array('a' => array('href' => '#second')), 'Second', '/a',
|
|
|
2087 |
'/li',
|
|
|
2088 |
'/ul'
|
|
|
2089 |
)
|
|
|
2090 |
);
|
|
|
2091 |
|
|
|
2092 |
$result = $this->Html->getCrumbList(null, array('url' => '/home', 'text' => '<img src="/home.png" />', 'escape' => false));
|
|
|
2093 |
$this->assertTags(
|
|
|
2094 |
$result,
|
|
|
2095 |
array(
|
|
|
2096 |
'<ul',
|
|
|
2097 |
array('li' => array('class' => 'first')),
|
|
|
2098 |
array('a' => array('href' => '/home')), 'img' => array('src' => '/home.png'), '/a',
|
|
|
2099 |
'/li',
|
|
|
2100 |
'<li',
|
|
|
2101 |
array('a' => array('href' => '#first')), 'First', '/a',
|
|
|
2102 |
'/li',
|
|
|
2103 |
array('li' => array('class' => 'last')),
|
|
|
2104 |
array('a' => array('href' => '#second')), 'Second', '/a',
|
|
|
2105 |
'/li',
|
|
|
2106 |
'/ul'
|
|
|
2107 |
)
|
|
|
2108 |
);
|
|
|
2109 |
}
|
|
|
2110 |
|
|
|
2111 |
/**
|
|
|
2112 |
* test getCrumbList() in Twitter Bootstrap style.
|
|
|
2113 |
*
|
|
|
2114 |
* @return void
|
|
|
2115 |
*/
|
|
|
2116 |
public function testCrumbListBootstrapStyle() {
|
|
|
2117 |
$this->Html->addCrumb('Home', '/', array('class' => 'home'));
|
|
|
2118 |
$this->Html->addCrumb('Library', '/lib');
|
|
|
2119 |
$this->Html->addCrumb('Data');
|
|
|
2120 |
$result = $this->Html->getCrumbList(array(
|
|
|
2121 |
'class' => 'breadcrumb',
|
|
|
2122 |
'separator' => '<span class="divider">-</span>',
|
|
|
2123 |
'firstClass' => false,
|
|
|
2124 |
'lastClass' => 'active'
|
|
|
2125 |
));
|
|
|
2126 |
$this->assertTags(
|
|
|
2127 |
$result,
|
|
|
2128 |
array(
|
|
|
2129 |
array('ul' => array('class' => 'breadcrumb')),
|
|
|
2130 |
'<li',
|
|
|
2131 |
array('a' => array('class' => 'home', 'href' => '/')), 'Home', '/a',
|
|
|
2132 |
array('span' => array('class' => 'divider')), '-', '/span',
|
|
|
2133 |
'/li',
|
|
|
2134 |
'<li',
|
|
|
2135 |
array('a' => array('href' => '/lib')), 'Library', '/a',
|
|
|
2136 |
array('span' => array('class' => 'divider')), '-', '/span',
|
|
|
2137 |
'/li',
|
|
|
2138 |
array('li' => array('class' => 'active')), 'Data', '/li',
|
|
|
2139 |
'/ul'
|
|
|
2140 |
)
|
|
|
2141 |
);
|
|
|
2142 |
}
|
|
|
2143 |
|
|
|
2144 |
/**
|
|
|
2145 |
* Test GetCrumbList using style of Zurb Foundation.
|
|
|
2146 |
*
|
|
|
2147 |
* @return void
|
|
|
2148 |
*/
|
|
|
2149 |
public function testCrumbListZurbStyle() {
|
|
|
2150 |
$this->Html->addCrumb('Home', '#');
|
|
|
2151 |
$this->Html->addCrumb('Features', '#');
|
|
|
2152 |
$this->Html->addCrumb('Gene Splicing', '#');
|
|
|
2153 |
$this->Html->addCrumb('Home', '#');
|
|
|
2154 |
$result = $this->Html->getCrumbList(
|
|
|
2155 |
array('class' => 'breadcrumbs', 'firstClass' => false, 'lastClass' => 'current')
|
|
|
2156 |
);
|
|
|
2157 |
$this->assertTags(
|
|
|
2158 |
$result,
|
|
|
2159 |
array(
|
|
|
2160 |
array('ul' => array('class' => 'breadcrumbs')),
|
|
|
2161 |
'<li',
|
|
|
2162 |
array('a' => array('href' => '#')), 'Home', '/a',
|
|
|
2163 |
'/li',
|
|
|
2164 |
'<li',
|
|
|
2165 |
array('a' => array('href' => '#')), 'Features', '/a',
|
|
|
2166 |
'/li',
|
|
|
2167 |
'<li',
|
|
|
2168 |
array('a' => array('href' => '#')), 'Gene Splicing', '/a',
|
|
|
2169 |
'/li',
|
|
|
2170 |
array('li' => array('class' => 'current')),
|
|
|
2171 |
array('a' => array('href' => '#')), 'Home', '/a',
|
|
|
2172 |
'/li',
|
|
|
2173 |
'/ul'
|
|
|
2174 |
), true
|
|
|
2175 |
);
|
|
|
2176 |
}
|
|
|
2177 |
|
|
|
2178 |
/**
|
|
|
2179 |
* testLoadConfig method
|
|
|
2180 |
*
|
|
|
2181 |
* @return void
|
|
|
2182 |
*/
|
|
|
2183 |
|
|
|
2184 |
public function testLoadConfig() {
|
|
|
2185 |
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS;
|
|
|
2186 |
|
|
|
2187 |
$result = $this->Html->loadConfig('htmlhelper_tags', $path);
|
|
|
2188 |
$expected = array(
|
|
|
2189 |
'tags' => array(
|
|
|
2190 |
'form' => 'start form',
|
|
|
2191 |
'formend' => 'finish form',
|
|
|
2192 |
'hiddenblock' => '<div class="hidden">%s</div>'
|
|
|
2193 |
)
|
|
|
2194 |
);
|
|
|
2195 |
$this->assertEquals($expected, $result);
|
|
|
2196 |
$tags = $this->Html->getAttribute('_tags');
|
|
|
2197 |
$this->assertEquals('start form', $tags['form']);
|
|
|
2198 |
$this->assertEquals('finish form', $tags['formend']);
|
|
|
2199 |
$this->assertEquals('</select>', $tags['selectend']);
|
|
|
2200 |
|
|
|
2201 |
$result = $this->Html->loadConfig(array('htmlhelper_minimized.ini', 'ini'), $path);
|
|
|
2202 |
$expected = array(
|
|
|
2203 |
'minimizedAttributeFormat' => 'format'
|
|
|
2204 |
);
|
|
|
2205 |
$this->assertEquals($expected, $result);
|
|
|
2206 |
$this->assertEquals('format', $this->Html->getAttribute('_minimizedAttributeFormat'));
|
|
|
2207 |
}
|
|
|
2208 |
|
|
|
2209 |
/**
|
|
|
2210 |
* testLoadConfigWrongFile method
|
|
|
2211 |
*
|
|
|
2212 |
* @return void
|
|
|
2213 |
* @expectedException ConfigureException
|
|
|
2214 |
*/
|
|
|
2215 |
public function testLoadConfigWrongFile() {
|
|
|
2216 |
$this->Html->loadConfig('wrong_file');
|
|
|
2217 |
}
|
|
|
2218 |
|
|
|
2219 |
/**
|
|
|
2220 |
* testLoadConfigWrongReader method
|
|
|
2221 |
*
|
|
|
2222 |
* @return void
|
|
|
2223 |
* @expectedException ConfigureException
|
|
|
2224 |
*/
|
|
|
2225 |
public function testLoadConfigWrongReader() {
|
|
|
2226 |
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS;
|
|
|
2227 |
$this->Html->loadConfig(array('htmlhelper_tags', 'wrong_reader'), $path);
|
|
|
2228 |
}
|
|
|
2229 |
|
|
|
2230 |
/**
|
|
|
2231 |
* test parsing attributes.
|
|
|
2232 |
*
|
|
|
2233 |
* @return void
|
|
|
2234 |
*/
|
|
|
2235 |
public function testParseAttributeCompact() {
|
|
|
2236 |
$helper = new TestHtmlHelper($this->View);
|
|
|
2237 |
$compact = array('compact', 'checked', 'declare', 'readonly', 'disabled',
|
|
|
2238 |
'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize');
|
|
|
2239 |
|
|
|
2240 |
foreach ($compact as $attribute) {
|
|
|
2241 |
foreach (array('true', true, 1, '1', $attribute) as $value) {
|
|
|
2242 |
$attrs = array($attribute => $value);
|
|
|
2243 |
$expected = ' ' . $attribute . '="' . $attribute . '"';
|
|
|
2244 |
$this->assertEquals($expected, $helper->parseAttributes($attrs), '%s Failed on ' . $value);
|
|
|
2245 |
}
|
|
|
2246 |
}
|
|
|
2247 |
$this->assertEquals(' compact="compact"', $helper->parseAttributes(array('compact')));
|
|
|
2248 |
|
|
|
2249 |
$attrs = array('class' => array('foo', 'bar'));
|
|
|
2250 |
$expected = ' class="foo bar"';
|
|
|
2251 |
$this->assertEquals(' class="foo bar"', $helper->parseAttributes($attrs));
|
|
|
2252 |
|
|
|
2253 |
$helper = new Html5TestHelper($this->View);
|
|
|
2254 |
$expected = ' require';
|
|
|
2255 |
$this->assertEquals($expected, $helper->parseAttributes(array('require')));
|
|
|
2256 |
$this->assertEquals($expected, $helper->parseAttributes(array('require' => true)));
|
|
|
2257 |
$this->assertEquals('', $helper->parseAttributes(array('require' => false)));
|
|
|
2258 |
}
|
|
|
2259 |
|
|
|
2260 |
}
|