Mercurial > hg > Members > shoshi > webvirt
comparison cake/tests/cases/libs/view/helpers/rss.test.php @ 0:261e66bd5a0c
hg init
author | Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 24 Jul 2011 21:08:31 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:261e66bd5a0c |
---|---|
1 <?php | |
2 /** | |
3 * RssHelperTest file | |
4 * | |
5 * PHP versions 4 and 5 | |
6 * | |
7 * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing> | |
8 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
9 * | |
10 * Licensed under The Open Group Test Suite License | |
11 * Redistributions of files must retain the above copyright notice. | |
12 * | |
13 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
14 * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests | |
15 * @package cake | |
16 * @subpackage cake.tests.cases.libs.view.helpers | |
17 * @since CakePHP(tm) v 1.2.0.4206 | |
18 * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License | |
19 */ | |
20 App::import('Helper', array('Rss', 'Time')); | |
21 | |
22 /** | |
23 * RssHelperTest class | |
24 * | |
25 * @package cake | |
26 * @subpackage cake.tests.cases.libs.view.helpers | |
27 */ | |
28 class RssHelperTest extends CakeTestCase { | |
29 | |
30 /** | |
31 * setUp method | |
32 * | |
33 * @access public | |
34 * @return void | |
35 */ | |
36 function setUp() { | |
37 $this->Rss =& new RssHelper(); | |
38 $this->Rss->Time =& new TimeHelper(); | |
39 $this->Rss->beforeRender(); | |
40 | |
41 $manager =& XmlManager::getInstance(); | |
42 $manager->namespaces = array(); | |
43 } | |
44 | |
45 /** | |
46 * tearDown method | |
47 * | |
48 * @access public | |
49 * @return void | |
50 */ | |
51 function tearDown() { | |
52 unset($this->Rss); | |
53 } | |
54 | |
55 /** | |
56 * testAddNamespace method | |
57 * | |
58 * @access public | |
59 * @return void | |
60 */ | |
61 function testAddNamespace() { | |
62 $this->Rss->addNs('custom', 'http://example.com/dtd.xml'); | |
63 $manager =& XmlManager::getInstance(); | |
64 | |
65 $expected = array('custom' => 'http://example.com/dtd.xml'); | |
66 $this->assertEqual($manager->namespaces, $expected); | |
67 | |
68 $this->Rss->removeNs('custom'); | |
69 | |
70 $this->Rss->addNs('dummy', 'http://dummy.com/1.0/'); | |
71 $result = $this->Rss->document(); | |
72 $expected = array( | |
73 'rss' => array( | |
74 'xmlns:dummy' => 'http://dummy.com/1.0/', | |
75 'version' => '2.0' | |
76 ) | |
77 ); | |
78 $this->assertTags($result, $expected); | |
79 | |
80 $this->Rss->removeNs('dummy'); | |
81 } | |
82 | |
83 /** | |
84 * testRemoveNamespace method | |
85 * | |
86 * @access public | |
87 * @return void | |
88 */ | |
89 function testRemoveNamespace() { | |
90 $this->Rss->addNs('custom', 'http://example.com/dtd.xml'); | |
91 $this->Rss->addNs('custom2', 'http://example.com/dtd2.xml'); | |
92 $manager =& XmlManager::getInstance(); | |
93 | |
94 $expected = array('custom' => 'http://example.com/dtd.xml', 'custom2' => 'http://example.com/dtd2.xml'); | |
95 $this->assertEqual($manager->namespaces, $expected); | |
96 | |
97 $this->Rss->removeNs('custom'); | |
98 $expected = array('custom2' => 'http://example.com/dtd2.xml'); | |
99 $this->assertEqual($manager->namespaces, $expected); | |
100 } | |
101 /** | |
102 * testDocument method | |
103 * | |
104 * @access public | |
105 * @return void | |
106 */ | |
107 function testDocument() { | |
108 $result = $this->Rss->document(); | |
109 $expected = array( | |
110 'rss' => array( | |
111 'version' => '2.0' | |
112 ) | |
113 ); | |
114 $this->assertTags($result, $expected); | |
115 | |
116 $result = $this->Rss->document(array('contrived' => 'parameter')); | |
117 $expected = array( | |
118 'rss' => array( | |
119 'version' => '2.0' | |
120 ), | |
121 '<parameter' | |
122 ); | |
123 $this->assertTags($result, $expected); | |
124 | |
125 $result = $this->Rss->document(null, 'content'); | |
126 $expected = array( | |
127 'rss' => array( | |
128 'version' => '2.0' | |
129 ), | |
130 'content' | |
131 ); | |
132 $this->assertTags($result, $expected); | |
133 | |
134 $result = $this->Rss->document(array('contrived' => 'parameter'), 'content'); | |
135 $expected = array( | |
136 'rss' => array( | |
137 'contrived' => 'parameter', | |
138 'version' => '2.0' | |
139 ), | |
140 'content' | |
141 ); | |
142 $this->assertTags($result, $expected); | |
143 } | |
144 | |
145 /** | |
146 * testChannel method | |
147 * | |
148 * @access public | |
149 * @return void | |
150 */ | |
151 function testChannel() { | |
152 $attrib = array('a' => '1', 'b' => '2'); | |
153 $elements = array('title' => 'title'); | |
154 $content = 'content'; | |
155 | |
156 $result = $this->Rss->channel($attrib, $elements, $content); | |
157 $expected = array( | |
158 'channel' => array( | |
159 'a' => '1', | |
160 'b' => '2' | |
161 ), | |
162 '<title', | |
163 'title', | |
164 '/title', | |
165 '<link', | |
166 RssHelper::url('/', true), | |
167 '/link', | |
168 '<description', | |
169 'content', | |
170 '/channel' | |
171 ); | |
172 $this->assertTags($result, $expected); | |
173 } | |
174 | |
175 /** | |
176 * test correct creation of channel sub elements. | |
177 * | |
178 * @access public | |
179 * @return void | |
180 */ | |
181 function testChannelElements() { | |
182 $attrib = array(); | |
183 $elements = array( | |
184 'title' => 'Title of RSS Feed', | |
185 'link' => 'http://example.com', | |
186 'description' => 'Description of RSS Feed', | |
187 'image' => array( | |
188 'title' => 'Title of image', | |
189 'url' => 'http://example.com/example.png', | |
190 'link' => 'http://example.com' | |
191 ), | |
192 'cloud' => array( | |
193 'domain' => "rpc.sys.com", | |
194 'port' => "80", | |
195 'path' =>"/RPC2", | |
196 'registerProcedure' => "myCloud.rssPleaseNotify", | |
197 'protocol' => "xml-rpc" | |
198 ) | |
199 ); | |
200 $content = 'content-here'; | |
201 $result = $this->Rss->channel($attrib, $elements, $content); | |
202 $expected = array( | |
203 '<channel', | |
204 '<title', 'Title of RSS Feed', '/title', | |
205 '<link', 'http://example.com', '/link', | |
206 '<description', 'Description of RSS Feed', '/description', | |
207 '<image', | |
208 '<title', 'Title of image', '/title', | |
209 '<url', 'http://example.com/example.png', '/url', | |
210 '<link', 'http://example.com', '/link', | |
211 '/image', | |
212 'cloud' => array( | |
213 'domain' => "rpc.sys.com", | |
214 'port' => "80", | |
215 'path' =>"/RPC2", | |
216 'registerProcedure' => "myCloud.rssPleaseNotify", | |
217 'protocol' => "xml-rpc" | |
218 ), | |
219 'content-here', | |
220 '/channel', | |
221 ); | |
222 $this->assertTags($result, $expected); | |
223 } | |
224 function testChannelElementAttributes() { | |
225 $attrib = array(); | |
226 $elements = array( | |
227 'title' => 'Title of RSS Feed', | |
228 'link' => 'http://example.com', | |
229 'description' => 'Description of RSS Feed', | |
230 'image' => array( | |
231 'title' => 'Title of image', | |
232 'url' => 'http://example.com/example.png', | |
233 'link' => 'http://example.com' | |
234 ), | |
235 'atom:link' => array( | |
236 'attrib' => array( | |
237 'href' => 'http://www.example.com/rss.xml', | |
238 'rel' => 'self', | |
239 'type' => 'application/rss+xml') | |
240 ) | |
241 ); | |
242 $content = 'content-here'; | |
243 $result = $this->Rss->channel($attrib, $elements, $content); | |
244 $expected = array( | |
245 '<channel', | |
246 '<title', 'Title of RSS Feed', '/title', | |
247 '<link', 'http://example.com', '/link', | |
248 '<description', 'Description of RSS Feed', '/description', | |
249 '<image', | |
250 '<title', 'Title of image', '/title', | |
251 '<url', 'http://example.com/example.png', '/url', | |
252 '<link', 'http://example.com', '/link', | |
253 '/image', | |
254 'atom:link' => array( | |
255 'href' => "http://www.example.com/rss.xml", | |
256 'rel' => "self", | |
257 'type' =>"application/rss+xml" | |
258 ), | |
259 'content-here', | |
260 '/channel', | |
261 ); | |
262 $this->assertTags($result, $expected); | |
263 } | |
264 | |
265 /** | |
266 * testItems method | |
267 * | |
268 * @access public | |
269 * @return void | |
270 */ | |
271 function testItems() { | |
272 $items = array( | |
273 array('title' => 'title1', 'guid' => 'http://www.example.com/guid1', 'link' => 'http://www.example.com/link1', 'description' => 'description1'), | |
274 array('title' => 'title2', 'guid' => 'http://www.example.com/guid2', 'link' => 'http://www.example.com/link2', 'description' => 'description2'), | |
275 array('title' => 'title3', 'guid' => 'http://www.example.com/guid3', 'link' => 'http://www.example.com/link3', 'description' => 'description3') | |
276 ); | |
277 | |
278 $result = $this->Rss->items($items); | |
279 $expected = array( | |
280 '<item', | |
281 '<title', 'title1', '/title', | |
282 '<guid', 'http://www.example.com/guid1', '/guid', | |
283 '<link', 'http://www.example.com/link1', '/link', | |
284 '<description', 'description1', '/description', | |
285 '/item', | |
286 '<item', | |
287 '<title', 'title2', '/title', | |
288 '<guid', 'http://www.example.com/guid2', '/guid', | |
289 '<link', 'http://www.example.com/link2', '/link', | |
290 '<description', 'description2', '/description', | |
291 '/item', | |
292 '<item', | |
293 '<title', 'title3', '/title', | |
294 '<guid', 'http://www.example.com/guid3', '/guid', | |
295 '<link', 'http://www.example.com/link3', '/link', | |
296 '<description', 'description3', '/description', | |
297 '/item' | |
298 ); | |
299 $this->assertTags($result, $expected); | |
300 | |
301 $result = $this->Rss->items(array()); | |
302 $expected = ''; | |
303 $this->assertEqual($result, $expected); | |
304 } | |
305 | |
306 /** | |
307 * testItem method | |
308 * | |
309 * @access public | |
310 * @return void | |
311 */ | |
312 function testItem() { | |
313 $item = array( | |
314 'title' => 'My title', | |
315 'description' => 'My description', | |
316 'link' => 'http://www.google.com/' | |
317 ); | |
318 $result = $this->Rss->item(null, $item); | |
319 $expected = array( | |
320 '<item', | |
321 '<title', | |
322 'My title', | |
323 '/title', | |
324 '<description', | |
325 'My description', | |
326 '/description', | |
327 '<link', | |
328 'http://www.google.com/', | |
329 '/link', | |
330 '<guid', | |
331 'http://www.google.com/', | |
332 '/guid', | |
333 '/item' | |
334 ); | |
335 $this->assertTags($result, $expected); | |
336 | |
337 $item = array( | |
338 'title' => array( | |
339 'value' => 'My Title', | |
340 'cdata' => true, | |
341 ), | |
342 'link' => 'http://www.example.com/1', | |
343 'description' => array( | |
344 'value' => 'descriptive words', | |
345 'cdata' => true, | |
346 ), | |
347 'pubDate' => '2008-05-31 12:00:00', | |
348 'guid' => 'http://www.example.com/1' | |
349 ); | |
350 $result = $this->Rss->item(null, $item); | |
351 | |
352 $expected = array( | |
353 '<item', | |
354 '<title', | |
355 '<![CDATA[My Title]]', | |
356 '/title', | |
357 '<link', | |
358 'http://www.example.com/1', | |
359 '/link', | |
360 '<description', | |
361 '<![CDATA[descriptive words]]', | |
362 '/description', | |
363 '<pubDate', | |
364 date('r', strtotime('2008-05-31 12:00:00')), | |
365 '/pubDate', | |
366 '<guid', | |
367 'http://www.example.com/1', | |
368 '/guid', | |
369 '/item' | |
370 ); | |
371 $this->assertTags($result, $expected); | |
372 | |
373 $item = array( | |
374 'title' => array( | |
375 'value' => 'My Title & more', | |
376 'cdata' => true | |
377 ) | |
378 ); | |
379 $result = $this->Rss->item(null, $item); | |
380 $expected = array( | |
381 '<item', | |
382 '<title', | |
383 '<![CDATA[My Title & more]]', | |
384 '/title', | |
385 '/item' | |
386 ); | |
387 $this->assertTags($result, $expected); | |
388 | |
389 $item = array( | |
390 'title' => array( | |
391 'value' => 'My Title & more', | |
392 'convertEntities' => false | |
393 ) | |
394 ); | |
395 $result = $this->Rss->item(null, $item); | |
396 $expected = array( | |
397 '<item', | |
398 '<title', | |
399 'My Title & more', | |
400 '/title', | |
401 '/item' | |
402 ); | |
403 $this->assertTags($result, $expected); | |
404 | |
405 $item = array( | |
406 'title' => array( | |
407 'value' => 'My Title & more', | |
408 'cdata' => true, | |
409 'convertEntities' => false, | |
410 ) | |
411 ); | |
412 $result = $this->Rss->item(null, $item); | |
413 $expected = array( | |
414 '<item', | |
415 '<title', | |
416 '<![CDATA[My Title & more]]', | |
417 '/title', | |
418 '/item' | |
419 ); | |
420 $this->assertTags($result, $expected); | |
421 | |
422 $item = array( | |
423 'category' => array( | |
424 'value' => 'CakePHP', | |
425 'cdata' => true, | |
426 'domain' => 'http://www.cakephp.org' | |
427 ) | |
428 ); | |
429 $result = $this->Rss->item(null, $item); | |
430 $expected = array( | |
431 '<item', | |
432 'category' => array('domain' => 'http://www.cakephp.org'), | |
433 '<![CDATA[CakePHP]]', | |
434 '/category', | |
435 '/item' | |
436 ); | |
437 $this->assertTags($result, $expected); | |
438 | |
439 $item = array( | |
440 'category' => array( | |
441 array( | |
442 'value' => 'CakePHP', | |
443 'cdata' => true, | |
444 'domain' => 'http://www.cakephp.org' | |
445 ), | |
446 array( | |
447 'value' => 'Bakery', | |
448 'cdata' => true | |
449 ) | |
450 ) | |
451 ); | |
452 $result = $this->Rss->item(null, $item); | |
453 $expected = array( | |
454 '<item', | |
455 'category' => array('domain' => 'http://www.cakephp.org'), | |
456 '<![CDATA[CakePHP]]', | |
457 '/category', | |
458 '<category', | |
459 '<![CDATA[Bakery]]', | |
460 '/category', | |
461 '/item' | |
462 ); | |
463 $this->assertTags($result, $expected); | |
464 | |
465 $item = array( | |
466 'title' => array( | |
467 'value' => 'My Title', | |
468 'cdata' => true, | |
469 ), | |
470 'link' => 'http://www.example.com/1', | |
471 'description' => array( | |
472 'value' => 'descriptive words', | |
473 'cdata' => true, | |
474 ), | |
475 'enclosure' => array( | |
476 'url' => '/test.flv' | |
477 ), | |
478 'pubDate' => '2008-05-31 12:00:00', | |
479 'guid' => 'http://www.example.com/1', | |
480 'category' => array( | |
481 array( | |
482 'value' => 'CakePHP', | |
483 'cdata' => true, | |
484 'domain' => 'http://www.cakephp.org' | |
485 ), | |
486 array( | |
487 'value' => 'Bakery', | |
488 'cdata' => true | |
489 ) | |
490 ) | |
491 ); | |
492 $result = $this->Rss->item(null, $item); | |
493 $expected = array( | |
494 '<item', | |
495 '<title', | |
496 '<![CDATA[My Title]]', | |
497 '/title', | |
498 '<link', | |
499 'http://www.example.com/1', | |
500 '/link', | |
501 '<description', | |
502 '<![CDATA[descriptive words]]', | |
503 '/description', | |
504 'enclosure' => array('url' => RssHelper::url('/test.flv', true)), | |
505 '<pubDate', | |
506 date('r', strtotime('2008-05-31 12:00:00')), | |
507 '/pubDate', | |
508 '<guid', | |
509 'http://www.example.com/1', | |
510 '/guid', | |
511 'category' => array('domain' => 'http://www.cakephp.org'), | |
512 '<![CDATA[CakePHP]]', | |
513 '/category', | |
514 '<category', | |
515 '<![CDATA[Bakery]]', | |
516 '/category', | |
517 '/item' | |
518 ); | |
519 $this->assertTags($result, $expected); | |
520 | |
521 $item = array( | |
522 'title' => 'Foo bar', | |
523 'link' => array( | |
524 'url' => 'http://example.com/foo?a=1&b=2', | |
525 'convertEntities' => false | |
526 ), | |
527 'description' => array( | |
528 'value' => 'descriptive words', | |
529 'cdata' => true, | |
530 ), | |
531 'pubDate' => '2008-05-31 12:00:00' | |
532 ); | |
533 $result = $this->Rss->item(null, $item); | |
534 $expected = array( | |
535 '<item', | |
536 '<title', | |
537 'Foo bar', | |
538 '/title', | |
539 '<link', | |
540 'http://example.com/foo?a=1&b=2', | |
541 '/link', | |
542 '<description', | |
543 '<![CDATA[descriptive words]]', | |
544 '/description', | |
545 '<pubDate', | |
546 date('r', strtotime('2008-05-31 12:00:00')), | |
547 '/pubDate', | |
548 '<guid', | |
549 'http://example.com/foo?a=1&b=2', | |
550 '/guid', | |
551 '/item' | |
552 ); | |
553 $this->assertTags($result, $expected); | |
554 } | |
555 | |
556 /** | |
557 * testTime method | |
558 * | |
559 * @access public | |
560 * @return void | |
561 */ | |
562 function testTime() { | |
563 } | |
564 | |
565 /** | |
566 * testElementAttrNotInParent method | |
567 * | |
568 * @access public | |
569 * @return void | |
570 */ | |
571 function testElementAttrNotInParent() { | |
572 $attributes = array( | |
573 'title' => 'Some Title', | |
574 'link' => 'http://link.com', | |
575 'description' => 'description' | |
576 ); | |
577 $elements = array('enclosure' => array('url' => 'http://test.com')); | |
578 | |
579 $result = $this->Rss->item($attributes, $elements); | |
580 $expected = array( | |
581 'item' => array( | |
582 'title' => 'Some Title', | |
583 'link' => 'http://link.com', | |
584 'description' => 'description' | |
585 ), | |
586 'enclosure' => array( | |
587 'url' => 'http://test.com' | |
588 ), | |
589 '/item' | |
590 ); | |
591 $this->assertTags($result, $expected); | |
592 } | |
593 } |