aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag')
-rw-r--r--tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php115
1 files changed, 115 insertions, 0 deletions
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 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Command;
4
5use Symfony\Bundle\FrameworkBundle\Console\Application;
6use Symfony\Component\Console\Tester\CommandTester;
7use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
8use Wallabag\CoreBundle\Command\ReloadEntryCommand;
9use Wallabag\CoreBundle\Entity\Entry;
10
11class ReloadEntryCommandTest extends WallabagCoreTestCase
12{
13 public $url = 'http://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');
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 public function testRunReloadEntryCommand()
49 {
50 $application = new Application($this->getClient()->getKernel());
51 $application->add(new ReloadEntryCommand());
52
53 $command = $application->find('wallabag:entry:reload');
54 $tester = new CommandTester($command);
55 $tester->execute([
56 'command' => $command->getName(),
57 ], [
58 'interactive' => false,
59 ]);
60
61 $reloadedEntries = $this->getClient()
62 ->getContainer()
63 ->get('wallabag_core.entry_repository')
64 ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]);
65
66 foreach ($reloadedEntries as $reloadedEntry) {
67 $this->assertNotEmpty($reloadedEntry->getContent());
68 }
69
70 $this->assertContains('Done', $tester->getDisplay());
71 }
72
73 public function testRunReloadEntryWithUsernameCommand()
74 {
75 $application = new Application($this->getClient()->getKernel());
76 $application->add(new ReloadEntryCommand());
77
78 $command = $application->find('wallabag:entry:reload');
79 $tester = new CommandTester($command);
80 $tester->execute([
81 'command' => $command->getName(),
82 'username' => 'admin',
83 ], [
84 'interactive' => false,
85 ]);
86
87 $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository');
88
89 $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId());
90 $this->assertNotEmpty($reloadedAdminEntry->getContent());
91
92 $reloadedBobEntry = $entryRepository->find($this->bobEntry->getId());
93 $this->assertEmpty($reloadedBobEntry->getContent());
94
95 $this->assertContains('Done', $tester->getDisplay());
96 }
97
98 public function testRunReloadEntryWithoutEntryCommand()
99 {
100 $application = new Application($this->getClient()->getKernel());
101 $application->add(new ReloadEntryCommand());
102
103 $command = $application->find('wallabag:entry:reload');
104 $tester = new CommandTester($command);
105 $tester->execute([
106 'command' => $command->getName(),
107 'username' => 'empty',
108 ], [
109 'interactive' => false,
110 ]);
111
112 $this->assertContains('No entry to reload', $tester->getDisplay());
113 $this->assertNotContains('Done', $tester->getDisplay());
114 }
115}