diff options
author | ArthurHoaro <arthur@hoa.ro> | 2016-12-22 14:36:45 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2017-01-15 13:55:22 +0100 |
commit | c3b00963fe22479e87998c82bc83827a54c8d972 (patch) | |
tree | 4c3f47697f8e58e2c60aa94bdcb506c770e4bd5e /tests/api/ApiUtilsTest.php | |
parent | fc11ab2f290a3712b766d78fdbcd354625a35d0a (diff) | |
download | Shaarli-c3b00963fe22479e87998c82bc83827a54c8d972.tar.gz Shaarli-c3b00963fe22479e87998c82bc83827a54c8d972.tar.zst Shaarli-c3b00963fe22479e87998c82bc83827a54c8d972.zip |
REST API: implement getLinks service
See http://shaarli.github.io/api-documentation/#links-links-collection-get
Diffstat (limited to 'tests/api/ApiUtilsTest.php')
-rw-r--r-- | tests/api/ApiUtilsTest.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/api/ApiUtilsTest.php b/tests/api/ApiUtilsTest.php index 10da1459..516ee686 100644 --- a/tests/api/ApiUtilsTest.php +++ b/tests/api/ApiUtilsTest.php | |||
@@ -203,4 +203,69 @@ class ApiUtilsTest extends \PHPUnit_Framework_TestCase | |||
203 | $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() + 60) . '}', 'secret'); | 203 | $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() + 60) . '}', 'secret'); |
204 | ApiUtils::validateJwtToken($token, 'secret'); | 204 | ApiUtils::validateJwtToken($token, 'secret'); |
205 | } | 205 | } |
206 | |||
207 | /** | ||
208 | * Test formatLink() with a link using all useful fields. | ||
209 | */ | ||
210 | public function testFormatLinkComplete() | ||
211 | { | ||
212 | $indexUrl = 'https://domain.tld/sub/'; | ||
213 | $link = [ | ||
214 | 'id' => 12, | ||
215 | 'url' => 'http://lol.lol', | ||
216 | 'shorturl' => 'abc', | ||
217 | 'title' => 'Important Title', | ||
218 | 'description' => 'It is very lol<tag>' . PHP_EOL . 'new line', | ||
219 | 'tags' => 'blip .blop ', | ||
220 | 'private' => '1', | ||
221 | 'created' => \DateTime::createFromFormat('Ymd_His', '20170107_160102'), | ||
222 | 'updated' => \DateTime::createFromFormat('Ymd_His', '20170107_160612'), | ||
223 | ]; | ||
224 | |||
225 | $expected = [ | ||
226 | 'id' => 12, | ||
227 | 'url' => 'http://lol.lol', | ||
228 | 'shorturl' => 'abc', | ||
229 | 'title' => 'Important Title', | ||
230 | 'description' => 'It is very lol<tag>' . PHP_EOL . 'new line', | ||
231 | 'tags' => ['blip', '.blop'], | ||
232 | 'private' => true, | ||
233 | 'created' => '2017-01-07T16:01:02+00:00', | ||
234 | 'updated' => '2017-01-07T16:06:12+00:00', | ||
235 | ]; | ||
236 | |||
237 | $this->assertEquals($expected, ApiUtils::formatLink($link, $indexUrl)); | ||
238 | } | ||
239 | |||
240 | /** | ||
241 | * Test formatLink() with only minimal fields filled, and internal link. | ||
242 | */ | ||
243 | public function testFormatLinkMinimalNote() | ||
244 | { | ||
245 | $indexUrl = 'https://domain.tld/sub/'; | ||
246 | $link = [ | ||
247 | 'id' => 12, | ||
248 | 'url' => '?abc', | ||
249 | 'shorturl' => 'abc', | ||
250 | 'title' => 'Note', | ||
251 | 'description' => '', | ||
252 | 'tags' => '', | ||
253 | 'private' => '', | ||
254 | 'created' => \DateTime::createFromFormat('Ymd_His', '20170107_160102'), | ||
255 | ]; | ||
256 | |||
257 | $expected = [ | ||
258 | 'id' => 12, | ||
259 | 'url' => 'https://domain.tld/sub/?abc', | ||
260 | 'shorturl' => 'abc', | ||
261 | 'title' => 'Note', | ||
262 | 'description' => '', | ||
263 | 'tags' => [], | ||
264 | 'private' => false, | ||
265 | 'created' => '2017-01-07T16:01:02+00:00', | ||
266 | 'updated' => '', | ||
267 | ]; | ||
268 | |||
269 | $this->assertEquals($expected, ApiUtils::formatLink($link, $indexUrl)); | ||
270 | } | ||
206 | } | 271 | } |