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();
48 public function testRunReloadEntryCommand()
50 $application = new Application($this->getClient()->getKernel());
51 $application->add(new ReloadEntryCommand());
53 $command = $application->find('wallabag:entry:reload');
54 $tester = new CommandTester($command);
56 'command' => $command->getName(),
58 'interactive' => false,
61 $reloadedEntries = $this->getClient()
63 ->get('wallabag_core.entry_repository.test')
64 ->findById([$this->adminEntry
->getId(), $this->bobEntry
->getId()]);
66 foreach ($reloadedEntries as $reloadedEntry) {
67 $this->assertNotEmpty($reloadedEntry->getContent());
70 $this->assertContains('Done', $tester->getDisplay());
73 public function testRunReloadEntryWithUsernameCommand()
75 $application = new Application($this->getClient()->getKernel());
76 $application->add(new ReloadEntryCommand());
78 $command = $application->find('wallabag:entry:reload');
79 $tester = new CommandTester($command);
81 'command' => $command->getName(),
82 'username' => 'admin',
84 'interactive' => false,
87 $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository.test');
89 $reloadedAdminEntry = $entryRepository->find($this->adminEntry
->getId());
90 $this->assertNotEmpty($reloadedAdminEntry->getContent());
92 $reloadedBobEntry = $entryRepository->find($this->bobEntry
->getId());
93 $this->assertEmpty($reloadedBobEntry->getContent());
95 $this->assertContains('Done', $tester->getDisplay());
98 public function testRunReloadEntryWithoutEntryCommand()
100 $application = new Application($this->getClient()->getKernel());
101 $application->add(new ReloadEntryCommand());
103 $command = $application->find('wallabag:entry:reload');
104 $tester = new CommandTester($command);
106 'command' => $command->getName(),
107 'username' => 'empty',
109 'interactive' => false,
112 $this->assertContains('No entry to reload', $tester->getDisplay());
113 $this->assertNotContains('Done', $tester->getDisplay());