diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-09-25 13:29:36 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-10-15 09:08:46 +0200 |
commit | 4cf3564d28dc8e4d08a3e64f09ad045ffbde97ae (patch) | |
tree | 8f8ef095cdfea3b35953417fd3d8bb6cdbc7cb46 /tests/http | |
parent | f34554c6c2cd8fe99fe2e8907bfc196a4884416a (diff) | |
download | Shaarli-4cf3564d28dc8e4d08a3e64f09ad045ffbde97ae.tar.gz Shaarli-4cf3564d28dc8e4d08a3e64f09ad045ffbde97ae.tar.zst Shaarli-4cf3564d28dc8e4d08a3e64f09ad045ffbde97ae.zip |
Add a setting to retrieve bookmark metadata asynchrounously
- There is a new standalone script (metadata.js) which requests
a new controller to get bookmark metadata and fill the form async
- This feature is enabled with the new setting: general.enable_async_metadata
(enabled by default)
- general.retrieve_description is now enabled by default
- A small rotating loader animation has a been added to bookmark inputs
when metadata is being retrieved (default template)
- Custom JS htmlentities has been removed and mathiasbynens/he
library is used instead
Fixes #1563
Diffstat (limited to 'tests/http')
-rw-r--r-- | tests/http/MetadataRetrieverTest.php | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/tests/http/MetadataRetrieverTest.php b/tests/http/MetadataRetrieverTest.php new file mode 100644 index 00000000..2a1838e8 --- /dev/null +++ b/tests/http/MetadataRetrieverTest.php | |||
@@ -0,0 +1,123 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Http; | ||
6 | |||
7 | use PHPUnit\Framework\TestCase; | ||
8 | use Shaarli\Config\ConfigManager; | ||
9 | |||
10 | class MetadataRetrieverTest extends TestCase | ||
11 | { | ||
12 | /** @var MetadataRetriever */ | ||
13 | protected $retriever; | ||
14 | |||
15 | /** @var ConfigManager */ | ||
16 | protected $conf; | ||
17 | |||
18 | /** @var HttpAccess */ | ||
19 | protected $httpAccess; | ||
20 | |||
21 | public function setUp(): void | ||
22 | { | ||
23 | $this->conf = $this->createMock(ConfigManager::class); | ||
24 | $this->httpAccess = $this->createMock(HttpAccess::class); | ||
25 | $this->retriever = new MetadataRetriever($this->conf, $this->httpAccess); | ||
26 | |||
27 | $this->conf->method('get')->willReturnCallback(function (string $param, $default) { | ||
28 | return $default === null ? $param : $default; | ||
29 | }); | ||
30 | } | ||
31 | |||
32 | /** | ||
33 | * Test metadata retrieve() with values returned | ||
34 | */ | ||
35 | public function testFullRetrieval(): void | ||
36 | { | ||
37 | $url = 'https://domain.tld/link'; | ||
38 | $remoteTitle = 'Remote Title '; | ||
39 | $remoteDesc = 'Sometimes the meta description is relevant.'; | ||
40 | $remoteTags = 'abc def'; | ||
41 | |||
42 | $expectedResult = [ | ||
43 | 'title' => $remoteTitle, | ||
44 | 'description' => $remoteDesc, | ||
45 | 'tags' => $remoteTags, | ||
46 | ]; | ||
47 | |||
48 | $this->httpAccess | ||
49 | ->expects(static::once()) | ||
50 | ->method('getCurlDownloadCallback') | ||
51 | ->willReturnCallback( | ||
52 | function (&$charset, &$title, &$description, &$tags) use ( | ||
53 | $remoteTitle, | ||
54 | $remoteDesc, | ||
55 | $remoteTags | ||
56 | ): callable { | ||
57 | return function () use ( | ||
58 | &$charset, | ||
59 | &$title, | ||
60 | &$description, | ||
61 | &$tags, | ||
62 | $remoteTitle, | ||
63 | $remoteDesc, | ||
64 | $remoteTags | ||
65 | ): void { | ||
66 | $charset = 'ISO-8859-1'; | ||
67 | $title = $remoteTitle; | ||
68 | $description = $remoteDesc; | ||
69 | $tags = $remoteTags; | ||
70 | }; | ||
71 | } | ||
72 | ) | ||
73 | ; | ||
74 | $this->httpAccess | ||
75 | ->expects(static::once()) | ||
76 | ->method('getHttpResponse') | ||
77 | ->with($url, 30, 4194304) | ||
78 | ->willReturnCallback(function($url, $timeout, $maxBytes, $callback): void { | ||
79 | $callback(); | ||
80 | }) | ||
81 | ; | ||
82 | |||
83 | $result = $this->retriever->retrieve($url); | ||
84 | |||
85 | static::assertSame($expectedResult, $result); | ||
86 | } | ||
87 | |||
88 | /** | ||
89 | * Test metadata retrieve() without any value | ||
90 | */ | ||
91 | public function testEmptyRetrieval(): void | ||
92 | { | ||
93 | $url = 'https://domain.tld/link'; | ||
94 | |||
95 | $expectedResult = [ | ||
96 | 'title' => null, | ||
97 | 'description' => null, | ||
98 | 'tags' => null, | ||
99 | ]; | ||
100 | |||
101 | $this->httpAccess | ||
102 | ->expects(static::once()) | ||
103 | ->method('getCurlDownloadCallback') | ||
104 | ->willReturnCallback( | ||
105 | function (&$charset, &$title, &$description, &$tags): callable { | ||
106 | return function () use (&$charset, &$title, &$description, &$tags): void {}; | ||
107 | } | ||
108 | ) | ||
109 | ; | ||
110 | $this->httpAccess | ||
111 | ->expects(static::once()) | ||
112 | ->method('getHttpResponse') | ||
113 | ->with($url, 30, 4194304) | ||
114 | ->willReturnCallback(function($url, $timeout, $maxBytes, $callback): void { | ||
115 | $callback(); | ||
116 | }) | ||
117 | ; | ||
118 | |||
119 | $result = $this->retriever->retrieve($url); | ||
120 | |||
121 | static::assertSame($expectedResult, $result); | ||
122 | } | ||
123 | } | ||