aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php
blob: c4bd6dacecbc50d1317e00b30c6939332d01df28 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php

namespace Tests\Wallabag\CoreBundle\Command;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\CoreBundle\Command\ReloadEntryCommand;
use Wallabag\CoreBundle\Entity\Entry;

class ReloadEntryCommandTest extends WallabagCoreTestCase
{
    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';

    /**
     * @var entry
     */
    public $adminEntry;

    /**
     * @var Entry
     */
    public $bobEntry;

    public function setUp()
    {
        parent::setUp();

        $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository.test');

        $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.test')
            ->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.test');

        $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());
    }
}