diff options
Diffstat (limited to 'tests/feed/FeedBuilderTest.php')
-rw-r--r-- | tests/feed/FeedBuilderTest.php | 83 |
1 files changed, 25 insertions, 58 deletions
diff --git a/tests/feed/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php index 54671891..5c2aaedb 100644 --- a/tests/feed/FeedBuilderTest.php +++ b/tests/feed/FeedBuilderTest.php | |||
@@ -65,23 +65,6 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
65 | } | 65 | } |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Test GetTypeLanguage(). | ||
69 | */ | ||
70 | public function testGetTypeLanguage() | ||
71 | { | ||
72 | $feedBuilder = new FeedBuilder(null, self::$formatter, FeedBuilder::$FEED_ATOM, null, null, false); | ||
73 | $feedBuilder->setLocale(self::$LOCALE); | ||
74 | $this->assertEquals(self::$ATOM_LANGUAGUE, $feedBuilder->getTypeLanguage()); | ||
75 | $feedBuilder = new FeedBuilder(null, self::$formatter, FeedBuilder::$FEED_RSS, null, null, false); | ||
76 | $feedBuilder->setLocale(self::$LOCALE); | ||
77 | $this->assertEquals(self::$RSS_LANGUAGE, $feedBuilder->getTypeLanguage()); | ||
78 | $feedBuilder = new FeedBuilder(null, self::$formatter, FeedBuilder::$FEED_ATOM, null, null, false); | ||
79 | $this->assertEquals('en', $feedBuilder->getTypeLanguage()); | ||
80 | $feedBuilder = new FeedBuilder(null, self::$formatter, FeedBuilder::$FEED_RSS, null, null, false); | ||
81 | $this->assertEquals('en-en', $feedBuilder->getTypeLanguage()); | ||
82 | } | ||
83 | |||
84 | /** | ||
85 | * Test buildData with RSS feed. | 68 | * Test buildData with RSS feed. |
86 | */ | 69 | */ |
87 | public function testRSSBuildData() | 70 | public function testRSSBuildData() |
@@ -89,13 +72,11 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
89 | $feedBuilder = new FeedBuilder( | 72 | $feedBuilder = new FeedBuilder( |
90 | self::$bookmarkService, | 73 | self::$bookmarkService, |
91 | self::$formatter, | 74 | self::$formatter, |
92 | FeedBuilder::$FEED_RSS, | 75 | static::$serverInfo, |
93 | self::$serverInfo, | ||
94 | null, | ||
95 | false | 76 | false |
96 | ); | 77 | ); |
97 | $feedBuilder->setLocale(self::$LOCALE); | 78 | $feedBuilder->setLocale(self::$LOCALE); |
98 | $data = $feedBuilder->buildData(); | 79 | $data = $feedBuilder->buildData(FeedBuilder::$FEED_RSS, null); |
99 | // Test headers (RSS) | 80 | // Test headers (RSS) |
100 | $this->assertEquals(self::$RSS_LANGUAGE, $data['language']); | 81 | $this->assertEquals(self::$RSS_LANGUAGE, $data['language']); |
101 | $this->assertRegExp('/Wed, 03 Aug 2016 09:30:33 \+\d{4}/', $data['last_update']); | 82 | $this->assertRegExp('/Wed, 03 Aug 2016 09:30:33 \+\d{4}/', $data['last_update']); |
@@ -109,15 +90,15 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
109 | $link = $data['links'][array_keys($data['links'])[2]]; | 90 | $link = $data['links'][array_keys($data['links'])[2]]; |
110 | $this->assertEquals(41, $link['id']); | 91 | $this->assertEquals(41, $link['id']); |
111 | $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); | 92 | $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); |
112 | $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); | 93 | $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); |
113 | $this->assertEquals('http://host.tld/?WDWyig', $link['url']); | 94 | $this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']); |
114 | $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']); | 95 | $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']); |
115 | $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']); | 96 | $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']); |
116 | $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); | 97 | $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); |
117 | $this->assertEquals($pub, $up); | 98 | $this->assertEquals($pub, $up); |
118 | $this->assertContains('Stallman has a beard', $link['description']); | 99 | $this->assertContains('Stallman has a beard', $link['description']); |
119 | $this->assertContains('Permalink', $link['description']); | 100 | $this->assertContains('Permalink', $link['description']); |
120 | $this->assertContains('http://host.tld/?WDWyig', $link['description']); | 101 | $this->assertContains('http://host.tld/shaare/WDWyig', $link['description']); |
121 | $this->assertEquals(1, count($link['taglist'])); | 102 | $this->assertEquals(1, count($link['taglist'])); |
122 | $this->assertEquals('sTuff', $link['taglist'][0]); | 103 | $this->assertEquals('sTuff', $link['taglist'][0]); |
123 | 104 | ||
@@ -140,13 +121,11 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
140 | $feedBuilder = new FeedBuilder( | 121 | $feedBuilder = new FeedBuilder( |
141 | self::$bookmarkService, | 122 | self::$bookmarkService, |
142 | self::$formatter, | 123 | self::$formatter, |
143 | FeedBuilder::$FEED_ATOM, | 124 | static::$serverInfo, |
144 | self::$serverInfo, | ||
145 | null, | ||
146 | false | 125 | false |
147 | ); | 126 | ); |
148 | $feedBuilder->setLocale(self::$LOCALE); | 127 | $feedBuilder->setLocale(self::$LOCALE); |
149 | $data = $feedBuilder->buildData(); | 128 | $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null); |
150 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); | 129 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); |
151 | $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']); | 130 | $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']); |
152 | $link = $data['links'][array_keys($data['links'])[2]]; | 131 | $link = $data['links'][array_keys($data['links'])[2]]; |
@@ -166,13 +145,11 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
166 | $feedBuilder = new FeedBuilder( | 145 | $feedBuilder = new FeedBuilder( |
167 | self::$bookmarkService, | 146 | self::$bookmarkService, |
168 | self::$formatter, | 147 | self::$formatter, |
169 | FeedBuilder::$FEED_ATOM, | 148 | static::$serverInfo, |
170 | self::$serverInfo, | ||
171 | $criteria, | ||
172 | false | 149 | false |
173 | ); | 150 | ); |
174 | $feedBuilder->setLocale(self::$LOCALE); | 151 | $feedBuilder->setLocale(self::$LOCALE); |
175 | $data = $feedBuilder->buildData(); | 152 | $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, $criteria); |
176 | $this->assertEquals(1, count($data['links'])); | 153 | $this->assertEquals(1, count($data['links'])); |
177 | $link = array_shift($data['links']); | 154 | $link = array_shift($data['links']); |
178 | $this->assertEquals(41, $link['id']); | 155 | $this->assertEquals(41, $link['id']); |
@@ -190,13 +167,11 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
190 | $feedBuilder = new FeedBuilder( | 167 | $feedBuilder = new FeedBuilder( |
191 | self::$bookmarkService, | 168 | self::$bookmarkService, |
192 | self::$formatter, | 169 | self::$formatter, |
193 | FeedBuilder::$FEED_ATOM, | 170 | static::$serverInfo, |
194 | self::$serverInfo, | ||
195 | $criteria, | ||
196 | false | 171 | false |
197 | ); | 172 | ); |
198 | $feedBuilder->setLocale(self::$LOCALE); | 173 | $feedBuilder->setLocale(self::$LOCALE); |
199 | $data = $feedBuilder->buildData(); | 174 | $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, $criteria); |
200 | $this->assertEquals(3, count($data['links'])); | 175 | $this->assertEquals(3, count($data['links'])); |
201 | $link = $data['links'][array_keys($data['links'])[2]]; | 176 | $link = $data['links'][array_keys($data['links'])[2]]; |
202 | $this->assertEquals(41, $link['id']); | 177 | $this->assertEquals(41, $link['id']); |
@@ -211,29 +186,27 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
211 | $feedBuilder = new FeedBuilder( | 186 | $feedBuilder = new FeedBuilder( |
212 | self::$bookmarkService, | 187 | self::$bookmarkService, |
213 | self::$formatter, | 188 | self::$formatter, |
214 | FeedBuilder::$FEED_ATOM, | 189 | static::$serverInfo, |
215 | self::$serverInfo, | ||
216 | null, | ||
217 | false | 190 | false |
218 | ); | 191 | ); |
219 | $feedBuilder->setLocale(self::$LOCALE); | 192 | $feedBuilder->setLocale(self::$LOCALE); |
220 | $feedBuilder->setUsePermalinks(true); | 193 | $feedBuilder->setUsePermalinks(true); |
221 | $data = $feedBuilder->buildData(); | 194 | $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null); |
222 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); | 195 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); |
223 | $this->assertTrue($data['usepermalinks']); | 196 | $this->assertTrue($data['usepermalinks']); |
224 | // First link is a permalink | 197 | // First link is a permalink |
225 | $link = $data['links'][array_keys($data['links'])[2]]; | 198 | $link = $data['links'][array_keys($data['links'])[2]]; |
226 | $this->assertEquals(41, $link['id']); | 199 | $this->assertEquals(41, $link['id']); |
227 | $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); | 200 | $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); |
228 | $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); | 201 | $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); |
229 | $this->assertEquals('http://host.tld/?WDWyig', $link['url']); | 202 | $this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']); |
230 | $this->assertContains('Direct link', $link['description']); | 203 | $this->assertContains('Direct link', $link['description']); |
231 | $this->assertContains('http://host.tld/?WDWyig', $link['description']); | 204 | $this->assertContains('http://host.tld/shaare/WDWyig', $link['description']); |
232 | // Second link is a direct link | 205 | // Second link is a direct link |
233 | $link = $data['links'][array_keys($data['links'])[3]]; | 206 | $link = $data['links'][array_keys($data['links'])[3]]; |
234 | $this->assertEquals(8, $link['id']); | 207 | $this->assertEquals(8, $link['id']); |
235 | $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']); | 208 | $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']); |
236 | $this->assertEquals('http://host.tld/?RttfEw', $link['guid']); | 209 | $this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']); |
237 | $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']); | 210 | $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']); |
238 | $this->assertContains('Direct link', $link['description']); | 211 | $this->assertContains('Direct link', $link['description']); |
239 | $this->assertContains('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']); | 212 | $this->assertContains('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']); |
@@ -247,14 +220,12 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
247 | $feedBuilder = new FeedBuilder( | 220 | $feedBuilder = new FeedBuilder( |
248 | self::$bookmarkService, | 221 | self::$bookmarkService, |
249 | self::$formatter, | 222 | self::$formatter, |
250 | FeedBuilder::$FEED_ATOM, | 223 | static::$serverInfo, |
251 | self::$serverInfo, | ||
252 | null, | ||
253 | false | 224 | false |
254 | ); | 225 | ); |
255 | $feedBuilder->setLocale(self::$LOCALE); | 226 | $feedBuilder->setLocale(self::$LOCALE); |
256 | $feedBuilder->setHideDates(true); | 227 | $feedBuilder->setHideDates(true); |
257 | $data = $feedBuilder->buildData(); | 228 | $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null); |
258 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); | 229 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); |
259 | $this->assertFalse($data['show_dates']); | 230 | $this->assertFalse($data['show_dates']); |
260 | 231 | ||
@@ -262,14 +233,12 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
262 | $feedBuilder = new FeedBuilder( | 233 | $feedBuilder = new FeedBuilder( |
263 | self::$bookmarkService, | 234 | self::$bookmarkService, |
264 | self::$formatter, | 235 | self::$formatter, |
265 | FeedBuilder::$FEED_ATOM, | 236 | static::$serverInfo, |
266 | self::$serverInfo, | ||
267 | null, | ||
268 | true | 237 | true |
269 | ); | 238 | ); |
270 | $feedBuilder->setLocale(self::$LOCALE); | 239 | $feedBuilder->setLocale(self::$LOCALE); |
271 | $feedBuilder->setHideDates(true); | 240 | $feedBuilder->setHideDates(true); |
272 | $data = $feedBuilder->buildData(); | 241 | $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null); |
273 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); | 242 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); |
274 | $this->assertTrue($data['show_dates']); | 243 | $this->assertTrue($data['show_dates']); |
275 | } | 244 | } |
@@ -289,13 +258,11 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
289 | $feedBuilder = new FeedBuilder( | 258 | $feedBuilder = new FeedBuilder( |
290 | self::$bookmarkService, | 259 | self::$bookmarkService, |
291 | self::$formatter, | 260 | self::$formatter, |
292 | FeedBuilder::$FEED_ATOM, | ||
293 | $serverInfo, | 261 | $serverInfo, |
294 | null, | ||
295 | false | 262 | false |
296 | ); | 263 | ); |
297 | $feedBuilder->setLocale(self::$LOCALE); | 264 | $feedBuilder->setLocale(self::$LOCALE); |
298 | $data = $feedBuilder->buildData(); | 265 | $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null); |
299 | 266 | ||
300 | $this->assertEquals( | 267 | $this->assertEquals( |
301 | 'http://host.tld:8080/~user/shaarli/index.php?do=feed', | 268 | 'http://host.tld:8080/~user/shaarli/index.php?do=feed', |
@@ -304,8 +271,8 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
304 | 271 | ||
305 | // Test first link (note link) | 272 | // Test first link (note link) |
306 | $link = $data['links'][array_keys($data['links'])[2]]; | 273 | $link = $data['links'][array_keys($data['links'])[2]]; |
307 | $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['guid']); | 274 | $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['guid']); |
308 | $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['url']); | 275 | $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['url']); |
309 | $this->assertContains('http://host.tld:8080/~user/shaarli/?addtag=hashtag', $link['description']); | 276 | $this->assertContains('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']); |
310 | } | 277 | } |
311 | } | 278 | } |