]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php
tests: add a NetworkCalls group for tests making network calls
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Command / ReloadEntryCommandTest.php
1 <?php
2
3 namespace Tests\Wallabag\CoreBundle\Command;
4
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;
10
11 class ReloadEntryCommandTest extends WallabagCoreTestCase
12 {
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';
14
15 /**
16 * @var entry
17 */
18 public $adminEntry;
19
20 /**
21 * @var Entry
22 */
23 public $bobEntry;
24
25 public function setUp()
26 {
27 parent::setUp();
28
29 $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository.test');
30
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);
37
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);
44
45 $this->getEntityManager()->flush();
46 }
47
48 /**
49 * @group NetworkCalls
50 */
51 public function testRunReloadEntryCommand()
52 {
53 $application = new Application($this->getClient()->getKernel());
54 $application->add(new ReloadEntryCommand());
55
56 $command = $application->find('wallabag:entry:reload');
57 $tester = new CommandTester($command);
58 $tester->execute([
59 'command' => $command->getName(),
60 ], [
61 'interactive' => false,
62 ]);
63
64 $reloadedEntries = $this->getClient()
65 ->getContainer()
66 ->get('wallabag_core.entry_repository.test')
67 ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]);
68
69 foreach ($reloadedEntries as $reloadedEntry) {
70 $this->assertNotEmpty($reloadedEntry->getContent());
71 }
72
73 $this->assertContains('Done', $tester->getDisplay());
74 }
75
76 /**
77 * @group NetworkCalls
78 */
79 public function testRunReloadEntryWithUsernameCommand()
80 {
81 $application = new Application($this->getClient()->getKernel());
82 $application->add(new ReloadEntryCommand());
83
84 $command = $application->find('wallabag:entry:reload');
85 $tester = new CommandTester($command);
86 $tester->execute([
87 'command' => $command->getName(),
88 'username' => 'admin',
89 ], [
90 'interactive' => false,
91 ]);
92
93 $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository.test');
94
95 $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId());
96 $this->assertNotEmpty($reloadedAdminEntry->getContent());
97
98 $reloadedBobEntry = $entryRepository->find($this->bobEntry->getId());
99 $this->assertEmpty($reloadedBobEntry->getContent());
100
101 $this->assertContains('Done', $tester->getDisplay());
102 }
103
104 public function testRunReloadEntryWithoutEntryCommand()
105 {
106 $application = new Application($this->getClient()->getKernel());
107 $application->add(new ReloadEntryCommand());
108
109 $command = $application->find('wallabag:entry:reload');
110 $tester = new CommandTester($command);
111 $tester->execute([
112 'command' => $command->getName(),
113 'username' => 'empty',
114 ], [
115 'interactive' => false,
116 ]);
117
118 $this->assertContains('No entry to reload', $tester->getDisplay());
119 $this->assertNotContains('Done', $tester->getDisplay());
120 }
121 }