diff options
Diffstat (limited to 'tests/Wallabag/ImportBundle/Command/ImportCommandTest.php')
-rw-r--r-- | tests/Wallabag/ImportBundle/Command/ImportCommandTest.php | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php new file mode 100644 index 00000000..7be1eb18 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php | |||
@@ -0,0 +1,85 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ImportBundle\Command; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
6 | use Symfony\Component\Console\Tester\CommandTester; | ||
7 | use Wallabag\ImportBundle\Command\ImportCommand; | ||
8 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
9 | |||
10 | class ImportCommandTest extends WallabagCoreTestCase | ||
11 | { | ||
12 | /** | ||
13 | * @expectedException Symfony\Component\Console\Exception\RuntimeException | ||
14 | * @expectedExceptionMessage Not enough arguments | ||
15 | */ | ||
16 | public function testRunImportCommandWithoutArguments() | ||
17 | { | ||
18 | $application = new Application($this->getClient()->getKernel()); | ||
19 | $application->add(new ImportCommand()); | ||
20 | |||
21 | $command = $application->find('wallabag:import'); | ||
22 | |||
23 | $tester = new CommandTester($command); | ||
24 | $tester->execute([ | ||
25 | 'command' => $command->getName(), | ||
26 | ]); | ||
27 | } | ||
28 | |||
29 | /** | ||
30 | * @expectedException Symfony\Component\Config\Definition\Exception\Exception | ||
31 | * @expectedExceptionMessage not found | ||
32 | */ | ||
33 | public function testRunImportCommandWithoutFilepath() | ||
34 | { | ||
35 | $application = new Application($this->getClient()->getKernel()); | ||
36 | $application->add(new ImportCommand()); | ||
37 | |||
38 | $command = $application->find('wallabag:import'); | ||
39 | |||
40 | $tester = new CommandTester($command); | ||
41 | $tester->execute([ | ||
42 | 'command' => $command->getName(), | ||
43 | 'userId' => 1, | ||
44 | 'filepath' => 1, | ||
45 | ]); | ||
46 | } | ||
47 | |||
48 | /** | ||
49 | * @expectedException Symfony\Component\Config\Definition\Exception\Exception | ||
50 | * @expectedExceptionMessage User with id | ||
51 | */ | ||
52 | public function testRunImportCommandWithoutUserId() | ||
53 | { | ||
54 | $application = new Application($this->getClient()->getKernel()); | ||
55 | $application->add(new ImportCommand()); | ||
56 | |||
57 | $command = $application->find('wallabag:import'); | ||
58 | |||
59 | $tester = new CommandTester($command); | ||
60 | $tester->execute([ | ||
61 | 'command' => $command->getName(), | ||
62 | 'userId' => 0, | ||
63 | 'filepath' => './', | ||
64 | ]); | ||
65 | } | ||
66 | |||
67 | public function testRunImportCommand() | ||
68 | { | ||
69 | $application = new Application($this->getClient()->getKernel()); | ||
70 | $application->add(new ImportCommand()); | ||
71 | |||
72 | $command = $application->find('wallabag:import'); | ||
73 | |||
74 | $tester = new CommandTester($command); | ||
75 | $tester->execute([ | ||
76 | 'command' => $command->getName(), | ||
77 | 'userId' => 1, | ||
78 | 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.root_dir').'/../tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', | ||
79 | '--importer' => 'v2', | ||
80 | ]); | ||
81 | |||
82 | $this->assertContains('imported', $tester->getDisplay()); | ||
83 | $this->assertContains('already saved', $tester->getDisplay()); | ||
84 | } | ||
85 | } | ||