diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Command/ReleaseNotificationCommandTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Command/ReleaseNotificationCommandTest.php | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/ReleaseNotificationCommandTest.php b/tests/Wallabag/CoreBundle/Command/ReleaseNotificationCommandTest.php new file mode 100644 index 00000000..9b1990a2 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/ReleaseNotificationCommandTest.php | |||
@@ -0,0 +1,96 @@ | |||
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\ReleaseNotificationCommand; | ||
9 | |||
10 | class ReleaseNotificationCommandTest extends WallabagCoreTestCase | ||
11 | { | ||
12 | public function testRunWithoutArguments() | ||
13 | { | ||
14 | $application = new Application($this->getClient()->getKernel()); | ||
15 | $application->add(new ReleaseNotificationCommand()); | ||
16 | |||
17 | $command = $application->find('wallabag:notification:release'); | ||
18 | |||
19 | $tester = new CommandTester($command); | ||
20 | $tester->execute([ | ||
21 | 'command' => $command->getName(), | ||
22 | ]); | ||
23 | |||
24 | $this->assertContains('Sent notification for user admin', $tester->getDisplay()); | ||
25 | $this->assertContains('Finished sending notifications.', $tester->getDisplay()); | ||
26 | } | ||
27 | |||
28 | public function testRunSendReleaseNotificationCommandWithBadUsername() | ||
29 | { | ||
30 | $application = new Application($this->getClient()->getKernel()); | ||
31 | $application->add(new ReleaseNotificationCommand()); | ||
32 | |||
33 | $command = $application->find('wallabag:notification:release'); | ||
34 | |||
35 | $tester = new CommandTester($command); | ||
36 | $tester->execute([ | ||
37 | 'command' => $command->getName(), | ||
38 | 'username' => 'unknown', | ||
39 | 'link' => 'https://wallabag.org', | ||
40 | ]); | ||
41 | |||
42 | $this->assertContains('User "unknown" not found', $tester->getDisplay()); | ||
43 | } | ||
44 | |||
45 | public function testSendReleaseNotificationCommandForUser() | ||
46 | { | ||
47 | $application = new Application($this->getClient()->getKernel()); | ||
48 | $application->add(new ReleaseNotificationCommand()); | ||
49 | |||
50 | $command = $application->find('wallabag:notification:release'); | ||
51 | |||
52 | $tester = new CommandTester($command); | ||
53 | $tester->execute([ | ||
54 | 'command' => $command->getName(), | ||
55 | 'username' => 'admin', | ||
56 | 'link' => 'https://wallabag.org', | ||
57 | ]); | ||
58 | |||
59 | $this->assertContains('Sent notification for user admin', $tester->getDisplay()); | ||
60 | } | ||
61 | |||
62 | public function testSendReleaseNotificationCommand() | ||
63 | { | ||
64 | $client = $this->getClient(); | ||
65 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
66 | |||
67 | $this->logInAs('admin'); | ||
68 | |||
69 | $notifications = $em->getRepository('WallabagCoreBundle:Notification')->findByUser($this->getLoggedInUserId()); | ||
70 | |||
71 | $this->assertCount(0, $notifications); | ||
72 | |||
73 | $application = new Application($this->getClient()->getKernel()); | ||
74 | $application->add(new ReleaseNotificationCommand()); | ||
75 | |||
76 | $command = $application->find('wallabag:notification:release'); | ||
77 | |||
78 | $tester = new CommandTester($command); | ||
79 | $tester->execute([ | ||
80 | 'command' => $command->getName(), | ||
81 | 'username' => 'admin', | ||
82 | 'link' => 'https://wallabag.org', | ||
83 | ]); | ||
84 | |||
85 | $this->assertContains('Sent notification for user admin', $tester->getDisplay()); | ||
86 | |||
87 | $notifications = $em->getRepository('WallabagCoreBundle:Notification')->findByUser($this->getLoggedInUserId()); | ||
88 | |||
89 | $this->assertCount(1, $notifications); | ||
90 | |||
91 | $crawler = $client->request('GET', '/'); | ||
92 | |||
93 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
94 | $this->assertCount(1, $crawler->filter('.notifications-area .collection')); | ||
95 | } | ||
96 | } | ||