diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-05-18 13:03:13 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-07-23 21:19:21 +0200 |
commit | f4929b1188b4bc5e92b925ebc44f5ad40bb1a4ed (patch) | |
tree | 63c83dc7b5e4663f8e976485f0478eb37b0f77b6 | |
parent | c56a540c6ef211cd9cb0189ba09911bb77696f28 (diff) | |
download | Shaarli-f4929b1188b4bc5e92b925ebc44f5ad40bb1a4ed.tar.gz Shaarli-f4929b1188b4bc5e92b925ebc44f5ad40bb1a4ed.tar.zst Shaarli-f4929b1188b4bc5e92b925ebc44f5ad40bb1a4ed.zip |
Make FeedBuilder instance creation independant of the request stack
-rw-r--r-- | application/feed/FeedBuilder.php | 139 | ||||
-rw-r--r-- | index.php | 4 | ||||
-rw-r--r-- | tests/feed/FeedBuilderTest.php | 63 |
3 files changed, 82 insertions, 124 deletions
diff --git a/application/feed/FeedBuilder.php b/application/feed/FeedBuilder.php index 40bd4f15..bcf27c2c 100644 --- a/application/feed/FeedBuilder.php +++ b/application/feed/FeedBuilder.php | |||
@@ -43,22 +43,10 @@ class FeedBuilder | |||
43 | */ | 43 | */ |
44 | protected $formatter; | 44 | protected $formatter; |
45 | 45 | ||
46 | /** | 46 | /** @var mixed[] $_SERVER */ |
47 | * @var string RSS or ATOM feed. | ||
48 | */ | ||
49 | protected $feedType; | ||
50 | |||
51 | /** | ||
52 | * @var array $_SERVER | ||
53 | */ | ||
54 | protected $serverInfo; | 47 | protected $serverInfo; |
55 | 48 | ||
56 | /** | 49 | /** |
57 | * @var array $_GET | ||
58 | */ | ||
59 | protected $userInput; | ||
60 | |||
61 | /** | ||
62 | * @var boolean True if the user is currently logged in, false otherwise. | 50 | * @var boolean True if the user is currently logged in, false otherwise. |
63 | */ | 51 | */ |
64 | protected $isLoggedIn; | 52 | protected $isLoggedIn; |
@@ -77,7 +65,6 @@ class FeedBuilder | |||
77 | * @var string server locale. | 65 | * @var string server locale. |
78 | */ | 66 | */ |
79 | protected $locale; | 67 | protected $locale; |
80 | |||
81 | /** | 68 | /** |
82 | * @var DateTime Latest item date. | 69 | * @var DateTime Latest item date. |
83 | */ | 70 | */ |
@@ -88,37 +75,36 @@ class FeedBuilder | |||
88 | * | 75 | * |
89 | * @param BookmarkServiceInterface $linkDB LinkDB instance. | 76 | * @param BookmarkServiceInterface $linkDB LinkDB instance. |
90 | * @param BookmarkFormatter $formatter instance. | 77 | * @param BookmarkFormatter $formatter instance. |
91 | * @param string $feedType Type of feed. | ||
92 | * @param array $serverInfo $_SERVER. | 78 | * @param array $serverInfo $_SERVER. |
93 | * @param array $userInput $_GET. | ||
94 | * @param boolean $isLoggedIn True if the user is currently logged in, false otherwise. | 79 | * @param boolean $isLoggedIn True if the user is currently logged in, false otherwise. |
95 | */ | 80 | */ |
96 | public function __construct($linkDB, $formatter, $feedType, $serverInfo, $userInput, $isLoggedIn) | 81 | public function __construct($linkDB, $formatter, array $serverInfo, $isLoggedIn) |
97 | { | 82 | { |
98 | $this->linkDB = $linkDB; | 83 | $this->linkDB = $linkDB; |
99 | $this->formatter = $formatter; | 84 | $this->formatter = $formatter; |
100 | $this->feedType = $feedType; | ||
101 | $this->serverInfo = $serverInfo; | 85 | $this->serverInfo = $serverInfo; |
102 | $this->userInput = $userInput; | ||
103 | $this->isLoggedIn = $isLoggedIn; | 86 | $this->isLoggedIn = $isLoggedIn; |
104 | } | 87 | } |
105 | 88 | ||
106 | /** | 89 | /** |
107 | * Build data for feed templates. | 90 | * Build data for feed templates. |
108 | * | 91 | * |
92 | * @param string $feedType Type of feed (RSS/ATOM). | ||
93 | * @param array $userInput $_GET. | ||
94 | * | ||
109 | * @return array Formatted data for feeds templates. | 95 | * @return array Formatted data for feeds templates. |
110 | */ | 96 | */ |
111 | public function buildData() | 97 | public function buildData(string $feedType, ?array $userInput) |
112 | { | 98 | { |
113 | // Search for untagged bookmarks | 99 | // Search for untagged bookmarks |
114 | if (isset($this->userInput['searchtags']) && empty($this->userInput['searchtags'])) { | 100 | if (isset($this->userInput['searchtags']) && empty($userInput['searchtags'])) { |
115 | $this->userInput['searchtags'] = false; | 101 | $userInput['searchtags'] = false; |
116 | } | 102 | } |
117 | 103 | ||
118 | // Optionally filter the results: | 104 | // Optionally filter the results: |
119 | $linksToDisplay = $this->linkDB->search($this->userInput); | 105 | $linksToDisplay = $this->linkDB->search($userInput); |
120 | 106 | ||
121 | $nblinksToDisplay = $this->getNbLinks(count($linksToDisplay)); | 107 | $nblinksToDisplay = $this->getNbLinks(count($linksToDisplay), $userInput); |
122 | 108 | ||
123 | // Can't use array_keys() because $link is a LinkDB instance and not a real array. | 109 | // Can't use array_keys() because $link is a LinkDB instance and not a real array. |
124 | $keys = array(); | 110 | $keys = array(); |
@@ -130,11 +116,11 @@ class FeedBuilder | |||
130 | $this->formatter->addContextData('index_url', $pageaddr); | 116 | $this->formatter->addContextData('index_url', $pageaddr); |
131 | $linkDisplayed = array(); | 117 | $linkDisplayed = array(); |
132 | for ($i = 0; $i < $nblinksToDisplay && $i < count($keys); $i++) { | 118 | for ($i = 0; $i < $nblinksToDisplay && $i < count($keys); $i++) { |
133 | $linkDisplayed[$keys[$i]] = $this->buildItem($linksToDisplay[$keys[$i]], $pageaddr); | 119 | $linkDisplayed[$keys[$i]] = $this->buildItem($feedType, $linksToDisplay[$keys[$i]], $pageaddr); |
134 | } | 120 | } |
135 | 121 | ||
136 | $data['language'] = $this->getTypeLanguage(); | 122 | $data['language'] = $this->getTypeLanguage($feedType); |
137 | $data['last_update'] = $this->getLatestDateFormatted(); | 123 | $data['last_update'] = $this->getLatestDateFormatted($feedType); |
138 | $data['show_dates'] = !$this->hideDates || $this->isLoggedIn; | 124 | $data['show_dates'] = !$this->hideDates || $this->isLoggedIn; |
139 | // Remove leading slash from REQUEST_URI. | 125 | // Remove leading slash from REQUEST_URI. |
140 | $data['self_link'] = escape(server_url($this->serverInfo)) | 126 | $data['self_link'] = escape(server_url($this->serverInfo)) |
@@ -147,14 +133,45 @@ class FeedBuilder | |||
147 | } | 133 | } |
148 | 134 | ||
149 | /** | 135 | /** |
136 | * Set this to true to use permalinks instead of direct bookmarks. | ||
137 | * | ||
138 | * @param boolean $usePermalinks true to force permalinks. | ||
139 | */ | ||
140 | public function setUsePermalinks($usePermalinks) | ||
141 | { | ||
142 | $this->usePermalinks = $usePermalinks; | ||
143 | } | ||
144 | |||
145 | /** | ||
146 | * Set this to true to hide timestamps in feeds. | ||
147 | * | ||
148 | * @param boolean $hideDates true to enable. | ||
149 | */ | ||
150 | public function setHideDates($hideDates) | ||
151 | { | ||
152 | $this->hideDates = $hideDates; | ||
153 | } | ||
154 | |||
155 | /** | ||
156 | * Set the locale. Used to show feed language. | ||
157 | * | ||
158 | * @param string $locale The locale (eg. 'fr_FR.UTF8'). | ||
159 | */ | ||
160 | public function setLocale($locale) | ||
161 | { | ||
162 | $this->locale = strtolower($locale); | ||
163 | } | ||
164 | |||
165 | /** | ||
150 | * Build a feed item (one per shaare). | 166 | * Build a feed item (one per shaare). |
151 | * | 167 | * |
168 | * @param string $feedType Type of feed (RSS/ATOM). | ||
152 | * @param Bookmark $link Single link array extracted from LinkDB. | 169 | * @param Bookmark $link Single link array extracted from LinkDB. |
153 | * @param string $pageaddr Index URL. | 170 | * @param string $pageaddr Index URL. |
154 | * | 171 | * |
155 | * @return array Link array with feed attributes. | 172 | * @return array Link array with feed attributes. |
156 | */ | 173 | */ |
157 | protected function buildItem($link, $pageaddr) | 174 | protected function buildItem(string $feedType, $link, $pageaddr) |
158 | { | 175 | { |
159 | $data = $this->formatter->format($link); | 176 | $data = $this->formatter->format($link); |
160 | $data['guid'] = $pageaddr . '?' . $data['shorturl']; | 177 | $data['guid'] = $pageaddr . '?' . $data['shorturl']; |
@@ -165,13 +182,13 @@ class FeedBuilder | |||
165 | } | 182 | } |
166 | $data['description'] .= PHP_EOL . PHP_EOL . '<br>— ' . $permalink; | 183 | $data['description'] .= PHP_EOL . PHP_EOL . '<br>— ' . $permalink; |
167 | 184 | ||
168 | $data['pub_iso_date'] = $this->getIsoDate($data['created']); | 185 | $data['pub_iso_date'] = $this->getIsoDate($feedType, $data['created']); |
169 | 186 | ||
170 | // atom:entry elements MUST contain exactly one atom:updated element. | 187 | // atom:entry elements MUST contain exactly one atom:updated element. |
171 | if (!empty($link->getUpdated())) { | 188 | if (!empty($link->getUpdated())) { |
172 | $data['up_iso_date'] = $this->getIsoDate($data['updated'], DateTime::ATOM); | 189 | $data['up_iso_date'] = $this->getIsoDate($feedType, $data['updated'], DateTime::ATOM); |
173 | } else { | 190 | } else { |
174 | $data['up_iso_date'] = $this->getIsoDate($data['created'], DateTime::ATOM); | 191 | $data['up_iso_date'] = $this->getIsoDate($feedType, $data['created'], DateTime::ATOM); |
175 | } | 192 | } |
176 | 193 | ||
177 | // Save the more recent item. | 194 | // Save the more recent item. |
@@ -186,51 +203,23 @@ class FeedBuilder | |||
186 | } | 203 | } |
187 | 204 | ||
188 | /** | 205 | /** |
189 | * Set this to true to use permalinks instead of direct bookmarks. | ||
190 | * | ||
191 | * @param boolean $usePermalinks true to force permalinks. | ||
192 | */ | ||
193 | public function setUsePermalinks($usePermalinks) | ||
194 | { | ||
195 | $this->usePermalinks = $usePermalinks; | ||
196 | } | ||
197 | |||
198 | /** | ||
199 | * Set this to true to hide timestamps in feeds. | ||
200 | * | ||
201 | * @param boolean $hideDates true to enable. | ||
202 | */ | ||
203 | public function setHideDates($hideDates) | ||
204 | { | ||
205 | $this->hideDates = $hideDates; | ||
206 | } | ||
207 | |||
208 | /** | ||
209 | * Set the locale. Used to show feed language. | ||
210 | * | ||
211 | * @param string $locale The locale (eg. 'fr_FR.UTF8'). | ||
212 | */ | ||
213 | public function setLocale($locale) | ||
214 | { | ||
215 | $this->locale = strtolower($locale); | ||
216 | } | ||
217 | |||
218 | /** | ||
219 | * Get the language according to the feed type, based on the locale: | 206 | * Get the language according to the feed type, based on the locale: |
220 | * | 207 | * |
221 | * - RSS format: en-us (default: 'en-en'). | 208 | * - RSS format: en-us (default: 'en-en'). |
222 | * - ATOM format: fr (default: 'en'). | 209 | * - ATOM format: fr (default: 'en'). |
223 | * | 210 | * |
211 | * @param string $feedType Type of feed (RSS/ATOM). | ||
212 | * | ||
224 | * @return string The language. | 213 | * @return string The language. |
225 | */ | 214 | */ |
226 | public function getTypeLanguage() | 215 | protected function getTypeLanguage(string $feedType) |
227 | { | 216 | { |
228 | // Use the locale do define the language, if available. | 217 | // Use the locale do define the language, if available. |
229 | if (!empty($this->locale) && preg_match('/^\w{2}[_\-]\w{2}/', $this->locale)) { | 218 | if (!empty($this->locale) && preg_match('/^\w{2}[_\-]\w{2}/', $this->locale)) { |
230 | $length = ($this->feedType === self::$FEED_RSS) ? 5 : 2; | 219 | $length = ($feedType === self::$FEED_RSS) ? 5 : 2; |
231 | return str_replace('_', '-', substr($this->locale, 0, $length)); | 220 | return str_replace('_', '-', substr($this->locale, 0, $length)); |
232 | } | 221 | } |
233 | return ($this->feedType === self::$FEED_RSS) ? 'en-en' : 'en'; | 222 | return ($feedType === self::$FEED_RSS) ? 'en-en' : 'en'; |
234 | } | 223 | } |
235 | 224 | ||
236 | /** | 225 | /** |
@@ -238,32 +227,35 @@ class FeedBuilder | |||
238 | * | 227 | * |
239 | * Return an empty string if invalid DateTime is passed. | 228 | * Return an empty string if invalid DateTime is passed. |
240 | * | 229 | * |
230 | * @param string $feedType Type of feed (RSS/ATOM). | ||
231 | * | ||
241 | * @return string Formatted date. | 232 | * @return string Formatted date. |
242 | */ | 233 | */ |
243 | protected function getLatestDateFormatted() | 234 | protected function getLatestDateFormatted(string $feedType) |
244 | { | 235 | { |
245 | if (empty($this->latestDate) || !$this->latestDate instanceof DateTime) { | 236 | if (empty($this->latestDate) || !$this->latestDate instanceof DateTime) { |
246 | return ''; | 237 | return ''; |
247 | } | 238 | } |
248 | 239 | ||
249 | $type = ($this->feedType == self::$FEED_RSS) ? DateTime::RSS : DateTime::ATOM; | 240 | $type = ($feedType == self::$FEED_RSS) ? DateTime::RSS : DateTime::ATOM; |
250 | return $this->latestDate->format($type); | 241 | return $this->latestDate->format($type); |
251 | } | 242 | } |
252 | 243 | ||
253 | /** | 244 | /** |
254 | * Get ISO date from DateTime according to feed type. | 245 | * Get ISO date from DateTime according to feed type. |
255 | * | 246 | * |
247 | * @param string $feedType Type of feed (RSS/ATOM). | ||
256 | * @param DateTime $date Date to format. | 248 | * @param DateTime $date Date to format. |
257 | * @param string|bool $format Force format. | 249 | * @param string|bool $format Force format. |
258 | * | 250 | * |
259 | * @return string Formatted date. | 251 | * @return string Formatted date. |
260 | */ | 252 | */ |
261 | protected function getIsoDate(DateTime $date, $format = false) | 253 | protected function getIsoDate(string $feedType, DateTime $date, $format = false) |
262 | { | 254 | { |
263 | if ($format !== false) { | 255 | if ($format !== false) { |
264 | return $date->format($format); | 256 | return $date->format($format); |
265 | } | 257 | } |
266 | if ($this->feedType == self::$FEED_RSS) { | 258 | if ($feedType == self::$FEED_RSS) { |
267 | return $date->format(DateTime::RSS); | 259 | return $date->format(DateTime::RSS); |
268 | } | 260 | } |
269 | return $date->format(DateTime::ATOM); | 261 | return $date->format(DateTime::ATOM); |
@@ -275,21 +267,22 @@ class FeedBuilder | |||
275 | * If 'nb' not set or invalid, default value: $DEFAULT_NB_LINKS. | 267 | * If 'nb' not set or invalid, default value: $DEFAULT_NB_LINKS. |
276 | * If 'nb' is set to 'all', display all filtered bookmarks (max parameter). | 268 | * If 'nb' is set to 'all', display all filtered bookmarks (max parameter). |
277 | * | 269 | * |
278 | * @param int $max maximum number of bookmarks to display. | 270 | * @param int $max maximum number of bookmarks to display. |
271 | * @param array $userInput $_GET. | ||
279 | * | 272 | * |
280 | * @return int number of bookmarks to display. | 273 | * @return int number of bookmarks to display. |
281 | */ | 274 | */ |
282 | public function getNbLinks($max) | 275 | protected function getNbLinks($max, ?array $userInput) |
283 | { | 276 | { |
284 | if (empty($this->userInput['nb'])) { | 277 | if (empty($userInput['nb'])) { |
285 | return self::$DEFAULT_NB_LINKS; | 278 | return self::$DEFAULT_NB_LINKS; |
286 | } | 279 | } |
287 | 280 | ||
288 | if ($this->userInput['nb'] == 'all') { | 281 | if ($userInput['nb'] == 'all') { |
289 | return $max; | 282 | return $max; |
290 | } | 283 | } |
291 | 284 | ||
292 | $intNb = intval($this->userInput['nb']); | 285 | $intNb = intval($userInput['nb']); |
293 | if (!is_int($intNb) || $intNb == 0) { | 286 | if (!is_int($intNb) || $intNb == 0) { |
294 | return self::$DEFAULT_NB_LINKS; | 287 | return self::$DEFAULT_NB_LINKS; |
295 | } | 288 | } |
@@ -452,15 +452,13 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM | |||
452 | $feedGenerator = new FeedBuilder( | 452 | $feedGenerator = new FeedBuilder( |
453 | $bookmarkService, | 453 | $bookmarkService, |
454 | $factory->getFormatter(), | 454 | $factory->getFormatter(), |
455 | $feedType, | ||
456 | $_SERVER, | 455 | $_SERVER, |
457 | $_GET, | ||
458 | $loginManager->isLoggedIn() | 456 | $loginManager->isLoggedIn() |
459 | ); | 457 | ); |
460 | $feedGenerator->setLocale(strtolower(setlocale(LC_COLLATE, 0))); | 458 | $feedGenerator->setLocale(strtolower(setlocale(LC_COLLATE, 0))); |
461 | $feedGenerator->setHideDates($conf->get('privacy.hide_timestamps') && !$loginManager->isLoggedIn()); | 459 | $feedGenerator->setHideDates($conf->get('privacy.hide_timestamps') && !$loginManager->isLoggedIn()); |
462 | $feedGenerator->setUsePermalinks(isset($_GET['permalinks']) || !$conf->get('feed.rss_permalinks')); | 460 | $feedGenerator->setUsePermalinks(isset($_GET['permalinks']) || !$conf->get('feed.rss_permalinks')); |
463 | $data = $feedGenerator->buildData(); | 461 | $data = $feedGenerator->buildData($feedType, $_GET); |
464 | 462 | ||
465 | // Process plugin hook. | 463 | // Process plugin hook. |
466 | $pluginManager->executeHooks('render_feed', $data, array( | 464 | $pluginManager->executeHooks('render_feed', $data, array( |
diff --git a/tests/feed/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php index 535207aa..b2b70b70 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']); |
@@ -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,14 +186,12 @@ 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 |
@@ -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', |