aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-10-30 21:30:45 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-10-30 21:30:45 +0100
commitd1495dd0a456f0e35a09fb68679ee51f8d17bfe4 (patch)
treea819eec38d3d8b880460cbaca42b6e08b073585a
parent309e13c11b54277626f18616c41f68ae9656a403 (diff)
downloadwallabag-d1495dd0a456f0e35a09fb68679ee51f8d17bfe4.tar.gz
wallabag-d1495dd0a456f0e35a09fb68679ee51f8d17bfe4.tar.zst
wallabag-d1495dd0a456f0e35a09fb68679ee51f8d17bfe4.zip
Ability to enable/disable downloading images
This will speed up the test suite because it won’t download everything when we add new entry… Add a custom test with downloading image enabled
-rw-r--r--src/Wallabag/CoreBundle/Command/InstallCommand.php15
-rw-r--r--src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php15
-rw-r--r--src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php8
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php40
4 files changed, 78 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
index 277f8524..aedccfe4 100644
--- a/src/Wallabag/CoreBundle/Command/InstallCommand.php
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -398,6 +398,21 @@ class InstallCommand extends ContainerAwareCommand
398 'value' => 'wallabag', 398 'value' => 'wallabag',
399 'section' => 'misc', 399 'section' => 'misc',
400 ], 400 ],
401 [
402 'name' => 'download_images_enabled',
403 'value' => '0',
404 'section' => 'image',
405 ],
406 [
407 'name' => 'download_images_with_rabbitmq',
408 'value' => '0',
409 'section' => 'image',
410 ],
411 [
412 'name' => 'download_images_with_redis',
413 'value' => '0',
414 'section' => 'image',
415 ],
401 ]; 416 ];
402 417
403 foreach ($settings as $setting) { 418 foreach ($settings as $setting) {
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php
index 12f66c19..70a7a4ac 100644
--- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php
+++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php
@@ -140,6 +140,21 @@ class LoadSettingData extends AbstractFixture implements OrderedFixtureInterface
140 'value' => 'wallabag', 140 'value' => 'wallabag',
141 'section' => 'misc', 141 'section' => 'misc',
142 ], 142 ],
143 [
144 'name' => 'download_images_enabled',
145 'value' => '0',
146 'section' => 'image',
147 ],
148 [
149 'name' => 'download_images_with_rabbitmq',
150 'value' => '0',
151 'section' => 'image',
152 ],
153 [
154 'name' => 'download_images_with_redis',
155 'value' => '0',
156 'section' => 'image',
157 ],
143 ]; 158 ];
144 159
145 foreach ($settings as $setting) { 160 foreach ($settings as $setting) {
diff --git a/src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php b/src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php
index 0792653e..3f2d460c 100644
--- a/src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php
+++ b/src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php
@@ -52,6 +52,10 @@ class DownloadImagesSubscriber implements EventSubscriber
52 $config = new $this->configClass(); 52 $config = new $this->configClass();
53 $config->setEntityManager($args->getEntityManager()); 53 $config->setEntityManager($args->getEntityManager());
54 54
55 if (!$config->get('download_images_enabled')) {
56 return;
57 }
58
55 // field content has been updated 59 // field content has been updated
56 if ($args->hasChangedField('content')) { 60 if ($args->hasChangedField('content')) {
57 $html = $this->downloadImages($config, $entity); 61 $html = $this->downloadImages($config, $entity);
@@ -87,6 +91,10 @@ class DownloadImagesSubscriber implements EventSubscriber
87 $config = new $this->configClass(); 91 $config = new $this->configClass();
88 $config->setEntityManager($args->getEntityManager()); 92 $config->setEntityManager($args->getEntityManager());
89 93
94 if (!$config->get('download_images_enabled')) {
95 return;
96 }
97
90 // update all images inside the html 98 // update all images inside the html
91 $html = $this->downloadImages($config, $entity); 99 $html = $this->downloadImages($config, $entity);
92 if (false !== $html) { 100 if (false !== $html) {
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 05113650..514e9d89 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -836,4 +836,44 @@ class EntryControllerTest extends WallabagCoreTestCase
836 $client->request('GET', '/share/'.$content->getUuid()); 836 $client->request('GET', '/share/'.$content->getUuid());
837 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 837 $this->assertEquals(404, $client->getResponse()->getStatusCode());
838 } 838 }
839
840 public function testNewEntryWithDownloadImagesEnabled()
841 {
842 $this->logInAs('admin');
843 $client = $this->getClient();
844
845 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
846 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
847
848 $crawler = $client->request('GET', '/new');
849
850 $this->assertEquals(200, $client->getResponse()->getStatusCode());
851
852 $form = $crawler->filter('form[name=entry]')->form();
853
854 $data = [
855 'entry[url]' => $url,
856 ];
857
858 $client->submit($form, $data);
859
860 $this->assertEquals(302, $client->getResponse()->getStatusCode());
861
862 $em = $client->getContainer()
863 ->get('doctrine.orm.entity_manager');
864
865 $entry = $em
866 ->getRepository('WallabagCoreBundle:Entry')
867 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
868
869 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
870 $this->assertEquals($url, $entry->getUrl());
871 $this->assertContains('Perpignan', $entry->getTitle());
872 $this->assertContains('assets/images/8/e/8ec9229a/d9bc0fcd.jpeg', $entry->getContent());
873
874 $em->remove($entry);
875 $em->flush();
876
877 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
878 }
839} 879}