aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/feed
diff options
context:
space:
mode:
Diffstat (limited to 'tests/feed')
-rw-r--r--tests/feed/CacheTest.php92
-rw-r--r--tests/feed/CachedPageTest.php13
-rw-r--r--tests/feed/FeedBuilderTest.php171
3 files changed, 108 insertions, 168 deletions
diff --git a/tests/feed/CacheTest.php b/tests/feed/CacheTest.php
deleted file mode 100644
index c0a9f26f..00000000
--- a/tests/feed/CacheTest.php
+++ /dev/null
@@ -1,92 +0,0 @@
1<?php
2/**
3 * Cache tests
4 */
5namespace Shaarli\Feed;
6
7// required to access $_SESSION array
8session_start();
9
10require_once 'application/feed/Cache.php';
11
12/**
13 * Unitary tests for cached pages
14 */
15class CacheTest extends \PHPUnit\Framework\TestCase
16{
17 // test cache directory
18 protected static $testCacheDir = 'sandbox/dummycache';
19
20 // dummy cached file names / content
21 protected static $pages = array('a', 'toto', 'd7b59c');
22
23
24 /**
25 * Populate the cache with dummy files
26 */
27 public function setUp()
28 {
29 if (!is_dir(self::$testCacheDir)) {
30 mkdir(self::$testCacheDir);
31 } else {
32 array_map('unlink', glob(self::$testCacheDir . '/*'));
33 }
34
35 foreach (self::$pages as $page) {
36 file_put_contents(self::$testCacheDir . '/' . $page . '.cache', $page);
37 }
38 file_put_contents(self::$testCacheDir . '/intru.der', 'ShouldNotBeThere');
39 }
40
41 /**
42 * Remove dummycache folder after each tests.
43 */
44 public function tearDown()
45 {
46 array_map('unlink', glob(self::$testCacheDir . '/*'));
47 rmdir(self::$testCacheDir);
48 }
49
50 /**
51 * Purge cached pages
52 */
53 public function testPurgeCachedPages()
54 {
55 purgeCachedPages(self::$testCacheDir);
56 foreach (self::$pages as $page) {
57 $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
58 }
59
60 $this->assertFileExists(self::$testCacheDir . '/intru.der');
61 }
62
63 /**
64 * Purge cached pages - missing directory
65 */
66 public function testPurgeCachedPagesMissingDir()
67 {
68 $oldlog = ini_get('error_log');
69 ini_set('error_log', '/dev/null');
70 $this->assertEquals(
71 'Cannot purge sandbox/dummycache_missing: no directory',
72 purgeCachedPages(self::$testCacheDir . '_missing')
73 );
74 ini_set('error_log', $oldlog);
75 }
76
77 /**
78 * Purge cached pages and session cache
79 */
80 public function testInvalidateCaches()
81 {
82 $this->assertArrayNotHasKey('tags', $_SESSION);
83 $_SESSION['tags'] = array('goodbye', 'cruel', 'world');
84
85 invalidateCaches(self::$testCacheDir);
86 foreach (self::$pages as $page) {
87 $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
88 }
89
90 $this->assertArrayNotHasKey('tags', $_SESSION);
91 }
92}
diff --git a/tests/feed/CachedPageTest.php b/tests/feed/CachedPageTest.php
index 0bcc1442..904db9dc 100644
--- a/tests/feed/CachedPageTest.php
+++ b/tests/feed/CachedPageTest.php
@@ -7,17 +7,17 @@ namespace Shaarli\Feed;
7/** 7/**
8 * Unitary tests for cached pages 8 * Unitary tests for cached pages
9 */ 9 */
10class CachedPageTest extends \PHPUnit\Framework\TestCase 10class CachedPageTest extends \Shaarli\TestCase
11{ 11{
12 // test cache directory 12 // test cache directory
13 protected static $testCacheDir = 'sandbox/pagecache'; 13 protected static $testCacheDir = 'sandbox/pagecache';
14 protected static $url = 'http://shaar.li/?do=atom'; 14 protected static $url = 'http://shaar.li/feed/atom';
15 protected static $filename; 15 protected static $filename;
16 16
17 /** 17 /**
18 * Create the cache directory if needed 18 * Create the cache directory if needed
19 */ 19 */
20 public static function setUpBeforeClass() 20 public static function setUpBeforeClass(): void
21 { 21 {
22 if (!is_dir(self::$testCacheDir)) { 22 if (!is_dir(self::$testCacheDir)) {
23 mkdir(self::$testCacheDir); 23 mkdir(self::$testCacheDir);
@@ -28,7 +28,7 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase
28 /** 28 /**
29 * Reset the page cache 29 * Reset the page cache
30 */ 30 */
31 public function setUp() 31 protected function setUp(): void
32 { 32 {
33 if (file_exists(self::$filename)) { 33 if (file_exists(self::$filename)) {
34 unlink(self::$filename); 34 unlink(self::$filename);
@@ -42,8 +42,9 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase
42 { 42 {
43 new CachedPage(self::$testCacheDir, '', true); 43 new CachedPage(self::$testCacheDir, '', true);
44 new CachedPage(self::$testCacheDir, '', false); 44 new CachedPage(self::$testCacheDir, '', false);
45 new CachedPage(self::$testCacheDir, 'http://shaar.li/?do=rss', true); 45 new CachedPage(self::$testCacheDir, 'http://shaar.li/feed/rss', true);
46 new CachedPage(self::$testCacheDir, 'http://shaar.li/?do=atom', false); 46 new CachedPage(self::$testCacheDir, 'http://shaar.li/feed/atom', false);
47 $this->addToAssertionCount(1);
47 } 48 }
48 49
49 /** 50 /**
diff --git a/tests/feed/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php
index b496cb4c..c29e8ef3 100644
--- a/tests/feed/FeedBuilderTest.php
+++ b/tests/feed/FeedBuilderTest.php
@@ -4,14 +4,20 @@ namespace Shaarli\Feed;
4 4
5use DateTime; 5use DateTime;
6use ReferenceLinkDB; 6use ReferenceLinkDB;
7use Shaarli\Bookmark\Bookmark;
8use Shaarli\Bookmark\BookmarkFileService;
7use Shaarli\Bookmark\LinkDB; 9use Shaarli\Bookmark\LinkDB;
10use Shaarli\Config\ConfigManager;
11use Shaarli\Formatter\FormatterFactory;
12use Shaarli\History;
13use Shaarli\TestCase;
8 14
9/** 15/**
10 * FeedBuilderTest class. 16 * FeedBuilderTest class.
11 * 17 *
12 * Unit tests for FeedBuilder. 18 * Unit tests for FeedBuilder.
13 */ 19 */
14class FeedBuilderTest extends \PHPUnit\Framework\TestCase 20class FeedBuilderTest extends TestCase
15{ 21{
16 /** 22 /**
17 * @var string locale Basque (Spain). 23 * @var string locale Basque (Spain).
@@ -30,74 +36,70 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
30 36
31 protected static $testDatastore = 'sandbox/datastore.php'; 37 protected static $testDatastore = 'sandbox/datastore.php';
32 38
33 public static $linkDB; 39 public static $bookmarkService;
40
41 public static $formatter;
34 42
35 public static $serverInfo; 43 public static $serverInfo;
36 44
37 /** 45 /**
38 * Called before every test method. 46 * Called before every test method.
39 */ 47 */
40 public static function setUpBeforeClass() 48 public static function setUpBeforeClass(): void
41 { 49 {
42 $refLinkDB = new ReferenceLinkDB(); 50 $conf = new ConfigManager('tests/utils/config/configJson');
51 $conf->set('resource.datastore', self::$testDatastore);
52 $refLinkDB = new \ReferenceLinkDB();
43 $refLinkDB->write(self::$testDatastore); 53 $refLinkDB->write(self::$testDatastore);
44 self::$linkDB = new LinkDB(self::$testDatastore, true, false); 54 $history = new History('sandbox/history.php');
55 $factory = new FormatterFactory($conf, true);
56 self::$formatter = $factory->getFormatter();
57 self::$bookmarkService = new BookmarkFileService($conf, $history, true);
58
45 self::$serverInfo = array( 59 self::$serverInfo = array(
46 'HTTPS' => 'Off', 60 'HTTPS' => 'Off',
47 'SERVER_NAME' => 'host.tld', 61 'SERVER_NAME' => 'host.tld',
48 'SERVER_PORT' => '80', 62 'SERVER_PORT' => '80',
49 'SCRIPT_NAME' => '/index.php', 63 'SCRIPT_NAME' => '/index.php',
50 'REQUEST_URI' => '/index.php?do=feed', 64 'REQUEST_URI' => '/feed/atom',
51 ); 65 );
52 } 66 }
53 67
54 /** 68 /**
55 * Test GetTypeLanguage().
56 */
57 public function testGetTypeLanguage()
58 {
59 $feedBuilder = new FeedBuilder(null, FeedBuilder::$FEED_ATOM, null, null, false);
60 $feedBuilder->setLocale(self::$LOCALE);
61 $this->assertEquals(self::$ATOM_LANGUAGUE, $feedBuilder->getTypeLanguage());
62 $feedBuilder = new FeedBuilder(null, FeedBuilder::$FEED_RSS, null, null, false);
63 $feedBuilder->setLocale(self::$LOCALE);
64 $this->assertEquals(self::$RSS_LANGUAGE, $feedBuilder->getTypeLanguage());
65 $feedBuilder = new FeedBuilder(null, FeedBuilder::$FEED_ATOM, null, null, false);
66 $this->assertEquals('en', $feedBuilder->getTypeLanguage());
67 $feedBuilder = new FeedBuilder(null, FeedBuilder::$FEED_RSS, null, null, false);
68 $this->assertEquals('en-en', $feedBuilder->getTypeLanguage());
69 }
70
71 /**
72 * Test buildData with RSS feed. 69 * Test buildData with RSS feed.
73 */ 70 */
74 public function testRSSBuildData() 71 public function testRSSBuildData()
75 { 72 {
76 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_RSS, self::$serverInfo, null, false); 73 $feedBuilder = new FeedBuilder(
74 self::$bookmarkService,
75 self::$formatter,
76 static::$serverInfo,
77 false
78 );
77 $feedBuilder->setLocale(self::$LOCALE); 79 $feedBuilder->setLocale(self::$LOCALE);
78 $data = $feedBuilder->buildData(); 80 $data = $feedBuilder->buildData(FeedBuilder::$FEED_RSS, null);
79 // Test headers (RSS) 81 // Test headers (RSS)
80 $this->assertEquals(self::$RSS_LANGUAGE, $data['language']); 82 $this->assertEquals(self::$RSS_LANGUAGE, $data['language']);
81 $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']);
82 $this->assertEquals(true, $data['show_dates']); 84 $this->assertEquals(true, $data['show_dates']);
83 $this->assertEquals('http://host.tld/index.php?do=feed', $data['self_link']); 85 $this->assertEquals('http://host.tld/feed/atom', $data['self_link']);
84 $this->assertEquals('http://host.tld/', $data['index_url']); 86 $this->assertEquals('http://host.tld/', $data['index_url']);
85 $this->assertFalse($data['usepermalinks']); 87 $this->assertFalse($data['usepermalinks']);
86 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 88 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
87 89
88 // Test first not pinned link (note link) 90 // Test first not pinned link (note link)
89 $link = $data['links'][array_keys($data['links'])[2]]; 91 $link = $data['links'][array_keys($data['links'])[0]];
90 $this->assertEquals(41, $link['id']); 92 $this->assertEquals(41, $link['id']);
91 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 93 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
92 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); 94 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']);
93 $this->assertEquals('http://host.tld/?WDWyig', $link['url']); 95 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']);
94 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']); 96 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']);
95 $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']); 97 $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']);
96 $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); 98 $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']);
97 $this->assertEquals($pub, $up); 99 $this->assertEquals($pub, $up);
98 $this->assertContains('Stallman has a beard', $link['description']); 100 $this->assertContainsPolyfill('Stallman has a beard', $link['description']);
99 $this->assertContains('Permalink', $link['description']); 101 $this->assertContainsPolyfill('Permalink', $link['description']);
100 $this->assertContains('http://host.tld/?WDWyig', $link['description']); 102 $this->assertContainsPolyfill('http://host.tld/shaare/WDWyig', $link['description']);
101 $this->assertEquals(1, count($link['taglist'])); 103 $this->assertEquals(1, count($link['taglist']));
102 $this->assertEquals('sTuff', $link['taglist'][0]); 104 $this->assertEquals('sTuff', $link['taglist'][0]);
103 105
@@ -117,12 +119,17 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
117 */ 119 */
118 public function testAtomBuildData() 120 public function testAtomBuildData()
119 { 121 {
120 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, null, false); 122 $feedBuilder = new FeedBuilder(
123 self::$bookmarkService,
124 self::$formatter,
125 static::$serverInfo,
126 false
127 );
121 $feedBuilder->setLocale(self::$LOCALE); 128 $feedBuilder->setLocale(self::$LOCALE);
122 $data = $feedBuilder->buildData(); 129 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null);
123 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 130 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
124 $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']);
125 $link = $data['links'][array_keys($data['links'])[2]]; 132 $link = $data['links'][array_keys($data['links'])[0]];
126 $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']);
127 $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']);
128 } 135 }
@@ -136,13 +143,18 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
136 'searchtags' => 'stuff', 143 'searchtags' => 'stuff',
137 'searchterm' => 'beard', 144 'searchterm' => 'beard',
138 ); 145 );
139 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, $criteria, false); 146 $feedBuilder = new FeedBuilder(
147 self::$bookmarkService,
148 self::$formatter,
149 static::$serverInfo,
150 false
151 );
140 $feedBuilder->setLocale(self::$LOCALE); 152 $feedBuilder->setLocale(self::$LOCALE);
141 $data = $feedBuilder->buildData(); 153 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, $criteria);
142 $this->assertEquals(1, count($data['links'])); 154 $this->assertEquals(1, count($data['links']));
143 $link = array_shift($data['links']); 155 $link = array_shift($data['links']);
144 $this->assertEquals(41, $link['id']); 156 $this->assertEquals(41, $link['id']);
145 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 157 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
146 } 158 }
147 159
148 /** 160 /**
@@ -153,13 +165,18 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
153 $criteria = array( 165 $criteria = array(
154 'nb' => '3', 166 'nb' => '3',
155 ); 167 );
156 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, $criteria, false); 168 $feedBuilder = new FeedBuilder(
169 self::$bookmarkService,
170 self::$formatter,
171 static::$serverInfo,
172 false
173 );
157 $feedBuilder->setLocale(self::$LOCALE); 174 $feedBuilder->setLocale(self::$LOCALE);
158 $data = $feedBuilder->buildData(); 175 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, $criteria);
159 $this->assertEquals(3, count($data['links'])); 176 $this->assertEquals(3, count($data['links']));
160 $link = $data['links'][array_keys($data['links'])[2]]; 177 $link = $data['links'][array_keys($data['links'])[0]];
161 $this->assertEquals(41, $link['id']); 178 $this->assertEquals(41, $link['id']);
162 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 179 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
163 } 180 }
164 181
165 /** 182 /**
@@ -167,28 +184,33 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
167 */ 184 */
168 public function testBuildDataPermalinks() 185 public function testBuildDataPermalinks()
169 { 186 {
170 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, null, false); 187 $feedBuilder = new FeedBuilder(
188 self::$bookmarkService,
189 self::$formatter,
190 static::$serverInfo,
191 false
192 );
171 $feedBuilder->setLocale(self::$LOCALE); 193 $feedBuilder->setLocale(self::$LOCALE);
172 $feedBuilder->setUsePermalinks(true); 194 $feedBuilder->setUsePermalinks(true);
173 $data = $feedBuilder->buildData(); 195 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null);
174 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 196 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
175 $this->assertTrue($data['usepermalinks']); 197 $this->assertTrue($data['usepermalinks']);
176 // First link is a permalink 198 // First link is a permalink
177 $link = $data['links'][array_keys($data['links'])[2]]; 199 $link = $data['links'][array_keys($data['links'])[0]];
178 $this->assertEquals(41, $link['id']); 200 $this->assertEquals(41, $link['id']);
179 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 201 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
180 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); 202 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']);
181 $this->assertEquals('http://host.tld/?WDWyig', $link['url']); 203 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']);
182 $this->assertContains('Direct link', $link['description']); 204 $this->assertContainsPolyfill('Direct link', $link['description']);
183 $this->assertContains('http://host.tld/?WDWyig', $link['description']); 205 $this->assertContainsPolyfill('http://host.tld/shaare/WDWyig', $link['description']);
184 // Second link is a direct link 206 // Second link is a direct link
185 $link = $data['links'][array_keys($data['links'])[3]]; 207 $link = $data['links'][array_keys($data['links'])[1]];
186 $this->assertEquals(8, $link['id']); 208 $this->assertEquals(8, $link['id']);
187 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114633'), $link['created']); 209 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']);
188 $this->assertEquals('http://host.tld/?RttfEw', $link['guid']); 210 $this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']);
189 $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']);
190 $this->assertContains('Direct link', $link['description']); 212 $this->assertContainsPolyfill('Direct link', $link['description']);
191 $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']);
192 } 214 }
193 215
194 /** 216 /**
@@ -196,18 +218,28 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
196 */ 218 */
197 public function testBuildDataHideDates() 219 public function testBuildDataHideDates()
198 { 220 {
199 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, null, false); 221 $feedBuilder = new FeedBuilder(
222 self::$bookmarkService,
223 self::$formatter,
224 static::$serverInfo,
225 false
226 );
200 $feedBuilder->setLocale(self::$LOCALE); 227 $feedBuilder->setLocale(self::$LOCALE);
201 $feedBuilder->setHideDates(true); 228 $feedBuilder->setHideDates(true);
202 $data = $feedBuilder->buildData(); 229 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null);
203 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 230 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
204 $this->assertFalse($data['show_dates']); 231 $this->assertFalse($data['show_dates']);
205 232
206 // Show dates while logged in 233 // Show dates while logged in
207 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, null, true); 234 $feedBuilder = new FeedBuilder(
235 self::$bookmarkService,
236 self::$formatter,
237 static::$serverInfo,
238 true
239 );
208 $feedBuilder->setLocale(self::$LOCALE); 240 $feedBuilder->setLocale(self::$LOCALE);
209 $feedBuilder->setHideDates(true); 241 $feedBuilder->setHideDates(true);
210 $data = $feedBuilder->buildData(); 242 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null);
211 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 243 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
212 $this->assertTrue($data['show_dates']); 244 $this->assertTrue($data['show_dates']);
213 } 245 }
@@ -222,27 +254,26 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
222 'SERVER_NAME' => 'host.tld', 254 'SERVER_NAME' => 'host.tld',
223 'SERVER_PORT' => '8080', 255 'SERVER_PORT' => '8080',
224 'SCRIPT_NAME' => '/~user/shaarli/index.php', 256 'SCRIPT_NAME' => '/~user/shaarli/index.php',
225 'REQUEST_URI' => '/~user/shaarli/index.php?do=feed', 257 'REQUEST_URI' => '/~user/shaarli/feed/atom',
226 ); 258 );
227 $feedBuilder = new FeedBuilder( 259 $feedBuilder = new FeedBuilder(
228 self::$linkDB, 260 self::$bookmarkService,
229 FeedBuilder::$FEED_ATOM, 261 self::$formatter,
230 $serverInfo, 262 $serverInfo,
231 null,
232 false 263 false
233 ); 264 );
234 $feedBuilder->setLocale(self::$LOCALE); 265 $feedBuilder->setLocale(self::$LOCALE);
235 $data = $feedBuilder->buildData(); 266 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null);
236 267
237 $this->assertEquals( 268 $this->assertEquals(
238 'http://host.tld:8080/~user/shaarli/index.php?do=feed', 269 'http://host.tld:8080/~user/shaarli/feed/atom',
239 $data['self_link'] 270 $data['self_link']
240 ); 271 );
241 272
242 // Test first link (note link) 273 // Test first link (note link)
243 $link = $data['links'][array_keys($data['links'])[2]]; 274 $link = $data['links'][array_keys($data['links'])[0]];
244 $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['guid']); 275 $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['guid']);
245 $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['url']); 276 $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['url']);
246 $this->assertContains('http://host.tld:8080/~user/shaarli/?addtag=hashtag', $link['description']); 277 $this->assertContainsPolyfill('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']);
247 } 278 }
248} 279}