1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
<?php
namespace PicoFeed\Parser;
use PHPUnit_Framework_TestCase;
use DateTime;
class Rss20ParserTest extends PHPUnit_Framework_TestCase
{
/**
* @expectedException PicoFeed\Parser\MalformedXmlException
*/
public function testBadInput()
{
$parser = new Rss20('boo');
$parser->execute();
}
public function testFeedTitle()
{
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
$feed = $parser->execute();
$this->assertEquals('WordPress News', $feed->getTitle());
$parser = new Rss20(file_get_contents('tests/fixtures/pcinpact.xml'));
$feed = $parser->execute();
$this->assertEquals('PC INpact', $feed->getTitle());
}
public function testFeedDescription()
{
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
$feed = $parser->execute();
$this->assertEquals('WordPress News', $feed->getDescription());
$parser = new Rss20(file_get_contents('tests/fixtures/pcinpact.xml'));
$feed = $parser->execute();
$this->assertEquals('Actualités Informatique', $feed->getDescription());
$parser = new Rss20(file_get_contents('tests/fixtures/sametmax.xml'));
$feed = $parser->execute();
$this->assertEquals('Deux développeurs en vadrouille qui se sortent les doigts du code', $feed->getDescription());
}
public function testFeedLogo()
{
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
$feed = $parser->execute();
$this->assertEquals('', $feed->getLogo());
$parser = new Rss20(file_get_contents('tests/fixtures/radio-france.xml'));
$feed = $parser->execute();
$this->assertEquals('http://media.radiofrance-podcast.net/podcast09/RF_OMM_0000006330_ITE.jpg', $feed->getLogo());
}
public function testFeedUrl()
{
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
$feed = $parser->execute();
$this->assertEquals('', $feed->getFeedUrl());
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'), '', 'http://example.com/feed');
$feed = $parser->execute();
$this->assertEquals('http://example.com/feed', $feed->getFeedUrl());
$parser = new Rss20(file_get_contents('tests/fixtures/pcinpact.xml'));
$feed = $parser->execute();
$this->assertEquals('', $feed->getFeedUrl());
}
public function testSiteUrl()
{
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
$feed = $parser->execute();
$this->assertEquals('http://wordpress.org/news', $feed->getSiteUrl());
$parser = new Rss20(file_get_contents('tests/fixtures/pcinpact.xml'));
$feed = $parser->execute();
$this->assertEquals('http://www.pcinpact.com/', $feed->getSiteUrl());
}
public function testFeedId()
{
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
$feed = $parser->execute();
$this->assertEquals('http://wordpress.org/news', $feed->getId());
}
public function testFeedDate()
{
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
$feed = $parser->execute();
$this->assertEquals(1359066183, $feed->getDate()->getTimestamp());
$parser = new Rss20(file_get_contents('tests/fixtures/fulltextrss.xml'));
$feed = $parser->execute();
$this->assertEquals(new DateTime, $feed->getDate());
}
public function testFeedLanguage()
{
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
$feed = $parser->execute();
$this->assertEquals('en-US', $feed->getLanguage());
$this->assertEquals('en-US', $feed->items[0]->getLanguage());
$parser = new Rss20(file_get_contents('tests/fixtures/zoot_egkty.xml'));
$feed = $parser->execute();
$this->assertEquals('ur', $feed->getLanguage());
$this->assertEquals('ur', $feed->items[0]->getLanguage());
$parser = new Rss20(file_get_contents('tests/fixtures/ibash.ru.xml'));
$feed = $parser->execute();
$this->assertEquals('ru', $feed->getLanguage());
$this->assertEquals('ru', $feed->items[0]->getLanguage());
}
public function testItemId()
{
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$this->assertEquals('de679f14fc4774f0d6dfe73c3f8c8368ab85da18addf101a2af8c32ac6320f9f', $feed->items[0]->getId());
$parser = new Rss20(file_get_contents('tests/fixtures/pcinpact.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$this->assertEquals(hash('sha256', '78872'), $feed->items[0]->getId());
$parser = new Rss20(file_get_contents('tests/fixtures/fulltextrss.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$this->assertEquals(hash('sha256', 'http://www.numerama.com/magazine/25669-brevets-un-juge-doute-de-la-bonne-volonte-de-google-et-apple.html'), $feed->items[0]->getId());
$parser = new Rss20(file_get_contents('tests/fixtures/debug_show.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$this->assertEquals(hash('sha256', '38DC2FF1-4207-4C04-93F3-2DAFB0E559D9'), $feed->items[1]->getId());
$this->assertEquals(hash('sha256', '3FA03A63-BEA2-4199-A1E4-D2963845F3F6'), $feed->items[2]->getId());
$this->assertEquals($feed->items[1]->getUrl(), $feed->items[2]->getUrl());
$this->assertNotEquals($feed->items[1]->getId(), $feed->items[2]->getId());
}
public function testItemUrl()
{
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$this->assertEquals('http://wordpress.org/news/2013/01/wordpress-3-5-1/', $feed->items[0]->getUrl());
$parser = new Rss20(file_get_contents('tests/fixtures/pcinpact.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$this->assertEquals('http://www.pcinpact.com/breve/78872-la-dcri-purge-wikipedia-par-menace-bel-effet-streisand-a-cle.htm?utm_source=PCi_RSS_Feed&utm_medium=news&utm_campaign=pcinpact', $feed->items[0]->getUrl());
}
public function testItemTitle()
{
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$this->assertEquals('2012: A Look Back', $feed->items[1]->getTitle());
$parser = new Rss20(file_get_contents('tests/fixtures/womensweardaily.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$this->assertEquals('They Are Wearing: Frieze London Photo by Marcus Dawes', $feed->items[3]->getTitle());
}
public function testItemDate()
{
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$this->assertEquals(1357006940, $feed->items[1]->getDate()->getTimestamp());
$parser = new Rss20(file_get_contents('tests/fixtures/fulltextrss.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$this->assertEquals(1365781095, $feed->items[0]->getDate()->getTimestamp());
}
public function testItemLanguage()
{
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$this->assertEquals('en-US', $feed->items[1]->getLanguage());
}
public function testItemAuthor()
{
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$this->assertEquals('Jen Mylo', $feed->items[1]->getAuthor());
$parser = new Rss20(file_get_contents('tests/fixtures/rss2sample.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$this->assertEquals('webmaster@example.com', $feed->items[2]->getAuthor());
}
public function testItemContent()
{
$parser = new Rss20(file_get_contents('tests/fixtures/rss20.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$this->assertTrue(strpos($feed->items[1]->getContent(), '<p>Another year is coming') === 0);
$parser = new Rss20(file_get_contents('tests/fixtures/rss2sample.xml'));
$feed = $parser->execute();
$this->assertNotEmpty($feed->items);
$this->assertTrue(strpos($feed->items[1]<
|