]>
Commit | Line | Data |
---|---|---|
8303b037 TC |
1 | <?php |
2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Command; | |
4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Console\Application; | |
6 | use Symfony\Component\Console\Tester\CommandTester; | |
8303b037 | 7 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
f808b016 | 8 | use Wallabag\CoreBundle\Command\ExportCommand; |
8303b037 TC |
9 | |
10 | class ExportCommandTest extends WallabagCoreTestCase | |
11 | { | |
12 | /** | |
bad7df8c | 13 | * @expectedException \Symfony\Component\Console\Exception\RuntimeException |
8303b037 TC |
14 | * @expectedExceptionMessage Not enough arguments (missing: "username") |
15 | */ | |
16 | public function testExportCommandWithoutUsername() | |
17 | { | |
18 | $application = new Application($this->getClient()->getKernel()); | |
19 | $application->add(new ExportCommand()); | |
20 | ||
21 | $command = $application->find('wallabag:export'); | |
22 | ||
23 | $tester = new CommandTester($command); | |
24 | $tester->execute([ | |
25 | 'command' => $command->getName(), | |
26 | ]); | |
27 | } | |
28 | ||
29 | public function testExportCommandWithBadUsername() | |
30 | { | |
31 | $application = new Application($this->getClient()->getKernel()); | |
32 | $application->add(new ExportCommand()); | |
33 | ||
34 | $command = $application->find('wallabag:export'); | |
35 | ||
36 | $tester = new CommandTester($command); | |
37 | $tester->execute([ | |
38 | 'command' => $command->getName(), | |
39 | 'username' => 'unknown', | |
40 | ]); | |
41 | ||
42 | $this->assertContains('User "unknown" not found', $tester->getDisplay()); | |
43 | } | |
44 | ||
45 | public function testExportCommand() | |
46 | { | |
47 | $application = new Application($this->getClient()->getKernel()); | |
48 | $application->add(new ExportCommand()); | |
49 | ||
50 | $command = $application->find('wallabag:export'); | |
51 | ||
52 | $tester = new CommandTester($command); | |
53 | $tester->execute([ | |
54 | 'command' => $command->getName(), | |
55 | 'username' => 'admin', | |
56 | ]); | |
57 | ||
e1b33efb NH |
58 | $this->assertContains('Exporting 5 entrie(s) for user admin...', $tester->getDisplay()); |
59 | $this->assertContains('Done', $tester->getDisplay()); | |
3b0380f0 | 60 | $this->assertFileExists('admin-export.json'); |
8303b037 | 61 | } |
a607b7a9 TC |
62 | |
63 | public function testExportCommandWithSpecialPath() | |
64 | { | |
65 | $application = new Application($this->getClient()->getKernel()); | |
66 | $application->add(new ExportCommand()); | |
67 | ||
68 | $command = $application->find('wallabag:export'); | |
69 | ||
70 | $tester = new CommandTester($command); | |
71 | $tester->execute([ | |
72 | 'command' => $command->getName(), | |
73 | 'username' => 'admin', | |
d09fe4d2 | 74 | 'filepath' => 'specialexport.json', |
a607b7a9 TC |
75 | ]); |
76 | ||
77 | $this->assertFileExists('specialexport.json'); | |
78 | } | |
8303b037 | 79 | } |