]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php
Enable OTP 2FA
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Command / ShowUserCommandTest.php
CommitLineData
d143fa24
TC
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Command;
4
5use Symfony\Bundle\FrameworkBundle\Console\Application;
6use Symfony\Component\Console\Tester\CommandTester;
d143fa24
TC
7use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
8use Wallabag\CoreBundle\Command\ShowUserCommand;
d143fa24
TC
9use Wallabag\UserBundle\Entity\User;
10
11class 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
e1b33efb
NH
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());
a6b242a1
JB
62 $this->assertContains('2FA (email) activated', $tester->getDisplay());
63 $this->assertContains('2FA (OTP) activated', $tester->getDisplay());
d143fa24
TC
64 }
65
66 public function testShowUser()
67 {
68 $client = $this->getClient();
69 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
70
71 $this->logInAs('admin');
72
73 /** @var User $user */
74 $user = $em->getRepository('WallabagUserBundle:User')->findOneById($this->getLoggedInUserId());
75
76 $user->setName('Bug boss');
77 $em->persist($user);
78
79 $em->flush();
80
81 $application = new Application($this->getClient()->getKernel());
82 $application->add(new ShowUserCommand());
83
84 $command = $application->find('wallabag:user:show');
85
86 $tester = new CommandTester($command);
87 $tester->execute([
88 'command' => $command->getName(),
89 'username' => 'admin',
90 ]);
91
e1b33efb 92 $this->assertContains('Display name: Bug boss', $tester->getDisplay());
d143fa24
TC
93 }
94}