aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/api/ApiUtilsTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/api/ApiUtilsTest.php')
-rw-r--r--tests/api/ApiUtilsTest.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/api/ApiUtilsTest.php b/tests/api/ApiUtilsTest.php
index 4b2fa3b2..b4431d1b 100644
--- a/tests/api/ApiUtilsTest.php
+++ b/tests/api/ApiUtilsTest.php
@@ -206,4 +206,69 @@ class ApiUtilsTest extends \PHPUnit_Framework_TestCase
206 $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() + 60) . '}', 'secret'); 206 $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() + 60) . '}', 'secret');
207 ApiUtils::validateJwtToken($token, 'secret'); 207 ApiUtils::validateJwtToken($token, 'secret');
208 } 208 }
209
210 /**
211 * Test formatLink() with a link using all useful fields.
212 */
213 public function testFormatLinkComplete()
214 {
215 $indexUrl = 'https://domain.tld/sub/';
216 $link = [
217 'id' => 12,
218 'url' => 'http://lol.lol',
219 'shorturl' => 'abc',
220 'title' => 'Important Title',
221 'description' => 'It is very lol<tag>' . PHP_EOL . 'new line',
222 'tags' => 'blip .blop ',
223 'private' => '1',
224 'created' => \DateTime::createFromFormat('Ymd_His', '20170107_160102'),
225 'updated' => \DateTime::createFromFormat('Ymd_His', '20170107_160612'),
226 ];
227
228 $expected = [
229 'id' => 12,
230 'url' => 'http://lol.lol',
231 'shorturl' => 'abc',
232 'title' => 'Important Title',
233 'description' => 'It is very lol<tag>' . PHP_EOL . 'new line',
234 'tags' => ['blip', '.blop'],
235 'private' => true,
236 'created' => '2017-01-07T16:01:02+00:00',
237 'updated' => '2017-01-07T16:06:12+00:00',
238 ];
239
240 $this->assertEquals($expected, ApiUtils::formatLink($link, $indexUrl));
241 }
242
243 /**
244 * Test formatLink() with only minimal fields filled, and internal link.
245 */
246 public function testFormatLinkMinimalNote()
247 {
248 $indexUrl = 'https://domain.tld/sub/';
249 $link = [
250 'id' => 12,
251 'url' => '?abc',
252 'shorturl' => 'abc',
253 'title' => 'Note',
254 'description' => '',
255 'tags' => '',
256 'private' => '',
257 'created' => \DateTime::createFromFormat('Ymd_His', '20170107_160102'),
258 ];
259
260 $expected = [
261 'id' => 12,
262 'url' => 'https://domain.tld/sub/?abc',
263 'shorturl' => 'abc',
264 'title' => 'Note',
265 'description' => '',
266 'tags' => [],
267 'private' => false,
268 'created' => '2017-01-07T16:01:02+00:00',
269 'updated' => '',
270 ];
271
272 $this->assertEquals($expected, ApiUtils::formatLink($link, $indexUrl));
273 }
209} 274}