aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/feed
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-01-17 21:34:12 +0100
committerArthurHoaro <arthur@hoa.ro>2020-01-18 09:56:32 +0100
commite26e2060f5470ce8bf4c5973284bae07b8af170a (patch)
treeadf8512f93f5559ba87d0c9931969ae4ebea7133 /tests/feed
parentcf92b4dd1521241eefc58eaf6dcd202cd83969d8 (diff)
downloadShaarli-e26e2060f5470ce8bf4c5973284bae07b8af170a.tar.gz
Shaarli-e26e2060f5470ce8bf4c5973284bae07b8af170a.tar.zst
Shaarli-e26e2060f5470ce8bf4c5973284bae07b8af170a.zip
Add and update unit test for the new system (Bookmark + Service)
See #1307
Diffstat (limited to 'tests/feed')
-rw-r--r--tests/feed/FeedBuilderTest.php103
1 files changed, 83 insertions, 20 deletions
diff --git a/tests/feed/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php
index b496cb4c..a43ff672 100644
--- a/tests/feed/FeedBuilderTest.php
+++ b/tests/feed/FeedBuilderTest.php
@@ -4,7 +4,12 @@ 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;
8 13
9/** 14/**
10 * FeedBuilderTest class. 15 * FeedBuilderTest class.
@@ -30,7 +35,9 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
30 35
31 protected static $testDatastore = 'sandbox/datastore.php'; 36 protected static $testDatastore = 'sandbox/datastore.php';
32 37
33 public static $linkDB; 38 public static $bookmarkService;
39
40 public static $formatter;
34 41
35 public static $serverInfo; 42 public static $serverInfo;
36 43
@@ -39,9 +46,15 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
39 */ 46 */
40 public static function setUpBeforeClass() 47 public static function setUpBeforeClass()
41 { 48 {
42 $refLinkDB = new ReferenceLinkDB(); 49 $conf = new ConfigManager('tests/utils/config/configJson');
50 $conf->set('resource.datastore', self::$testDatastore);
51 $refLinkDB = new \ReferenceLinkDB();
43 $refLinkDB->write(self::$testDatastore); 52 $refLinkDB->write(self::$testDatastore);
44 self::$linkDB = new LinkDB(self::$testDatastore, true, false); 53 $history = new History('sandbox/history.php');
54 $factory = new FormatterFactory($conf);
55 self::$formatter = $factory->getFormatter();
56 self::$bookmarkService = new BookmarkFileService($conf, $history, true);
57
45 self::$serverInfo = array( 58 self::$serverInfo = array(
46 'HTTPS' => 'Off', 59 'HTTPS' => 'Off',
47 'SERVER_NAME' => 'host.tld', 60 'SERVER_NAME' => 'host.tld',
@@ -56,15 +69,15 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
56 */ 69 */
57 public function testGetTypeLanguage() 70 public function testGetTypeLanguage()
58 { 71 {
59 $feedBuilder = new FeedBuilder(null, FeedBuilder::$FEED_ATOM, null, null, false); 72 $feedBuilder = new FeedBuilder(null, self::$formatter, FeedBuilder::$FEED_ATOM, null, null, false);
60 $feedBuilder->setLocale(self::$LOCALE); 73 $feedBuilder->setLocale(self::$LOCALE);
61 $this->assertEquals(self::$ATOM_LANGUAGUE, $feedBuilder->getTypeLanguage()); 74 $this->assertEquals(self::$ATOM_LANGUAGUE, $feedBuilder->getTypeLanguage());
62 $feedBuilder = new FeedBuilder(null, FeedBuilder::$FEED_RSS, null, null, false); 75 $feedBuilder = new FeedBuilder(null, self::$formatter, FeedBuilder::$FEED_RSS, null, null, false);
63 $feedBuilder->setLocale(self::$LOCALE); 76 $feedBuilder->setLocale(self::$LOCALE);
64 $this->assertEquals(self::$RSS_LANGUAGE, $feedBuilder->getTypeLanguage()); 77 $this->assertEquals(self::$RSS_LANGUAGE, $feedBuilder->getTypeLanguage());
65 $feedBuilder = new FeedBuilder(null, FeedBuilder::$FEED_ATOM, null, null, false); 78 $feedBuilder = new FeedBuilder(null, self::$formatter, FeedBuilder::$FEED_ATOM, null, null, false);
66 $this->assertEquals('en', $feedBuilder->getTypeLanguage()); 79 $this->assertEquals('en', $feedBuilder->getTypeLanguage());
67 $feedBuilder = new FeedBuilder(null, FeedBuilder::$FEED_RSS, null, null, false); 80 $feedBuilder = new FeedBuilder(null, self::$formatter, FeedBuilder::$FEED_RSS, null, null, false);
68 $this->assertEquals('en-en', $feedBuilder->getTypeLanguage()); 81 $this->assertEquals('en-en', $feedBuilder->getTypeLanguage());
69 } 82 }
70 83
@@ -73,7 +86,14 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
73 */ 86 */
74 public function testRSSBuildData() 87 public function testRSSBuildData()
75 { 88 {
76 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_RSS, self::$serverInfo, null, false); 89 $feedBuilder = new FeedBuilder(
90 self::$bookmarkService,
91 self::$formatter,
92 FeedBuilder::$FEED_RSS,
93 self::$serverInfo,
94 null,
95 false
96 );
77 $feedBuilder->setLocale(self::$LOCALE); 97 $feedBuilder->setLocale(self::$LOCALE);
78 $data = $feedBuilder->buildData(); 98 $data = $feedBuilder->buildData();
79 // Test headers (RSS) 99 // Test headers (RSS)
@@ -88,7 +108,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
88 // Test first not pinned link (note link) 108 // Test first not pinned link (note link)
89 $link = $data['links'][array_keys($data['links'])[2]]; 109 $link = $data['links'][array_keys($data['links'])[2]];
90 $this->assertEquals(41, $link['id']); 110 $this->assertEquals(41, $link['id']);
91 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 111 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
92 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); 112 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
93 $this->assertEquals('http://host.tld/?WDWyig', $link['url']); 113 $this->assertEquals('http://host.tld/?WDWyig', $link['url']);
94 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']); 114 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']);
@@ -117,7 +137,14 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
117 */ 137 */
118 public function testAtomBuildData() 138 public function testAtomBuildData()
119 { 139 {
120 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, null, false); 140 $feedBuilder = new FeedBuilder(
141 self::$bookmarkService,
142 self::$formatter,
143 FeedBuilder::$FEED_ATOM,
144 self::$serverInfo,
145 null,
146 false
147 );
121 $feedBuilder->setLocale(self::$LOCALE); 148 $feedBuilder->setLocale(self::$LOCALE);
122 $data = $feedBuilder->buildData(); 149 $data = $feedBuilder->buildData();
123 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 150 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
@@ -136,13 +163,20 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
136 'searchtags' => 'stuff', 163 'searchtags' => 'stuff',
137 'searchterm' => 'beard', 164 'searchterm' => 'beard',
138 ); 165 );
139 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, $criteria, false); 166 $feedBuilder = new FeedBuilder(
167 self::$bookmarkService,
168 self::$formatter,
169 FeedBuilder::$FEED_ATOM,
170 self::$serverInfo,
171 $criteria,
172 false
173 );
140 $feedBuilder->setLocale(self::$LOCALE); 174 $feedBuilder->setLocale(self::$LOCALE);
141 $data = $feedBuilder->buildData(); 175 $data = $feedBuilder->buildData();
142 $this->assertEquals(1, count($data['links'])); 176 $this->assertEquals(1, count($data['links']));
143 $link = array_shift($data['links']); 177 $link = array_shift($data['links']);
144 $this->assertEquals(41, $link['id']); 178 $this->assertEquals(41, $link['id']);
145 $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']);
146 } 180 }
147 181
148 /** 182 /**
@@ -153,13 +187,20 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
153 $criteria = array( 187 $criteria = array(
154 'nb' => '3', 188 'nb' => '3',
155 ); 189 );
156 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, $criteria, false); 190 $feedBuilder = new FeedBuilder(
191 self::$bookmarkService,
192 self::$formatter,
193 FeedBuilder::$FEED_ATOM,
194 self::$serverInfo,
195 $criteria,
196 false
197 );
157 $feedBuilder->setLocale(self::$LOCALE); 198 $feedBuilder->setLocale(self::$LOCALE);
158 $data = $feedBuilder->buildData(); 199 $data = $feedBuilder->buildData();
159 $this->assertEquals(3, count($data['links'])); 200 $this->assertEquals(3, count($data['links']));
160 $link = $data['links'][array_keys($data['links'])[2]]; 201 $link = $data['links'][array_keys($data['links'])[2]];
161 $this->assertEquals(41, $link['id']); 202 $this->assertEquals(41, $link['id']);
162 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 203 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
163 } 204 }
164 205
165 /** 206 /**
@@ -167,7 +208,14 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
167 */ 208 */
168 public function testBuildDataPermalinks() 209 public function testBuildDataPermalinks()
169 { 210 {
170 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, null, false); 211 $feedBuilder = new FeedBuilder(
212 self::$bookmarkService,
213 self::$formatter,
214 FeedBuilder::$FEED_ATOM,
215 self::$serverInfo,
216 null,
217 false
218 );
171 $feedBuilder->setLocale(self::$LOCALE); 219 $feedBuilder->setLocale(self::$LOCALE);
172 $feedBuilder->setUsePermalinks(true); 220 $feedBuilder->setUsePermalinks(true);
173 $data = $feedBuilder->buildData(); 221 $data = $feedBuilder->buildData();
@@ -176,7 +224,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
176 // First link is a permalink 224 // First link is a permalink
177 $link = $data['links'][array_keys($data['links'])[2]]; 225 $link = $data['links'][array_keys($data['links'])[2]];
178 $this->assertEquals(41, $link['id']); 226 $this->assertEquals(41, $link['id']);
179 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 227 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
180 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); 228 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
181 $this->assertEquals('http://host.tld/?WDWyig', $link['url']); 229 $this->assertEquals('http://host.tld/?WDWyig', $link['url']);
182 $this->assertContains('Direct link', $link['description']); 230 $this->assertContains('Direct link', $link['description']);
@@ -184,7 +232,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
184 // Second link is a direct link 232 // Second link is a direct link
185 $link = $data['links'][array_keys($data['links'])[3]]; 233 $link = $data['links'][array_keys($data['links'])[3]];
186 $this->assertEquals(8, $link['id']); 234 $this->assertEquals(8, $link['id']);
187 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114633'), $link['created']); 235 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']);
188 $this->assertEquals('http://host.tld/?RttfEw', $link['guid']); 236 $this->assertEquals('http://host.tld/?RttfEw', $link['guid']);
189 $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']); 237 $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']);
190 $this->assertContains('Direct link', $link['description']); 238 $this->assertContains('Direct link', $link['description']);
@@ -196,7 +244,14 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
196 */ 244 */
197 public function testBuildDataHideDates() 245 public function testBuildDataHideDates()
198 { 246 {
199 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, null, false); 247 $feedBuilder = new FeedBuilder(
248 self::$bookmarkService,
249 self::$formatter,
250 FeedBuilder::$FEED_ATOM,
251 self::$serverInfo,
252 null,
253 false
254 );
200 $feedBuilder->setLocale(self::$LOCALE); 255 $feedBuilder->setLocale(self::$LOCALE);
201 $feedBuilder->setHideDates(true); 256 $feedBuilder->setHideDates(true);
202 $data = $feedBuilder->buildData(); 257 $data = $feedBuilder->buildData();
@@ -204,7 +259,14 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
204 $this->assertFalse($data['show_dates']); 259 $this->assertFalse($data['show_dates']);
205 260
206 // Show dates while logged in 261 // Show dates while logged in
207 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, null, true); 262 $feedBuilder = new FeedBuilder(
263 self::$bookmarkService,
264 self::$formatter,
265 FeedBuilder::$FEED_ATOM,
266 self::$serverInfo,
267 null,
268 true
269 );
208 $feedBuilder->setLocale(self::$LOCALE); 270 $feedBuilder->setLocale(self::$LOCALE);
209 $feedBuilder->setHideDates(true); 271 $feedBuilder->setHideDates(true);
210 $data = $feedBuilder->buildData(); 272 $data = $feedBuilder->buildData();
@@ -225,7 +287,8 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
225 'REQUEST_URI' => '/~user/shaarli/index.php?do=feed', 287 'REQUEST_URI' => '/~user/shaarli/index.php?do=feed',
226 ); 288 );
227 $feedBuilder = new FeedBuilder( 289 $feedBuilder = new FeedBuilder(
228 self::$linkDB, 290 self::$bookmarkService,
291 self::$formatter,
229 FeedBuilder::$FEED_ATOM, 292 FeedBuilder::$FEED_ATOM,
230 $serverInfo, 293 $serverInfo,
231 null, 294 null,