]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/ImportBundle/Command/ImportCommandTest.php
Fix tests
[github/wallabag/wallabag.git] / tests / Wallabag / ImportBundle / Command / ImportCommandTest.php
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 Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
8 use Wallabag\ImportBundle\Command\ImportCommand;
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 'username' => 'admin',
44 'filepath' => 1,
45 ]);
46 }
47
48 /**
49 * @expectedException \Doctrine\ORM\NoResultException
50 */
51 public function testRunImportCommandWithWrongUsername()
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(),
61 'username' => 'random',
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(),
76 'username' => 'admin',
77 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_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 }
84
85 public function testRunImportCommandWithUserId()
86 {
87 $this->logInAs('admin');
88
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(),
97 'username' => $this->getLoggedInUserId(),
98 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_dir') . '/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json',
99 '--useUserId' => true,
100 '--importer' => 'v2',
101 ]);
102
103 $this->assertContains('imported', $tester->getDisplay());
104 $this->assertContains('already saved', $tester->getDisplay());
105 }
106 }