3 namespace Tests\Wallabag\CoreBundle\Command
;
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
;
11 class AdminNotificationCommandTest
extends WallabagCoreTestCase
14 * @expectedException \Symfony\Component\Console\Exception\RuntimeException
15 * @expectedExceptionMessage Not enough arguments
17 public function testRunWithoutArguments()
19 $application = new Application($this->getClient()->getKernel());
20 $application->add(new AdminNotificationCommand());
22 $command = $application->find('wallabag:notification:send');
24 $tester = new CommandTester($command);
26 'command' => $command->getName(),
30 public function testRunSendNotificationCommandWithBadUsername()
32 $application = new Application($this->getClient()->getKernel());
33 $application->add(new AdminNotificationCommand());
35 $command = $application->find('wallabag:notification:send');
37 $tester = new CommandTester($command);
39 'command' => $command->getName(),
40 'username' => 'unknown',
45 $this->assertContains('User "unknown" not found', $tester->getDisplay());
48 public function testSendNotificationCommandForUser()
50 $application = new Application($this->getClient()->getKernel());
51 $application->add(new AdminNotificationCommand());
53 $command = $application->find('wallabag:notification:send');
55 $tester = new CommandTester($command);
57 'command' => $command->getName(),
58 'username' => 'admin',
63 $this->assertContains('Sent notification for user admin', $tester->getDisplay());
66 public function testSendNotificationCommand()
68 $client = $this->getClient();
69 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
71 $this->logInAs('admin');
73 $notifications = $em->getRepository('WallabagCoreBundle:Notification')->findByUser($this->getLoggedInUserId());
75 $this->assertCount(0, $notifications);
77 $application = new Application($this->getClient()->getKernel());
78 $application->add(new CleanDuplicatesCommand());
80 $command = $application->find('wallabag:notification:send');
82 $tester = new CommandTester($command);
84 'command' => $command->getName(),
85 'username' => 'admin',
90 $this->assertContains('Sent notification for user admin', $tester->getDisplay());
92 $notifications = $em->getRepository('WallabagCoreBundle:Notification')->findByUser($this->getLoggedInUserId());
94 $this->assertCount(1, $notifications);
96 $crawler = $client->request('GET', '/');
98 $this->assertEquals(200, $client->getResponse()->getStatusCode());
99 $this->assertCount(1, $crawler->filter('.notifications-area .collection'));