root / drupal7 / sites / all / libraries / simplepie-1.3.1 / tests / ItemTest.php @ a60304ed
1 | 41cc1b08 | Assos Assos | <?php
|
---|---|---|---|
2 | /**
|
||
3 | * Tests for SimplePie_Item
|
||
4 | *
|
||
5 | * SimplePie
|
||
6 | *
|
||
7 | * A PHP-Based RSS and Atom Feed Framework.
|
||
8 | * Takes the hard work out of managing a complete RSS/Atom solution.
|
||
9 | *
|
||
10 | * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||
11 | * All rights reserved.
|
||
12 | *
|
||
13 | * Redistribution and use in source and binary forms, with or without modification, are
|
||
14 | * permitted provided that the following conditions are met:
|
||
15 | *
|
||
16 | * * Redistributions of source code must retain the above copyright notice, this list of
|
||
17 | * conditions and the following disclaimer.
|
||
18 | *
|
||
19 | * * Redistributions in binary form must reproduce the above copyright notice, this list
|
||
20 | * of conditions and the following disclaimer in the documentation and/or other materials
|
||
21 | * provided with the distribution.
|
||
22 | *
|
||
23 | * * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||
24 | * to endorse or promote products derived from this software without specific prior
|
||
25 | * written permission.
|
||
26 | *
|
||
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||
28 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||
29 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||
30 | * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||
31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||
32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||
33 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||
34 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||
35 | * POSSIBILITY OF SUCH DAMAGE.
|
||
36 | *
|
||
37 | * @package SimplePie
|
||
38 | * @version 1.3.1
|
||
39 | * @copyright 2004-2011 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||
40 | * @author Ryan Parman
|
||
41 | * @author Geoffrey Sneddon
|
||
42 | * @author Ryan McCue
|
||
43 | * @link http://simplepie.org/ SimplePie
|
||
44 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||
45 | */
|
||
46 | |||
47 | require_once dirname(__FILE__) . '/bootstrap.php'; |
||
48 | |||
49 | class ItemTest extends PHPUnit_Framework_TestCase |
||
50 | { |
||
51 | /**
|
||
52 | * Run a test using a sprintf template and data
|
||
53 | *
|
||
54 | * @param string $template
|
||
55 | */
|
||
56 | protected function checkFromTemplate($template, $data, $expected) |
||
57 | { |
||
58 | if (!is_array($data)) |
||
59 | { |
||
60 | $data = array($data); |
||
61 | } |
||
62 | $xml = vsprintf($template, $data); |
||
63 | $feed = new SimplePie(); |
||
64 | $feed->set_raw_data($xml); |
||
65 | $feed->enable_cache(false); |
||
66 | $feed->init();
|
||
67 | |||
68 | return $feed; |
||
69 | } |
||
70 | |||
71 | public static function titleprovider() |
||
72 | { |
||
73 | return array( |
||
74 | array('Feed Title', 'Feed Title'), |
||
75 | |||
76 | // RSS Profile tests
|
||
77 | array('AT&T', 'AT&T'), |
||
78 | array('AT&T', 'AT&T'), |
||
79 | array("Bill & Ted's Excellent Adventure", "Bill & Ted's Excellent Adventure"), |
||
80 | array("Bill & Ted's Excellent Adventure", "Bill & Ted's Excellent Adventure"), |
||
81 | array('The & entity', 'The & entity'), |
||
82 | array('The & entity', 'The & entity'), |
||
83 | array('The &amp; entity', 'The &amp; entity'), |
||
84 | array('The &amp; entity', 'The &amp; entity'), |
||
85 | array('I <3 Phil Ringnalda', 'I <3 Phil Ringnalda'), |
||
86 | array('I <3 Phil Ringnalda', 'I <3 Phil Ringnalda'), |
||
87 | array('A < B', 'A < B'), |
||
88 | array('A < B', 'A < B'), |
||
89 | array('A<B', 'A<B'), |
||
90 | array('A<B', 'A<B'), |
||
91 | array("Nice <gorilla> what's he weigh?", "Nice <gorilla> what's he weigh?"), |
||
92 | array("Nice <gorilla> what's he weigh?", "Nice <gorilla> what's he weigh?"), |
||
93 | ); |
||
94 | } |
||
95 | |||
96 | /**
|
||
97 | * @dataProvider titleprovider
|
||
98 | */
|
||
99 | public function testTitleRSS20($title, $expected) |
||
100 | { |
||
101 | $data =
|
||
102 | '<rss version="2.0">
|
||
103 | <channel>
|
||
104 | <title>%s</title>
|
||
105 | </channel>
|
||
106 | </rss>';
|
||
107 | $feed = $this->checkFromTemplate($data, $title, $expected); |
||
108 | $this->assertEquals($expected, $feed->get_title()); |
||
109 | } |
||
110 | |||
111 | /**
|
||
112 | * @dataProvider titleprovider
|
||
113 | */
|
||
114 | public function testTitleRSS20WithDC10($title, $expected) |
||
115 | { |
||
116 | $data =
|
||
117 | '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.0/">
|
||
118 | <channel>
|
||
119 | <dc:title>%s</dc:title>
|
||
120 | </channel>
|
||
121 | </rss>';
|
||
122 | $feed = $this->checkFromTemplate($data, $title, $expected); |
||
123 | $this->assertEquals($expected, $feed->get_title()); |
||
124 | } |
||
125 | |||
126 | /**
|
||
127 | * @dataProvider titleprovider
|
||
128 | */
|
||
129 | public function testTitleRSS20WithDC11($title, $expected) |
||
130 | { |
||
131 | $data =
|
||
132 | '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||
133 | <channel>
|
||
134 | <dc:title>%s</dc:title>
|
||
135 | </channel>
|
||
136 | </rss>';
|
||
137 | $feed = $this->checkFromTemplate($data, $title, $expected); |
||
138 | $this->assertEquals($expected, $feed->get_title()); |
||
139 | } |
||
140 | |||
141 | /**
|
||
142 | * @dataProvider titleprovider
|
||
143 | */
|
||
144 | public function testTitleRSS20WithAtom03($title, $expected) |
||
145 | { |
||
146 | $data =
|
||
147 | '<rss version="2.0" xmlns:a="http://purl.org/atom/ns#">
|
||
148 | <channel>
|
||
149 | <a:title>%s</a:title>
|
||
150 | </channel>
|
||
151 | </rss>';
|
||
152 | $feed = $this->checkFromTemplate($data, $title, $expected); |
||
153 | $this->assertEquals($expected, $feed->get_title()); |
||
154 | } |
||
155 | |||
156 | /**
|
||
157 | * @dataProvider titleprovider
|
||
158 | */
|
||
159 | public function testTitleRSS20WithAtom10($title, $expected) |
||
160 | { |
||
161 | $data =
|
||
162 | '<rss version="2.0" xmlns:a="http://www.w3.org/2005/Atom">
|
||
163 | <channel>
|
||
164 | <a:title>%s</a:title>
|
||
165 | </channel>
|
||
166 | </rss>';
|
||
167 | $feed = $this->checkFromTemplate($data, $title, $expected); |
||
168 | $this->assertEquals($expected, $feed->get_title()); |
||
169 | } |
||
170 | |||
171 | /**
|
||
172 | * Based on a test from old bug 18
|
||
173 | *
|
||
174 | * @dataProvider titleprovider
|
||
175 | */
|
||
176 | public function testTitleRSS20WithImageTitle($title, $expected) |
||
177 | { |
||
178 | $data =
|
||
179 | '<rss version="2.0">
|
||
180 | <channel>
|
||
181 | <title>%s</title>
|
||
182 | <image>
|
||
183 | <title>Image title</title>
|
||
184 | </image>
|
||
185 | </channel>
|
||
186 | </rss>';
|
||
187 | $feed = $this->checkFromTemplate($data, $title, $expected); |
||
188 | $this->assertEquals($expected, $feed->get_title()); |
||
189 | } |
||
190 | |||
191 | /**
|
||
192 | * Based on a test from old bug 18
|
||
193 | *
|
||
194 | * @dataProvider titleprovider
|
||
195 | */
|
||
196 | public function testTitleRSS20WithImageTitleReversed($title, $expected) |
||
197 | { |
||
198 | $data =
|
||
199 | '<rss version="2.0">
|
||
200 | <channel>
|
||
201 | <image>
|
||
202 | <title>Image title</title>
|
||
203 | </image>
|
||
204 | <title>%s</title>
|
||
205 | </channel>
|
||
206 | </rss>';
|
||
207 | $feed = $this->checkFromTemplate($data, $title, $expected); |
||
208 | $this->assertEquals($expected, $feed->get_title()); |
||
209 | } |
||
210 | } |