]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php
Merge pull request #3857 from wallabag/php73
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Command / ShowUserCommandTest.php
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 (email) activated', $tester->getDisplay());
63 $this->assertContains('2FA (OTP) activated', $tester->getDisplay());
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
92 $this->assertContains('Display name: Bug boss', $tester->getDisplay());
93 }
94 }