diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2019-02-07 17:56:05 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2019-05-28 11:44:20 +0200 |
commit | b6c1e1bacc59ba761d1b47ac6611d1db800f7252 (patch) | |
tree | d6724737f4ed6bcaebc73b572495b440a5c19553 /tests/Wallabag/CoreBundle/Helper | |
parent | a91a3150fbc4446e379cc23618db8f74e4044515 (diff) | |
download | wallabag-b6c1e1bacc59ba761d1b47ac6611d1db800f7252.tar.gz wallabag-b6c1e1bacc59ba761d1b47ac6611d1db800f7252.tar.zst wallabag-b6c1e1bacc59ba761d1b47ac6611d1db800f7252.zip |
Fix some tests
Diffstat (limited to 'tests/Wallabag/CoreBundle/Helper')
-rw-r--r-- | tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index 0199b3e4..3c720425 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php | |||
@@ -2,10 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | 3 | namespace Tests\Wallabag\CoreBundle\Helper; |
4 | 4 | ||
5 | use GuzzleHttp\Client; | ||
6 | use GuzzleHttp\Psr7\Response; | 5 | use GuzzleHttp\Psr7\Response; |
7 | use GuzzleHttp\Stream\Stream; | ||
8 | use GuzzleHttp\Subscriber\Mock; | ||
9 | use Http\Mock\Client as HttpMockClient; | 6 | use Http\Mock\Client as HttpMockClient; |
10 | use Monolog\Handler\TestHandler; | 7 | use Monolog\Handler\TestHandler; |
11 | use Monolog\Logger; | 8 | use Monolog\Logger; |
@@ -153,20 +150,15 @@ class DownloadImagesTest extends TestCase | |||
153 | 150 | ||
154 | public function testProcessImageWithSrcset() | 151 | public function testProcessImageWithSrcset() |
155 | { | 152 | { |
156 | $client = new Client(); | 153 | $httpMockClient = new HttpMockClient(); |
157 | 154 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); | |
158 | $mock = new Mock([ | 155 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); |
159 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | 156 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); |
160 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
161 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
162 | ]); | ||
163 | |||
164 | $client->getEmitter()->attach($mock); | ||
165 | 157 | ||
166 | $logHandler = new TestHandler(); | 158 | $logHandler = new TestHandler(); |
167 | $logger = new Logger('test', [$logHandler]); | 159 | $logger = new Logger('test', [$logHandler]); |
168 | 160 | ||
169 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 161 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
170 | $res = $download->processHtml(123, '<p><img class="alignnone wp-image-1153" src="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg" alt="" width="628" height="444" srcset="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg 530w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-768x543.jpg 768w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-900x636.jpg 900w" sizes="(max-width: 628px) 100vw, 628px" /></p>', 'http://piketty.blog.lemonde.fr/2017/10/12/budget-2018-la-jeunesse-sacrifiee/'); | 162 | $res = $download->processHtml(123, '<p><img class="alignnone wp-image-1153" src="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg" alt="" width="628" height="444" srcset="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg 530w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-768x543.jpg 768w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-900x636.jpg 900w" sizes="(max-width: 628px) 100vw, 628px" /></p>', 'http://piketty.blog.lemonde.fr/2017/10/12/budget-2018-la-jeunesse-sacrifiee/'); |
171 | 163 | ||
172 | $this->assertNotContains('http://piketty.blog.lemonde.fr/', $res, 'Image srcset attribute were not replaced'); | 164 | $this->assertNotContains('http://piketty.blog.lemonde.fr/', $res, 'Image srcset attribute were not replaced'); |
@@ -174,20 +166,15 @@ class DownloadImagesTest extends TestCase | |||
174 | 166 | ||
175 | public function testProcessImageWithTrickySrcset() | 167 | public function testProcessImageWithTrickySrcset() |
176 | { | 168 | { |
177 | $client = new Client(); | 169 | $httpMockClient = new HttpMockClient(); |
178 | 170 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); | |
179 | $mock = new Mock([ | 171 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); |
180 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | 172 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); |
181 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
182 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
183 | ]); | ||
184 | |||
185 | $client->getEmitter()->attach($mock); | ||
186 | 173 | ||
187 | $logHandler = new TestHandler(); | 174 | $logHandler = new TestHandler(); |
188 | $logger = new Logger('test', [$logHandler]); | 175 | $logger = new Logger('test', [$logHandler]); |
189 | 176 | ||
190 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 177 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
191 | $res = $download->processHtml(123, '<figure id="post-257260" class="align-none media-257260"><img src="https://cdn.css-tricks.com/wp-content/uploads/2017/08/the-critical-request.png" srcset="https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_1000,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 1000w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_200,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 200w" sizes="(min-width: 1850px) calc( (100vw - 555px) / 3 ) | 178 | $res = $download->processHtml(123, '<figure id="post-257260" class="align-none media-257260"><img src="https://cdn.css-tricks.com/wp-content/uploads/2017/08/the-critical-request.png" srcset="https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_1000,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 1000w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_200,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 200w" sizes="(min-width: 1850px) calc( (100vw - 555px) / 3 ) |
192 | (min-width: 1251px) calc( (100vw - 530px) / 2 ) | 179 | (min-width: 1251px) calc( (100vw - 530px) / 2 ) |
193 | (min-width: 1086px) calc(100vw - 480px) | 180 | (min-width: 1086px) calc(100vw - 480px) |
@@ -199,18 +186,13 @@ class DownloadImagesTest extends TestCase | |||
199 | 186 | ||
200 | public function testProcessImageWithNullPath() | 187 | public function testProcessImageWithNullPath() |
201 | { | 188 | { |
202 | $client = new Client(); | 189 | $httpMockClient = new HttpMockClient(); |
203 | 190 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); | |
204 | $mock = new Mock([ | ||
205 | new Response(200, ['content-type' => null], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
206 | ]); | ||
207 | |||
208 | $client->getEmitter()->attach($mock); | ||
209 | 191 | ||
210 | $logHandler = new TestHandler(); | 192 | $logHandler = new TestHandler(); |
211 | $logger = new Logger('test', [$logHandler]); | 193 | $logger = new Logger('test', [$logHandler]); |
212 | 194 | ||
213 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 195 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
214 | 196 | ||
215 | $res = $download->processSingleImage( | 197 | $res = $download->processSingleImage( |
216 | 123, | 198 | 123, |