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
This commit is contained in:
Jeremy Benoist 2016-10-30 21:30:45 +01:00
parent 309e13c11b
commit d1495dd0a4
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
4 changed files with 78 additions and 0 deletions

View 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) {

View 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) {

View 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) {

View 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);
}
}