]>
Commit | Line | Data |
---|---|---|
d143fa24 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; | |
d143fa24 TC |
7 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
8 | use Wallabag\CoreBundle\Command\ShowUserCommand; | |
d143fa24 TC |
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 | ||
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()); | |
0d8ecb82 | 62 | $this->assertContains('2FA activated: no', $tester->getDisplay()); |
d143fa24 TC |
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 | ||
e1b33efb | 91 | $this->assertContains('Display name: Bug boss', $tester->getDisplay()); |
d143fa24 TC |
92 | } |
93 | } |