]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/ImportBundle/Command/ImportCommandTest.php
Fix tests
[github/wallabag/wallabag.git] / tests / Wallabag / ImportBundle / Command / ImportCommandTest.php
CommitLineData
ebf5e508
JB
1<?php
2
3namespace Tests\Wallabag\ImportBundle\Command;
4
5use Symfony\Bundle\FrameworkBundle\Console\Application;
6use Symfony\Component\Console\Tester\CommandTester;
ebf5e508 7use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
f808b016 8use Wallabag\ImportBundle\Command\ImportCommand;
ebf5e508
JB
9
10class ImportCommandTest extends WallabagCoreTestCase
11{
12 /**
d1e5059e 13 * @expectedException \Symfony\Component\Console\Exception\RuntimeException
ebf5e508
JB
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 /**
d1e5059e 30 * @expectedException \Symfony\Component\Config\Definition\Exception\Exception
ebf5e508
JB
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(),
d1e5059e 43 'username' => 'admin',
ebf5e508
JB
44 'filepath' => 1,
45 ]);
46 }
47
48 /**
d1e5059e 49 * @expectedException \Doctrine\ORM\NoResultException
ebf5e508 50 */
d1e5059e 51 public function testRunImportCommandWithWrongUsername()
ebf5e508
JB
52 {
53 $application = new Application($this->getClient()->getKernel());
54 $application->add(new ImportCommand());
55
56 $command = $application->find('wallabag:import');
57
58 $tester = new CommandTester($command);
59 $tester->execute([
60 'command' => $command->getName(),
d1e5059e 61 'username' => 'random',
ebf5e508
JB
62 'filepath' => './',
63 ]);
64 }
65
66 public function testRunImportCommand()
67 {
68 $application = new Application($this->getClient()->getKernel());
69 $application->add(new ImportCommand());
70
71 $command = $application->find('wallabag:import');
72
73 $tester = new CommandTester($command);
74 $tester->execute([
75 'command' => $command->getName(),
d1e5059e 76 'username' => 'admin',
9ca069a6 77 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_dir') . '/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json',
ebf5e508
JB
78 '--importer' => 'v2',
79 ]);
80
81 $this->assertContains('imported', $tester->getDisplay());
82 $this->assertContains('already saved', $tester->getDisplay());
83 }
d1e5059e
TC
84
85 public function testRunImportCommandWithUserId()
86 {
8f2038e5
JB
87 $this->logInAs('admin');
88
d1e5059e
TC
89 $application = new Application($this->getClient()->getKernel());
90 $application->add(new ImportCommand());
91
92 $command = $application->find('wallabag:import');
93
94 $tester = new CommandTester($command);
95 $tester->execute([
96 'command' => $command->getName(),
8f2038e5 97 'username' => $this->getLoggedInUserId(),
9ca069a6 98 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_dir') . '/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json',
d1e5059e 99 '--useUserId' => true,
7ab5eb95 100 '--importer' => 'v2',
d1e5059e 101 ]);
acc0a801
JB
102
103 $this->assertContains('imported', $tester->getDisplay());
104 $this->assertContains('already saved', $tester->getDisplay());
d1e5059e 105 }
ebf5e508 106}