From e0597476d1d5f6a4a7d6ea9b76966465f3d22fb8 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 1 Nov 2016 14:49:02 +0100 Subject: Use custom event instead of Doctrine ones MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This give us ability to use Entry ID to determine where to store images and it’s then more easy to remove them when we remove the entry. --- .../CoreBundle/Controller/EntryControllerTest.php | 26 ++++++++++++++++--- .../CoreBundle/Helper/DownloadImagesTest.php | 29 +++++++++++----------- 2 files changed, 37 insertions(+), 18 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 514e9d89..4ab06dbf 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -869,10 +869,30 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); $this->assertEquals($url, $entry->getUrl()); $this->assertContains('Perpignan', $entry->getTitle()); - $this->assertContains('assets/images/8/e/8ec9229a/d9bc0fcd.jpeg', $entry->getContent()); + $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent()); - $em->remove($entry); - $em->flush(); + $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); + } + + /** + * @depends testNewEntryWithDownloadImagesEnabled + */ + public function testRemoveEntryWithDownloadImagesEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; + $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($url, $this->getLoggedInUserId()); + + $client->request('GET', '/delete/'.$content->getId()); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); } diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index 33d2e389..920c21d9 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php @@ -26,12 +26,11 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase $logHandler = new TestHandler(); $logger = new Logger('test', array($logHandler)); - $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', $logger); - $download->setWallabagUrl('http://wallabag.io/'); + $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); - $res = $download->processHtml('
', 'http://imgur.com/gallery/WxtWY'); + $res = $download->processHtml(123, '
', 'http://imgur.com/gallery/WxtWY'); - $this->assertContains('http://wallabag.io/assets/images/4/2/4258f71e/c638b4c2.png', $res); + $this->assertContains('http://wallabag.io/assets/images/9/b/9b0ead26/c638b4c2.png', $res); } public function testProcessHtmlWithBadImage() @@ -47,8 +46,8 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase $logHandler = new TestHandler(); $logger = new Logger('test', array($logHandler)); - $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', $logger); - $res = $download->processHtml('
', 'http://imgur.com/gallery/WxtWY'); + $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); + $res = $download->processHtml(123, '
', 'http://imgur.com/gallery/WxtWY'); $this->assertContains('http://i.imgur.com/T9qgcHc.jpg', $res, 'Image were not replace because of content-type'); } @@ -79,10 +78,10 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase $logHandler = new TestHandler(); $logger = new Logger('test', array($logHandler)); - $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', $logger); - $res = $download->processSingleImage('T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); + $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); + $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); - $this->assertContains('/assets/images/4/2/4258f71e/ebe60399.'.$extension, $res); + $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.'.$extension, $res); } public function testProcessSingleImageWithBadUrl() @@ -98,8 +97,8 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase $logHandler = new TestHandler(); $logger = new Logger('test', array($logHandler)); - $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', $logger); - $res = $download->processSingleImage('T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); + $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); + $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); $this->assertFalse($res, 'Image can not be found, so it will not be replaced'); } @@ -117,8 +116,8 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase $logHandler = new TestHandler(); $logger = new Logger('test', array($logHandler)); - $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', $logger); - $res = $download->processSingleImage('http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); + $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); + $res = $download->processSingleImage(123, 'http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); $this->assertFalse($res, 'Image can not be loaded, so it will not be replaced'); } @@ -136,8 +135,8 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase $logHandler = new TestHandler(); $logger = new Logger('test', array($logHandler)); - $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', $logger); - $res = $download->processSingleImage('/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY'); + $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); + $res = $download->processSingleImage(123, '/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY'); $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced'); } -- cgit v1.2.3