aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/http/MetadataRetrieverTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-15 11:20:33 +0200
committerArthurHoaro <arthur@hoa.ro>2020-10-15 11:36:56 +0200
commit5334090be04e66da5cb5c3ad487604b3733c5cac (patch)
tree419217a587c2a15bc97b943acee11fcf7b559937 /tests/http/MetadataRetrieverTest.php
parent4cf3564d28dc8e4d08a3e64f09ad045ffbde97ae (diff)
downloadShaarli-5334090be04e66da5cb5c3ad487604b3733c5cac.tar.gz
Shaarli-5334090be04e66da5cb5c3ad487604b3733c5cac.tar.zst
Shaarli-5334090be04e66da5cb5c3ad487604b3733c5cac.zip
Improve metadata retrieval (performances and accuracy)
- Use dedicated function to download headers to avoid apply multiple regexps on headers - Also try to extract title from meta tags
Diffstat (limited to 'tests/http/MetadataRetrieverTest.php')
-rw-r--r--tests/http/MetadataRetrieverTest.php45
1 files changed, 38 insertions, 7 deletions
diff --git a/tests/http/MetadataRetrieverTest.php b/tests/http/MetadataRetrieverTest.php
index 2a1838e8..3c9eaa0e 100644
--- a/tests/http/MetadataRetrieverTest.php
+++ b/tests/http/MetadataRetrieverTest.php
@@ -38,6 +38,7 @@ class MetadataRetrieverTest extends TestCase
38 $remoteTitle = 'Remote Title '; 38 $remoteTitle = 'Remote Title ';
39 $remoteDesc = 'Sometimes the meta description is relevant.'; 39 $remoteDesc = 'Sometimes the meta description is relevant.';
40 $remoteTags = 'abc def'; 40 $remoteTags = 'abc def';
41 $remoteCharset = 'utf-8';
41 42
42 $expectedResult = [ 43 $expectedResult = [
43 'title' => $remoteTitle, 44 'title' => $remoteTitle,
@@ -47,9 +48,26 @@ class MetadataRetrieverTest extends TestCase
47 48
48 $this->httpAccess 49 $this->httpAccess
49 ->expects(static::once()) 50 ->expects(static::once())
51 ->method('getCurlHeaderCallback')
52 ->willReturnCallback(
53 function (&$charset) use (
54 $remoteCharset
55 ): callable {
56 return function () use (
57 &$charset,
58 $remoteCharset
59 ): void {
60 $charset = $remoteCharset;
61 };
62 }
63 )
64 ;
65 $this->httpAccess
66 ->expects(static::once())
50 ->method('getCurlDownloadCallback') 67 ->method('getCurlDownloadCallback')
51 ->willReturnCallback( 68 ->willReturnCallback(
52 function (&$charset, &$title, &$description, &$tags) use ( 69 function (&$charset, &$title, &$description, &$tags) use (
70 $remoteCharset,
53 $remoteTitle, 71 $remoteTitle,
54 $remoteDesc, 72 $remoteDesc,
55 $remoteTags 73 $remoteTags
@@ -59,11 +77,13 @@ class MetadataRetrieverTest extends TestCase
59 &$title, 77 &$title,
60 &$description, 78 &$description,
61 &$tags, 79 &$tags,
80 $remoteCharset,
62 $remoteTitle, 81 $remoteTitle,
63 $remoteDesc, 82 $remoteDesc,
64 $remoteTags 83 $remoteTags
65 ): void { 84 ): void {
66 $charset = 'ISO-8859-1'; 85 static::assertSame($remoteCharset, $charset);
86
67 $title = $remoteTitle; 87 $title = $remoteTitle;
68 $description = $remoteDesc; 88 $description = $remoteDesc;
69 $tags = $remoteTags; 89 $tags = $remoteTags;
@@ -75,8 +95,9 @@ class MetadataRetrieverTest extends TestCase
75 ->expects(static::once()) 95 ->expects(static::once())
76 ->method('getHttpResponse') 96 ->method('getHttpResponse')
77 ->with($url, 30, 4194304) 97 ->with($url, 30, 4194304)
78 ->willReturnCallback(function($url, $timeout, $maxBytes, $callback): void { 98 ->willReturnCallback(function($url, $timeout, $maxBytes, $headerCallback, $dlCallback): void {
79 $callback(); 99 $headerCallback();
100 $dlCallback();
80 }) 101 })
81 ; 102 ;
82 103
@@ -102,8 +123,17 @@ class MetadataRetrieverTest extends TestCase
102 ->expects(static::once()) 123 ->expects(static::once())
103 ->method('getCurlDownloadCallback') 124 ->method('getCurlDownloadCallback')
104 ->willReturnCallback( 125 ->willReturnCallback(
105 function (&$charset, &$title, &$description, &$tags): callable { 126 function (): callable {
106 return function () use (&$charset, &$title, &$description, &$tags): void {}; 127 return function (): void {};
128 }
129 )
130 ;
131 $this->httpAccess
132 ->expects(static::once())
133 ->method('getCurlHeaderCallback')
134 ->willReturnCallback(
135 function (): callable {
136 return function (): void {};
107 } 137 }
108 ) 138 )
109 ; 139 ;
@@ -111,8 +141,9 @@ class MetadataRetrieverTest extends TestCase
111 ->expects(static::once()) 141 ->expects(static::once())
112 ->method('getHttpResponse') 142 ->method('getHttpResponse')
113 ->with($url, 30, 4194304) 143 ->with($url, 30, 4194304)
114 ->willReturnCallback(function($url, $timeout, $maxBytes, $callback): void { 144 ->willReturnCallback(function($url, $timeout, $maxBytes, $headerCallback, $dlCallback): void {
115 $callback(); 145 $headerCallback();
146 $dlCallback();
116 }) 147 })
117 ; 148 ;
118 149