]>
Commit | Line | Data |
---|---|---|
ebf5e508 JB |
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; | |
ebf5e508 JB |
9 | |
10 | class 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', |
ebf5e508 JB |
77 | 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.root_dir').'/../tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', |
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 | { | |
87 | $application = new Application($this->getClient()->getKernel()); | |
88 | $application->add(new ImportCommand()); | |
89 | ||
90 | $command = $application->find('wallabag:import'); | |
91 | ||
92 | $tester = new CommandTester($command); | |
93 | $tester->execute([ | |
94 | 'command' => $command->getName(), | |
95 | 'username' => 1, | |
96 | 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.root_dir').'/../tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', | |
97 | '--useUserId' => true, | |
98 | ]); | |
99 | } | |
ebf5e508 | 100 | } |