aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php5
-rw-r--r--src/Wallabag/ImportBundle/Controller/ReadabilityController.php2
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagController.php2
-rw-r--r--src/Wallabag/ImportBundle/Form/Type/UploadImportType.php1
-rw-r--r--tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php74
-rw-r--r--tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php1
-rw-r--r--tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php17
-rw-r--r--tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php17
-rw-r--r--tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php17
9 files changed, 133 insertions, 3 deletions
diff --git a/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php b/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php
index 85c5a903..5f90e00f 100644
--- a/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php
+++ b/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php
@@ -5,6 +5,7 @@ namespace Wallabag\ImportBundle\Command;
5use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 5use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6use Symfony\Component\Config\Definition\Exception\Exception; 6use Symfony\Component\Config\Definition\Exception\Exception;
7use Symfony\Component\Console\Input\InputArgument; 7use Symfony\Component\Console\Input\InputArgument;
8use Symfony\Component\Console\Input\InputOption;
8use Symfony\Component\Console\Input\InputInterface; 9use Symfony\Component\Console\Input\InputInterface;
9use Symfony\Component\Console\Output\OutputInterface; 10use Symfony\Component\Console\Output\OutputInterface;
10use Simpleue\Worker\QueueWorker; 11use Simpleue\Worker\QueueWorker;
@@ -17,6 +18,7 @@ class RedisWorkerCommand extends ContainerAwareCommand
17 ->setName('wallabag:import:redis-worker') 18 ->setName('wallabag:import:redis-worker')
18 ->setDescription('Launch Redis worker') 19 ->setDescription('Launch Redis worker')
19 ->addArgument('serviceName', InputArgument::REQUIRED, 'Service to use: wallabag_v1, wallabag_v2, pocket or readability') 20 ->addArgument('serviceName', InputArgument::REQUIRED, 'Service to use: wallabag_v1, wallabag_v2, pocket or readability')
21 ->addOption('maxIterations', '', InputOption::VALUE_OPTIONAL, 'Number of iterations before stoping', false)
20 ; 22 ;
21 } 23 }
22 24
@@ -33,7 +35,8 @@ class RedisWorkerCommand extends ContainerAwareCommand
33 35
34 $worker = new QueueWorker( 36 $worker = new QueueWorker(
35 $this->getContainer()->get('wallabag_import.queue.redis.'.$serviceName), 37 $this->getContainer()->get('wallabag_import.queue.redis.'.$serviceName),
36 $this->getContainer()->get('wallabag_import.consumer.redis.'.$serviceName) 38 $this->getContainer()->get('wallabag_import.consumer.redis.'.$serviceName),
39 $input->getOption('maxIterations')
37 ); 40 );
38 41
39 $worker->start(); 42 $worker->start();
diff --git a/src/Wallabag/ImportBundle/Controller/ReadabilityController.php b/src/Wallabag/ImportBundle/Controller/ReadabilityController.php
index 61243042..8775e8a3 100644
--- a/src/Wallabag/ImportBundle/Controller/ReadabilityController.php
+++ b/src/Wallabag/ImportBundle/Controller/ReadabilityController.php
@@ -31,7 +31,7 @@ class ReadabilityController extends Controller
31 $markAsRead = $form->get('mark_as_read')->getData(); 31 $markAsRead = $form->get('mark_as_read')->getData();
32 $name = 'readability_'.$this->getUser()->getId().'.json'; 32 $name = 'readability_'.$this->getUser()->getId().'.json';
33 33
34 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
35 $res = $readability 35 $res = $readability
36 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 36 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
37 ->setMarkAsRead($markAsRead) 37 ->setMarkAsRead($markAsRead)
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagController.php b/src/Wallabag/ImportBundle/Controller/WallabagController.php
index 1e6114c5..3c2dd6d1 100644
--- a/src/Wallabag/ImportBundle/Controller/WallabagController.php
+++ b/src/Wallabag/ImportBundle/Controller/WallabagController.php
@@ -45,7 +45,7 @@ abstract class WallabagController extends Controller
45 $markAsRead = $form->get('mark_as_read')->getData(); 45 $markAsRead = $form->get('mark_as_read')->getData();
46 $name = $this->getUser()->getId().'.json'; 46 $name = $this->getUser()->getId().'.json';
47 47
48 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 48 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
49 $res = $wallabag 49 $res = $wallabag
50 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 50 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
51 ->setMarkAsRead($markAsRead) 51 ->setMarkAsRead($markAsRead)
diff --git a/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php b/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php
index 92a167d9..f50424c1 100644
--- a/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php
+++ b/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php
@@ -15,6 +15,7 @@ class UploadImportType extends AbstractType
15 $builder 15 $builder
16 ->add('file', FileType::class, [ 16 ->add('file', FileType::class, [
17 'label' => 'import.form.file_label', 17 'label' => 'import.form.file_label',
18 'required' => true,
18 ]) 19 ])
19 ->add('mark_as_read', CheckboxType::class, [ 20 ->add('mark_as_read', CheckboxType::class, [
20 'label' => 'import.form.mark_as_read_label', 21 'label' => 'import.form.mark_as_read_label',
diff --git a/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php b/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php
new file mode 100644
index 00000000..74952847
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php
@@ -0,0 +1,74 @@
1<?php
2
3namespace Tests\Wallabag\ImportBundle\Command;
4
5use Symfony\Bundle\FrameworkBundle\Console\Application;
6use Symfony\Component\Console\Tester\CommandTester;
7use Wallabag\ImportBundle\Command\RedisWorkerCommand;
8use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
9use M6Web\Component\RedisMock\RedisMockFactory;
10
11class RedisWorkerCommandTest extends WallabagCoreTestCase
12{
13 /**
14 * @expectedException Symfony\Component\Console\Exception\RuntimeException
15 * @expectedExceptionMessage Not enough arguments (missing: "serviceName")
16 */
17 public function testRunRedisWorkerCommandWithoutArguments()
18 {
19 $application = new Application($this->getClient()->getKernel());
20 $application->add(new RedisWorkerCommand());
21
22 $command = $application->find('wallabag:import:redis-worker');
23
24 $tester = new CommandTester($command);
25 $tester->execute([
26 'command' => $command->getName(),
27 ]);
28 }
29
30 /**
31 * @expectedException Symfony\Component\Config\Definition\Exception\Exception
32 * @expectedExceptionMessage No queue or consumer found for service name
33 */
34 public function testRunRedisWorkerCommandWithBadService()
35 {
36 $application = new Application($this->getClient()->getKernel());
37 $application->add(new RedisWorkerCommand());
38
39 $command = $application->find('wallabag:import:redis-worker');
40
41 $tester = new CommandTester($command);
42 $tester->execute([
43 'command' => $command->getName(),
44 'serviceName' => 'YOMONSERVICE',
45 ]);
46 }
47
48 public function testRunRedisWorkerCommand()
49 {
50 $application = new Application($this->getClient()->getKernel());
51 $application->add(new RedisWorkerCommand());
52
53 $factory = new RedisMockFactory();
54 $redisMock = $factory->getAdapter('Predis\Client', true);
55
56 $application->getKernel()->getContainer()->set('wallabag_core.redis.client', $redisMock);
57
58 // put a fake message in the queue so the worker will stop after reading that message
59 // instead of waiting for others
60 $redisMock->lpush('wallabag.import.readability', '{}');
61
62 $command = $application->find('wallabag:import:redis-worker');
63
64 $tester = new CommandTester($command);
65 $tester->execute([
66 'command' => $command->getName(),
67 'serviceName' => 'readability',
68 '--maxIterations' => 1,
69 ]);
70
71 $this->assertContains('Worker started at', $tester->getDisplay());
72 $this->assertContains('Waiting for message', $tester->getDisplay());
73 }
74}
diff --git a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php
index 0ce7ce49..5e8ee41d 100644
--- a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php
+++ b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php
@@ -220,5 +220,6 @@ JSON;
220 $res = $consumer->manage($body); 220 $res = $consumer->manage($body);
221 221
222 $this->assertFalse($res); 222 $this->assertFalse($res);
223 $this->assertFalse($consumer->isStopJob($body));
223 } 224 }
224} 225}
diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
index 69635382..fb835f62 100644
--- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
@@ -51,6 +51,23 @@ class ReadabilityControllerTest extends WallabagCoreTestCase
51 $client->getContainer()->get('craue_config')->set('import_with_redis', 0); 51 $client->getContainer()->get('craue_config')->set('import_with_redis', 0);
52 } 52 }
53 53
54 public function testImportReadabilityBadFile()
55 {
56 $this->logInAs('admin');
57 $client = $this->getClient();
58
59 $crawler = $client->request('GET', '/import/readability');
60 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
61
62 $data = [
63 'upload_import_file[file]' => '',
64 ];
65
66 $client->submit($form, $data);
67
68 $this->assertEquals(200, $client->getResponse()->getStatusCode());
69 }
70
54 public function testImportReadabilityWithFile() 71 public function testImportReadabilityWithFile()
55 { 72 {
56 $this->logInAs('admin'); 73 $this->logInAs('admin');
diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
index 933ddd6c..f1113365 100644
--- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
@@ -51,6 +51,23 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase
51 $client->getContainer()->get('craue_config')->set('import_with_redis', 0); 51 $client->getContainer()->get('craue_config')->set('import_with_redis', 0);
52 } 52 }
53 53
54 public function testImportWallabagBadFile()
55 {
56 $this->logInAs('admin');
57 $client = $this->getClient();
58
59 $crawler = $client->request('GET', '/import/wallabag-v1');
60 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
61
62 $data = [
63 'upload_import_file[file]' => '',
64 ];
65
66 $client->submit($form, $data);
67
68 $this->assertEquals(200, $client->getResponse()->getStatusCode());
69 }
70
54 public function testImportWallabagWithFile() 71 public function testImportWallabagWithFile()
55 { 72 {
56 $this->logInAs('admin'); 73 $this->logInAs('admin');
diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php
index 36e5221d..b20226ad 100644
--- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php
@@ -51,6 +51,23 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase
51 $client->getContainer()->get('craue_config')->set('import_with_redis', 0); 51 $client->getContainer()->get('craue_config')->set('import_with_redis', 0);
52 } 52 }
53 53
54 public function testImportWallabagBadFile()
55 {
56 $this->logInAs('admin');
57 $client = $this->getClient();
58
59 $crawler = $client->request('GET', '/import/wallabag-v2');
60 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
61
62 $data = [
63 'upload_import_file[file]' => '',
64 ];
65
66 $client->submit($form, $data);
67
68 $this->assertEquals(200, $client->getResponse()->getStatusCode());
69 }
70
54 public function testImportWallabagWithFile() 71 public function testImportWallabagWithFile()
55 { 72 {
56 $this->logInAs('admin'); 73 $this->logInAs('admin');