mirror of
https://github.com/wallabag/wallabag.git
synced 2025-07-27 17:28:39 +00:00
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:
parent
309e13c11b
commit
d1495dd0a4
4 changed files with 78 additions and 0 deletions
|
@ -398,6 +398,21 @@ class InstallCommand extends ContainerAwareCommand
|
||||||
'value' => 'wallabag',
|
'value' => 'wallabag',
|
||||||
'section' => 'misc',
|
'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) {
|
foreach ($settings as $setting) {
|
||||||
|
|
|
@ -140,6 +140,21 @@ class LoadSettingData extends AbstractFixture implements OrderedFixtureInterface
|
||||||
'value' => 'wallabag',
|
'value' => 'wallabag',
|
||||||
'section' => 'misc',
|
'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) {
|
foreach ($settings as $setting) {
|
||||||
|
|
|
@ -52,6 +52,10 @@ class DownloadImagesSubscriber implements EventSubscriber
|
||||||
$config = new $this->configClass();
|
$config = new $this->configClass();
|
||||||
$config->setEntityManager($args->getEntityManager());
|
$config->setEntityManager($args->getEntityManager());
|
||||||
|
|
||||||
|
if (!$config->get('download_images_enabled')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// field content has been updated
|
// field content has been updated
|
||||||
if ($args->hasChangedField('content')) {
|
if ($args->hasChangedField('content')) {
|
||||||
$html = $this->downloadImages($config, $entity);
|
$html = $this->downloadImages($config, $entity);
|
||||||
|
@ -87,6 +91,10 @@ class DownloadImagesSubscriber implements EventSubscriber
|
||||||
$config = new $this->configClass();
|
$config = new $this->configClass();
|
||||||
$config->setEntityManager($args->getEntityManager());
|
$config->setEntityManager($args->getEntityManager());
|
||||||
|
|
||||||
|
if (!$config->get('download_images_enabled')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// update all images inside the html
|
// update all images inside the html
|
||||||
$html = $this->downloadImages($config, $entity);
|
$html = $this->downloadImages($config, $entity);
|
||||||
if (false !== $html) {
|
if (false !== $html) {
|
||||||
|
|
|
@ -836,4 +836,44 @@ class EntryControllerTest extends WallabagCoreTestCase
|
||||||
$client->request('GET', '/share/'.$content->getUuid());
|
$client->request('GET', '/share/'.$content->getUuid());
|
||||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue