]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Ability to enable/disable downloading images
authorJeremy Benoist <jeremy.benoist@gmail.com>
Sun, 30 Oct 2016 20:30:45 +0000 (21:30 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sun, 30 Oct 2016 20:30:45 +0000 (21:30 +0100)
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

src/Wallabag/CoreBundle/Command/InstallCommand.php
src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php
src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php
tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php

index 277f852422f6d14afea83df85bbd2023dae31cfd..aedccfe4c8fcdbabda5da78d7d92c208618d7c81 100644 (file)
@@ -398,6 +398,21 @@ class InstallCommand extends ContainerAwareCommand
                 'value' => 'wallabag',
                 'section' => 'misc',
             ],
+            [
+                'name' => 'download_images_enabled',
+                'value' => '0',
+                'section' => 'image',
+            ],
+            [
+                'name' => 'download_images_with_rabbitmq',
+                'value' => '0',
+                'section' => 'image',
+            ],
+            [
+                'name' => 'download_images_with_redis',
+                'value' => '0',
+                'section' => 'image',
+            ],
         ];
 
         foreach ($settings as $setting) {
index 12f66c19be2710bb98e4b0e1a4a94db130a8754f..70a7a4ac0e37d7406e3b00a586a6fbdc275ca2c7 100644 (file)
@@ -140,6 +140,21 @@ class LoadSettingData extends AbstractFixture implements OrderedFixtureInterface
                 'value' => 'wallabag',
                 'section' => 'misc',
             ],
+            [
+                'name' => 'download_images_enabled',
+                'value' => '0',
+                'section' => 'image',
+            ],
+            [
+                'name' => 'download_images_with_rabbitmq',
+                'value' => '0',
+                'section' => 'image',
+            ],
+            [
+                'name' => 'download_images_with_redis',
+                'value' => '0',
+                'section' => 'image',
+            ],
         ];
 
         foreach ($settings as $setting) {
index 0792653e061740afed7e6e737f71f4e190a886d2..3f2d460c1ef7a3684f4e513336b881068070b77f 100644 (file)
@@ -52,6 +52,10 @@ class DownloadImagesSubscriber implements EventSubscriber
         $config = new $this->configClass();
         $config->setEntityManager($args->getEntityManager());
 
+        if (!$config->get('download_images_enabled')) {
+            return;
+        }
+
         // field content has been updated
         if ($args->hasChangedField('content')) {
             $html = $this->downloadImages($config, $entity);
@@ -87,6 +91,10 @@ class DownloadImagesSubscriber implements EventSubscriber
         $config = new $this->configClass();
         $config->setEntityManager($args->getEntityManager());
 
+        if (!$config->get('download_images_enabled')) {
+            return;
+        }
+
         // update all images inside the html
         $html = $this->downloadImages($config, $entity);
         if (false !== $html) {
index 051136503969722f78b7720ab40cc90890efb2b9..514e9d89f4d9c50954737fc932b9959cb366a4a7 100644 (file)
@@ -836,4 +836,44 @@ class EntryControllerTest extends WallabagCoreTestCase
         $client->request('GET', '/share/'.$content->getUuid());
         $this->assertEquals(404, $client->getResponse()->getStatusCode());
     }
+
+    public function testNewEntryWithDownloadImagesEnabled()
+    {
+        $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);
+
+        $crawler = $client->request('GET', '/new');
+
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());
+
+        $form = $crawler->filter('form[name=entry]')->form();
+
+        $data = [
+            'entry[url]' => $url,
+        ];
+
+        $client->submit($form, $data);
+
+        $this->assertEquals(302, $client->getResponse()->getStatusCode());
+
+        $em = $client->getContainer()
+            ->get('doctrine.orm.entity_manager');
+
+        $entry = $em
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findByUrlAndUserId($url, $this->getLoggedInUserId());
+
+        $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());
+
+        $em->remove($entry);
+        $em->flush();
+
+        $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
+    }
 }