From 511f1ce1e87e0f30a455ca6ed73e008bfd557f83 Mon Sep 17 00:00:00 2001 From: Nicolas Hart Date: Mon, 21 Aug 2017 10:36:56 +0200 Subject: Add reload entry command --- .../CoreBundle/Command/ReloadEntryCommandTest.php | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php new file mode 100644 index 00000000..63c068b4 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php @@ -0,0 +1,115 @@ +getClient()->getContainer()->get('wallabag_user.user_repository'); + + $user = $userRepository->findOneByUserName('admin'); + $this->adminEntry = new Entry($user); + $this->adminEntry->setUrl($this->url); + $this->adminEntry->setTitle('title foo'); + $this->adminEntry->setContent(''); + $this->getEntityManager()->persist($this->adminEntry); + + $user = $userRepository->findOneByUserName('bob'); + $this->bobEntry = new Entry($user); + $this->bobEntry->setUrl($this->url); + $this->bobEntry->setTitle('title foo'); + $this->bobEntry->setContent(''); + $this->getEntityManager()->persist($this->bobEntry); + + $this->getEntityManager()->flush(); + } + + public function testRunReloadEntryCommand() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ReloadEntryCommand()); + + $command = $application->find('wallabag:entry:reload'); + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + ], [ + 'interactive' => false, + ]); + + $reloadedEntries = $this->getClient() + ->getContainer() + ->get('wallabag_core.entry_repository') + ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]); + + foreach ($reloadedEntries as $reloadedEntry) { + $this->assertNotEmpty($reloadedEntry->getContent()); + } + + $this->assertContains('Done', $tester->getDisplay()); + } + + public function testRunReloadEntryWithUsernameCommand() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ReloadEntryCommand()); + + $command = $application->find('wallabag:entry:reload'); + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'username' => 'admin', + ], [ + 'interactive' => false, + ]); + + $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository'); + + $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId()); + $this->assertNotEmpty($reloadedAdminEntry->getContent()); + + $reloadedBobEntry = $entryRepository->find($this->bobEntry->getId()); + $this->assertEmpty($reloadedBobEntry->getContent()); + + $this->assertContains('Done', $tester->getDisplay()); + } + + public function testRunReloadEntryWithoutEntryCommand() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ReloadEntryCommand()); + + $command = $application->find('wallabag:entry:reload'); + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'username' => 'empty', + ], [ + 'interactive' => false, + ]); + + $this->assertContains('No entry to reload', $tester->getDisplay()); + $this->assertNotContains('Done', $tester->getDisplay()); + } +} -- cgit v1.2.3