forked from wallabag/wallabag
Avoid overlapping images when downloading them
This commit is contained in:
@ -31,7 +31,6 @@ class DownloadImagesTest extends TestCase
|
||||
public function testProcessHtml($html, $url)
|
||||
{
|
||||
$httpMockClient = new HttpMockClient();
|
||||
|
||||
$httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], file_get_contents(__DIR__ . '/../fixtures/unnamed.png')));
|
||||
|
||||
$logHandler = new TestHandler();
|
||||
@ -201,4 +200,23 @@ class DownloadImagesTest extends TestCase
|
||||
);
|
||||
$this->assertFalse($res);
|
||||
}
|
||||
|
||||
public function testEnsureOnlyFirstOccurenceIsReplaced()
|
||||
{
|
||||
$httpMockClient = new HttpMockClient();
|
||||
$httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], file_get_contents(__DIR__ . '/../fixtures/unnamed.png')));
|
||||
$httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], file_get_contents(__DIR__ . '/../fixtures/unnamed.png')));
|
||||
|
||||
$logHandler = new TestHandler();
|
||||
$logger = new Logger('test', [$logHandler]);
|
||||
|
||||
$download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger);
|
||||
|
||||
$html = '<img src="https://images.wsj.net/im-410981?width=860&height=573" srcset="https://images.wsj.net/im-410981?width=860&height=573&pixel_ratio=1.5 1290w" height="573" width="860" alt="" referrerpolicy="no-referrer">';
|
||||
$url = 'https://www.wsj.com/articles/5-interior-design-tips-to-max-out-your-basement-space-11633435201';
|
||||
|
||||
$res = $download->processHtml(123, $html, $url);
|
||||
|
||||
$this->assertSame('<img src="http://wallabag.io/assets/images/9/b/9b0ead26/6bef06fe.png" srcset="http://wallabag.io/assets/images/9/b/9b0ead26/43cc0123.png 1290w" height="573" width="860" alt="" referrerpolicy="no-referrer">', $res);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user