aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/ImportBundle/Command/ImportCommand.php6
-rw-r--r--tests/Wallabag/ImportBundle/Command/ImportCommandTest.php86
2 files changed, 91 insertions, 1 deletions
diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php
index a4aa8531..20ecc6e1 100644
--- a/src/Wallabag/ImportBundle/Command/ImportCommand.php
+++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php
@@ -26,6 +26,10 @@ class ImportCommand extends ContainerAwareCommand
26 { 26 {
27 $output->writeln('Start : '.(new \DateTime())->format('d-m-Y G:i:s').' ---'); 27 $output->writeln('Start : '.(new \DateTime())->format('d-m-Y G:i:s').' ---');
28 28
29 if (!file_exists($input->getArgument('filepath'))) {
30 throw new Exception(sprintf('File "%s" not found', $input->getArgument('filepath')));
31 }
32
29 $em = $this->getContainer()->get('doctrine')->getManager(); 33 $em = $this->getContainer()->get('doctrine')->getManager();
30 // Turning off doctrine default logs queries for saving memory 34 // Turning off doctrine default logs queries for saving memory
31 $em->getConnection()->getConfiguration()->setSQLLogger(null); 35 $em->getConnection()->getConfiguration()->setSQLLogger(null);
@@ -43,9 +47,9 @@ class ImportCommand extends ContainerAwareCommand
43 } 47 }
44 48
45 $wallabag->setMarkAsRead($input->getOption('markAsRead')); 49 $wallabag->setMarkAsRead($input->getOption('markAsRead'));
50 $wallabag->setUser($user);
46 51
47 $res = $wallabag 52 $res = $wallabag
48 ->setUser($user)
49 ->setFilepath($input->getArgument('filepath')) 53 ->setFilepath($input->getArgument('filepath'))
50 ->import(); 54 ->import();
51 55
diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php
new file mode 100644
index 00000000..eb7fce79
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php
@@ -0,0 +1,86 @@
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\ImportCommand;
8use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
9use M6Web\Component\RedisMock\RedisMockFactory;
10
11class ImportCommandTest extends WallabagCoreTestCase
12{
13 /**
14 * @expectedException Symfony\Component\Console\Exception\RuntimeException
15 * @expectedExceptionMessage Not enough arguments
16 */
17 public function testRunImportCommandWithoutArguments()
18 {
19 $application = new Application($this->getClient()->getKernel());
20 $application->add(new ImportCommand());
21
22 $command = $application->find('wallabag:import');
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 not found
33 */
34 public function testRunImportCommandWithoutFilepath()
35 {
36 $application = new Application($this->getClient()->getKernel());
37 $application->add(new ImportCommand());
38
39 $command = $application->find('wallabag:import');
40
41 $tester = new CommandTester($command);
42 $tester->execute([
43 'command' => $command->getName(),
44 'userId' => 1,
45 'filepath' => 1,
46 ]);
47 }
48
49 /**
50 * @expectedException Symfony\Component\Config\Definition\Exception\Exception
51 * @expectedExceptionMessage User with id
52 */
53 public function testRunImportCommandWithoutUserId()
54 {
55 $application = new Application($this->getClient()->getKernel());
56 $application->add(new ImportCommand());
57
58 $command = $application->find('wallabag:import');
59
60 $tester = new CommandTester($command);
61 $tester->execute([
62 'command' => $command->getName(),
63 'userId' => 0,
64 'filepath' => './',
65 ]);
66 }
67
68 public function testRunImportCommand()
69 {
70 $application = new Application($this->getClient()->getKernel());
71 $application->add(new ImportCommand());
72
73 $command = $application->find('wallabag:import');
74
75 $tester = new CommandTester($command);
76 $tester->execute([
77 'command' => $command->getName(),
78 'userId' => 1,
79 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.root_dir').'/../tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json',
80 '--importer' => 'v2',
81 ]);
82
83 $this->assertContains('imported', $tester->getDisplay());
84 $this->assertContains('already saved', $tester->getDisplay());
85 }
86}