]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/CoreBundle/Command/AdminNotificationCommandTest.php
Notifications
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Command / AdminNotificationCommandTest.php
CommitLineData
378aaefb
TC
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Command;
4
5use Symfony\Bundle\FrameworkBundle\Console\Application;
6use Symfony\Component\Console\Tester\CommandTester;
7use Wallabag\CoreBundle\Command\AdminNotificationCommand;
8use Wallabag\CoreBundle\Command\CleanDuplicatesCommand;
9use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
10
11class AdminNotificationCommandTest extends WallabagCoreTestCase
12{
13 /**
14 * @expectedException \Symfony\Component\Console\Exception\RuntimeException
15 * @expectedExceptionMessage Not enough arguments
16 */
17 public function testRunWithoutArguments()
18 {
19 $application = new Application($this->getClient()->getKernel());
20 $application->add(new AdminNotificationCommand());
21
22 $command = $application->find('wallabag:notification:send');
23
24 $tester = new CommandTester($command);
25 $tester->execute([
26 'command' => $command->getName(),
27 ]);
28 }
29
30 public function testRunSendNotificationCommandWithBadUsername()
31 {
32 $application = new Application($this->getClient()->getKernel());
33 $application->add(new AdminNotificationCommand());
34
35 $command = $application->find('wallabag:notification:send');
36
37 $tester = new CommandTester($command);
38 $tester->execute([
39 'command' => $command->getName(),
40 'username' => 'unknown',
41 'title' => 'foo',
42 'message' => 'bar'
43 ]);
44
45 $this->assertContains('User "unknown" not found', $tester->getDisplay());
46 }
47
48 public function testSendNotificationCommandForUser()
49 {
50 $application = new Application($this->getClient()->getKernel());
51 $application->add(new AdminNotificationCommand());
52
53 $command = $application->find('wallabag:notification:send');
54
55 $tester = new CommandTester($command);
56 $tester->execute([
57 'command' => $command->getName(),
58 'username' => 'admin',
59 'title' => 'foo',
60 'message' => 'bar'
61 ]);
62
63 $this->assertContains('Sent notification for user admin', $tester->getDisplay());
64 }
65
66 public function testSendNotificationCommand()
67 {
68 $client = $this->getClient();
69 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
70
71 $this->logInAs('admin');
72
73 $notifications = $em->getRepository('WallabagCoreBundle:Notification')->findByUser($this->getLoggedInUserId());
74
75 $this->assertCount(0, $notifications);
76
77 $application = new Application($this->getClient()->getKernel());
78 $application->add(new CleanDuplicatesCommand());
79
80 $command = $application->find('wallabag:notification:send');
81
82 $tester = new CommandTester($command);
83 $tester->execute([
84 'command' => $command->getName(),
85 'username' => 'admin',
86 'title' => 'foo',
87 'message' => 'bar'
88 ]);
89
90 $this->assertContains('Sent notification for user admin', $tester->getDisplay());
91
92 $notifications = $em->getRepository('WallabagCoreBundle:Notification')->findByUser($this->getLoggedInUserId());
93
94 $this->assertCount(1, $notifications);
95
96 $crawler = $client->request('GET', '/');
97
98 $this->assertEquals(200, $client->getResponse()->getStatusCode());
99 $this->assertCount(1, $crawler->filter('.notifications-area .collection'));
100 }
101}