diff options
Diffstat (limited to 'tests/feed/FeedBuilderTest.php')
-rw-r--r-- | tests/feed/FeedBuilderTest.php | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/tests/feed/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php index 5c2aaedb..c29e8ef3 100644 --- a/tests/feed/FeedBuilderTest.php +++ b/tests/feed/FeedBuilderTest.php | |||
@@ -10,13 +10,14 @@ use Shaarli\Bookmark\LinkDB; | |||
10 | use Shaarli\Config\ConfigManager; | 10 | use Shaarli\Config\ConfigManager; |
11 | use Shaarli\Formatter\FormatterFactory; | 11 | use Shaarli\Formatter\FormatterFactory; |
12 | use Shaarli\History; | 12 | use Shaarli\History; |
13 | use Shaarli\TestCase; | ||
13 | 14 | ||
14 | /** | 15 | /** |
15 | * FeedBuilderTest class. | 16 | * FeedBuilderTest class. |
16 | * | 17 | * |
17 | * Unit tests for FeedBuilder. | 18 | * Unit tests for FeedBuilder. |
18 | */ | 19 | */ |
19 | class FeedBuilderTest extends \PHPUnit\Framework\TestCase | 20 | class FeedBuilderTest extends TestCase |
20 | { | 21 | { |
21 | /** | 22 | /** |
22 | * @var string locale Basque (Spain). | 23 | * @var string locale Basque (Spain). |
@@ -44,7 +45,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
44 | /** | 45 | /** |
45 | * Called before every test method. | 46 | * Called before every test method. |
46 | */ | 47 | */ |
47 | public static function setUpBeforeClass() | 48 | public static function setUpBeforeClass(): void |
48 | { | 49 | { |
49 | $conf = new ConfigManager('tests/utils/config/configJson'); | 50 | $conf = new ConfigManager('tests/utils/config/configJson'); |
50 | $conf->set('resource.datastore', self::$testDatastore); | 51 | $conf->set('resource.datastore', self::$testDatastore); |
@@ -60,7 +61,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
60 | 'SERVER_NAME' => 'host.tld', | 61 | 'SERVER_NAME' => 'host.tld', |
61 | 'SERVER_PORT' => '80', | 62 | 'SERVER_PORT' => '80', |
62 | 'SCRIPT_NAME' => '/index.php', | 63 | 'SCRIPT_NAME' => '/index.php', |
63 | 'REQUEST_URI' => '/index.php?do=feed', | 64 | 'REQUEST_URI' => '/feed/atom', |
64 | ); | 65 | ); |
65 | } | 66 | } |
66 | 67 | ||
@@ -81,13 +82,13 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
81 | $this->assertEquals(self::$RSS_LANGUAGE, $data['language']); | 82 | $this->assertEquals(self::$RSS_LANGUAGE, $data['language']); |
82 | $this->assertRegExp('/Wed, 03 Aug 2016 09:30:33 \+\d{4}/', $data['last_update']); | 83 | $this->assertRegExp('/Wed, 03 Aug 2016 09:30:33 \+\d{4}/', $data['last_update']); |
83 | $this->assertEquals(true, $data['show_dates']); | 84 | $this->assertEquals(true, $data['show_dates']); |
84 | $this->assertEquals('http://host.tld/index.php?do=feed', $data['self_link']); | 85 | $this->assertEquals('http://host.tld/feed/atom', $data['self_link']); |
85 | $this->assertEquals('http://host.tld/', $data['index_url']); | 86 | $this->assertEquals('http://host.tld/', $data['index_url']); |
86 | $this->assertFalse($data['usepermalinks']); | 87 | $this->assertFalse($data['usepermalinks']); |
87 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); | 88 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); |
88 | 89 | ||
89 | // Test first not pinned link (note link) | 90 | // Test first not pinned link (note link) |
90 | $link = $data['links'][array_keys($data['links'])[2]]; | 91 | $link = $data['links'][array_keys($data['links'])[0]]; |
91 | $this->assertEquals(41, $link['id']); | 92 | $this->assertEquals(41, $link['id']); |
92 | $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); | 93 | $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); |
93 | $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); | 94 | $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); |
@@ -96,9 +97,9 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
96 | $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']); | 97 | $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']); |
97 | $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); | 98 | $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); |
98 | $this->assertEquals($pub, $up); | 99 | $this->assertEquals($pub, $up); |
99 | $this->assertContains('Stallman has a beard', $link['description']); | 100 | $this->assertContainsPolyfill('Stallman has a beard', $link['description']); |
100 | $this->assertContains('Permalink', $link['description']); | 101 | $this->assertContainsPolyfill('Permalink', $link['description']); |
101 | $this->assertContains('http://host.tld/shaare/WDWyig', $link['description']); | 102 | $this->assertContainsPolyfill('http://host.tld/shaare/WDWyig', $link['description']); |
102 | $this->assertEquals(1, count($link['taglist'])); | 103 | $this->assertEquals(1, count($link['taglist'])); |
103 | $this->assertEquals('sTuff', $link['taglist'][0]); | 104 | $this->assertEquals('sTuff', $link['taglist'][0]); |
104 | 105 | ||
@@ -128,7 +129,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
128 | $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null); | 129 | $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null); |
129 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); | 130 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); |
130 | $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']); | 131 | $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']); |
131 | $link = $data['links'][array_keys($data['links'])[2]]; | 132 | $link = $data['links'][array_keys($data['links'])[0]]; |
132 | $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']); | 133 | $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']); |
133 | $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']); | 134 | $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']); |
134 | } | 135 | } |
@@ -173,7 +174,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
173 | $feedBuilder->setLocale(self::$LOCALE); | 174 | $feedBuilder->setLocale(self::$LOCALE); |
174 | $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, $criteria); | 175 | $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, $criteria); |
175 | $this->assertEquals(3, count($data['links'])); | 176 | $this->assertEquals(3, count($data['links'])); |
176 | $link = $data['links'][array_keys($data['links'])[2]]; | 177 | $link = $data['links'][array_keys($data['links'])[0]]; |
177 | $this->assertEquals(41, $link['id']); | 178 | $this->assertEquals(41, $link['id']); |
178 | $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); | 179 | $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); |
179 | } | 180 | } |
@@ -195,21 +196,21 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
195 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); | 196 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); |
196 | $this->assertTrue($data['usepermalinks']); | 197 | $this->assertTrue($data['usepermalinks']); |
197 | // First link is a permalink | 198 | // First link is a permalink |
198 | $link = $data['links'][array_keys($data['links'])[2]]; | 199 | $link = $data['links'][array_keys($data['links'])[0]]; |
199 | $this->assertEquals(41, $link['id']); | 200 | $this->assertEquals(41, $link['id']); |
200 | $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); | 201 | $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); |
201 | $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); | 202 | $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); |
202 | $this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']); | 203 | $this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']); |
203 | $this->assertContains('Direct link', $link['description']); | 204 | $this->assertContainsPolyfill('Direct link', $link['description']); |
204 | $this->assertContains('http://host.tld/shaare/WDWyig', $link['description']); | 205 | $this->assertContainsPolyfill('http://host.tld/shaare/WDWyig', $link['description']); |
205 | // Second link is a direct link | 206 | // Second link is a direct link |
206 | $link = $data['links'][array_keys($data['links'])[3]]; | 207 | $link = $data['links'][array_keys($data['links'])[1]]; |
207 | $this->assertEquals(8, $link['id']); | 208 | $this->assertEquals(8, $link['id']); |
208 | $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']); | 209 | $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']); |
209 | $this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']); | 210 | $this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']); |
210 | $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']); | 211 | $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']); |
211 | $this->assertContains('Direct link', $link['description']); | 212 | $this->assertContainsPolyfill('Direct link', $link['description']); |
212 | $this->assertContains('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']); | 213 | $this->assertContainsPolyfill('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']); |
213 | } | 214 | } |
214 | 215 | ||
215 | /** | 216 | /** |
@@ -253,7 +254,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
253 | 'SERVER_NAME' => 'host.tld', | 254 | 'SERVER_NAME' => 'host.tld', |
254 | 'SERVER_PORT' => '8080', | 255 | 'SERVER_PORT' => '8080', |
255 | 'SCRIPT_NAME' => '/~user/shaarli/index.php', | 256 | 'SCRIPT_NAME' => '/~user/shaarli/index.php', |
256 | 'REQUEST_URI' => '/~user/shaarli/index.php?do=feed', | 257 | 'REQUEST_URI' => '/~user/shaarli/feed/atom', |
257 | ); | 258 | ); |
258 | $feedBuilder = new FeedBuilder( | 259 | $feedBuilder = new FeedBuilder( |
259 | self::$bookmarkService, | 260 | self::$bookmarkService, |
@@ -265,14 +266,14 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
265 | $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null); | 266 | $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null); |
266 | 267 | ||
267 | $this->assertEquals( | 268 | $this->assertEquals( |
268 | 'http://host.tld:8080/~user/shaarli/index.php?do=feed', | 269 | 'http://host.tld:8080/~user/shaarli/feed/atom', |
269 | $data['self_link'] | 270 | $data['self_link'] |
270 | ); | 271 | ); |
271 | 272 | ||
272 | // Test first link (note link) | 273 | // Test first link (note link) |
273 | $link = $data['links'][array_keys($data['links'])[2]]; | 274 | $link = $data['links'][array_keys($data['links'])[0]]; |
274 | $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['guid']); | 275 | $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['guid']); |
275 | $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['url']); | 276 | $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['url']); |
276 | $this->assertContains('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']); | 277 | $this->assertContainsPolyfill('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']); |
277 | } | 278 | } |
278 | } | 279 | } |