3 namespace Tests\Wallabag\CoreBundle\Command
;
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
;
10 class ReleaseNotificationCommandTest
extends WallabagCoreTestCase
12 public function testRunWithoutArguments()
14 $application = new Application($this->getClient()->getKernel());
15 $application->add(new ReleaseNotificationCommand());
17 $command = $application->find('wallabag:notification:release');
19 $tester = new CommandTester($command);
21 'command' => $command->getName(),
24 $this->assertContains('Sent notification for user admin', $tester->getDisplay());
25 $this->assertContains('Finished sending notifications.', $tester->getDisplay());
28 public function testRunSendReleaseNotificationCommandWithBadUsername()
30 $application = new Application($this->getClient()->getKernel());
31 $application->add(new ReleaseNotificationCommand());
33 $command = $application->find('wallabag:notification:release');
35 $tester = new CommandTester($command);
37 'command' => $command->getName(),
38 'username' => 'unknown',
39 'link' => 'https://wallabag.org',
42 $this->assertContains('User "unknown" not found', $tester->getDisplay());
45 public function testSendReleaseNotificationCommandForUser()
47 $application = new Application($this->getClient()->getKernel());
48 $application->add(new ReleaseNotificationCommand());
50 $command = $application->find('wallabag:notification:release');
52 $tester = new CommandTester($command);
54 'command' => $command->getName(),
55 'username' => 'admin',
56 'link' => 'https://wallabag.org',
59 $this->assertContains('Sent notification for user admin', $tester->getDisplay());
62 public function testSendReleaseNotificationCommand()
64 $client = $this->getClient();
65 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
67 $this->logInAs('admin');
69 $notifications = $em->getRepository('WallabagCoreBundle:Notification')->findByUser($this->getLoggedInUserId());
71 $this->assertCount(0, $notifications);
73 $application = new Application($this->getClient()->getKernel());
74 $application->add(new ReleaseNotificationCommand());
76 $command = $application->find('wallabag:notification:release');
78 $tester = new CommandTester($command);
80 'command' => $command->getName(),
81 'username' => 'admin',
82 'link' => 'https://wallabag.org',
85 $this->assertContains('Sent notification for user admin', $tester->getDisplay());
87 $notifications = $em->getRepository('WallabagCoreBundle:Notification')->findByUser($this->getLoggedInUserId());
89 $this->assertCount(1, $notifications);
91 $crawler = $client->request('GET', '/');
93 $this->assertEquals(200, $client->getResponse()->getStatusCode());
94 $this->assertCount(1, $crawler->filter('.notifications-area .collection'));