aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Command
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle/Command')
-rw-r--r--tests/Wallabag/CoreBundle/Command/AdminNotificationCommandTest.php101
-rw-r--r--tests/Wallabag/CoreBundle/Command/ReleaseNotificationCommandTest.php96
2 files changed, 197 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/AdminNotificationCommandTest.php b/tests/Wallabag/CoreBundle/Command/AdminNotificationCommandTest.php
new file mode 100644
index 00000000..42d243dd
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Command/AdminNotificationCommandTest.php
@@ -0,0 +1,101 @@
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}
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
3namespace Tests\Wallabag\CoreBundle\Command;
4
5use Symfony\Bundle\FrameworkBundle\Console\Application;
6use Symfony\Component\Console\Tester\CommandTester;
7use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
8use Wallabag\CoreBundle\Command\ReleaseNotificationCommand;
9
10class 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}