diff options
Diffstat (limited to 'tests')
4 files changed, 234 insertions, 1 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 | |||
3 | namespace Tests\Wallabag\CoreBundle\Command; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
6 | use Symfony\Component\Console\Tester\CommandTester; | ||
7 | use Wallabag\CoreBundle\Command\AdminNotificationCommand; | ||
8 | use Wallabag\CoreBundle\Command\CleanDuplicatesCommand; | ||
9 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
10 | |||
11 | class 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 | |||
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 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Controller/NotificationControllerTest.php b/tests/Wallabag/CoreBundle/Controller/NotificationControllerTest.php new file mode 100644 index 00000000..e92528ca --- /dev/null +++ b/tests/Wallabag/CoreBundle/Controller/NotificationControllerTest.php | |||
@@ -0,0 +1,32 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | use Wallabag\CoreBundle\Entity\Notification; | ||
7 | |||
8 | class NotificationControllerTest extends WallabagCoreTestCase | ||
9 | { | ||
10 | public function testDisplayNotification() | ||
11 | { | ||
12 | $this->logInAs('admin'); | ||
13 | |||
14 | $client = $this->getClient(); | ||
15 | |||
16 | $em = $client->getContainer() | ||
17 | ->get('doctrine.orm.entity_manager'); | ||
18 | |||
19 | $notification = new Notification($this->getLoggedInUser()); | ||
20 | $notification->setType(Notification::TYPE_USER) | ||
21 | ->setTitle('fooTitle') | ||
22 | ->setDescription('barDescription'); | ||
23 | |||
24 | $em->persist($notification); | ||
25 | $em->flush(); | ||
26 | |||
27 | $crawler = $client->request('GET', '/'); | ||
28 | $this->assertCount(1, $notificationArea = $crawler->filter('.notifications-area .collection')); | ||
29 | $this->assertContains('fooTitle', $notificationArea->text()); | ||
30 | $this->assertContains('barDescription', $notificationArea->text()); | ||
31 | } | ||
32 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php index ceec4b37..1fca2251 100644 --- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php +++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php | |||
@@ -16,6 +16,10 @@ class WallabagExtensionTest extends \PHPUnit_Framework_TestCase | |||
16 | ->disableOriginalConstructor() | 16 | ->disableOriginalConstructor() |
17 | ->getMock(); | 17 | ->getMock(); |
18 | 18 | ||
19 | $notificationRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\NotificationRepository') | ||
20 | ->disableOriginalConstructor() | ||
21 | ->getMock(); | ||
22 | |||
19 | $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') | 23 | $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') |
20 | ->disableOriginalConstructor() | 24 | ->disableOriginalConstructor() |
21 | ->getMock(); | 25 | ->getMock(); |
@@ -24,7 +28,7 @@ class WallabagExtensionTest extends \PHPUnit_Framework_TestCase | |||
24 | ->disableOriginalConstructor() | 28 | ->disableOriginalConstructor() |
25 | ->getMock(); | 29 | ->getMock(); |
26 | 30 | ||
27 | $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator); | 31 | $extension = new WallabagExtension($entryRepository, $tagRepository, $notificationRepository, $tokenStorage, 0, 5, $translator); |
28 | 32 | ||
29 | $this->assertSame('lemonde.fr', $extension->removeWww('www.lemonde.fr')); | 33 | $this->assertSame('lemonde.fr', $extension->removeWww('www.lemonde.fr')); |
30 | $this->assertSame('lemonde.fr', $extension->removeWww('lemonde.fr')); | 34 | $this->assertSame('lemonde.fr', $extension->removeWww('lemonde.fr')); |