diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Command')
-rw-r--r-- | tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php new file mode 100644 index 00000000..c0a4acfa --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php | |||
@@ -0,0 +1,93 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\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\CoreBundle\Command\ShowUserCommand; | ||
9 | use Wallabag\UserBundle\Entity\User; | ||
10 | |||
11 | class ShowUserCommandTest extends WallabagCoreTestCase | ||
12 | { | ||
13 | /** | ||
14 | * @expectedException \Symfony\Component\Console\Exception\RuntimeException | ||
15 | * @expectedExceptionMessage Not enough arguments | ||
16 | */ | ||
17 | public function testRunShowUserCommandWithoutUsername() | ||
18 | { | ||
19 | $application = new Application($this->getClient()->getKernel()); | ||
20 | $application->add(new ShowUserCommand()); | ||
21 | |||
22 | $command = $application->find('wallabag:user:show'); | ||
23 | |||
24 | $tester = new CommandTester($command); | ||
25 | $tester->execute([ | ||
26 | 'command' => $command->getName(), | ||
27 | ]); | ||
28 | } | ||
29 | |||
30 | public function testRunShowUserCommandWithBadUsername() | ||
31 | { | ||
32 | $application = new Application($this->getClient()->getKernel()); | ||
33 | $application->add(new ShowUserCommand()); | ||
34 | |||
35 | $command = $application->find('wallabag:user:show'); | ||
36 | |||
37 | $tester = new CommandTester($command); | ||
38 | $tester->execute([ | ||
39 | 'command' => $command->getName(), | ||
40 | 'username' => 'unknown', | ||
41 | ]); | ||
42 | |||
43 | $this->assertContains('User "unknown" not found', $tester->getDisplay()); | ||
44 | } | ||
45 | |||
46 | public function testRunShowUserCommandForUser() | ||
47 | { | ||
48 | $application = new Application($this->getClient()->getKernel()); | ||
49 | $application->add(new ShowUserCommand()); | ||
50 | |||
51 | $command = $application->find('wallabag:user:show'); | ||
52 | |||
53 | $tester = new CommandTester($command); | ||
54 | $tester->execute([ | ||
55 | 'command' => $command->getName(), | ||
56 | 'username' => 'admin', | ||
57 | ]); | ||
58 | |||
59 | $this->assertContains('Username : admin', $tester->getDisplay()); | ||
60 | $this->assertContains('Email : bigboss@wallabag.org', $tester->getDisplay()); | ||
61 | $this->assertContains('Display name : Big boss', $tester->getDisplay()); | ||
62 | $this->assertContains('2FA activated: no', $tester->getDisplay()); | ||
63 | } | ||
64 | |||
65 | public function testShowUser() | ||
66 | { | ||
67 | $client = $this->getClient(); | ||
68 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
69 | |||
70 | $this->logInAs('admin'); | ||
71 | |||
72 | /** @var User $user */ | ||
73 | $user = $em->getRepository('WallabagUserBundle:User')->findOneById($this->getLoggedInUserId()); | ||
74 | |||
75 | $user->setName('Bug boss'); | ||
76 | $em->persist($user); | ||
77 | |||
78 | $em->flush(); | ||
79 | |||
80 | $application = new Application($this->getClient()->getKernel()); | ||
81 | $application->add(new ShowUserCommand()); | ||
82 | |||
83 | $command = $application->find('wallabag:user:show'); | ||
84 | |||
85 | $tester = new CommandTester($command); | ||
86 | $tester->execute([ | ||
87 | 'command' => $command->getName(), | ||
88 | 'username' => 'admin', | ||
89 | ]); | ||
90 | |||
91 | $this->assertContains('Display name : Bug boss', $tester->getDisplay()); | ||
92 | } | ||
93 | } | ||