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\ReloadEntryCommand
;
9 use Wallabag\CoreBundle\Entity\Entry
;
11 class ReloadEntryCommandTest
extends WallabagCoreTestCase
13 public $url = 'https://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html';
25 public function setUp()
29 $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository.test');
31 $user = $userRepository->findOneByUserName('admin');
32 $this->adminEntry
= new Entry($user);
33 $this->adminEntry
->setUrl($this->url
);
34 $this->adminEntry
->setTitle('title foo');
35 $this->adminEntry
->setContent('');
36 $this->getEntityManager()->persist($this->adminEntry
);
38 $user = $userRepository->findOneByUserName('bob');
39 $this->bobEntry
= new Entry($user);
40 $this->bobEntry
->setUrl($this->url
);
41 $this->bobEntry
->setTitle('title foo');
42 $this->bobEntry
->setContent('');
43 $this->getEntityManager()->persist($this->bobEntry
);
45 $this->getEntityManager()->flush();
51 public function testRunReloadEntryCommand()
53 $application = new Application($this->getClient()->getKernel());
54 $application->add(new ReloadEntryCommand());
56 $command = $application->find('wallabag:entry:reload');
57 $tester = new CommandTester($command);
59 'command' => $command->getName(),
61 'interactive' => false,
64 $reloadedEntries = $this->getClient()
66 ->get('wallabag_core.entry_repository.test')
67 ->findById([$this->adminEntry
->getId(), $this->bobEntry
->getId()]);
69 foreach ($reloadedEntries as $reloadedEntry) {
70 $this->assertNotEmpty($reloadedEntry->getContent());
73 $this->assertContains('Done', $tester->getDisplay());
79 public function testRunReloadEntryWithUsernameCommand()
81 $application = new Application($this->getClient()->getKernel());
82 $application->add(new ReloadEntryCommand());
84 $command = $application->find('wallabag:entry:reload');
85 $tester = new CommandTester($command);
87 'command' => $command->getName(),
88 'username' => 'admin',
90 'interactive' => false,
93 $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository.test');
95 $reloadedAdminEntry = $entryRepository->find($this->adminEntry
->getId());
96 $this->assertNotEmpty($reloadedAdminEntry->getContent());
98 $reloadedBobEntry = $entryRepository->find($this->bobEntry
->getId());
99 $this->assertEmpty($reloadedBobEntry->getContent());
101 $this->assertContains('Done', $tester->getDisplay());
104 public function testRunReloadEntryWithoutEntryCommand()
106 $application = new Application($this->getClient()->getKernel());
107 $application->add(new ReloadEntryCommand());
109 $command = $application->find('wallabag:entry:reload');
110 $tester = new CommandTester($command);
112 'command' => $command->getName(),
113 'username' => 'empty',
115 'interactive' => false,
118 $this->assertContains('No entry to reload', $tester->getDisplay());
119 $this->assertNotContains('Done', $tester->getDisplay());