wallabag/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php

122 lines
3.9 KiB
PHP
Raw Normal View History

2017-08-21 08:36:56 +00:00
<?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
{
2018-06-06 15:34:20 +00:00
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';
2017-08-21 08:36:56 +00:00
/**
* @var entry
*/
public $adminEntry;
/**
* @var Entry
*/
public $bobEntry;
2020-12-08 08:17:10 +00:00
protected function setUp(): void
2017-08-21 08:36:56 +00:00
{
parent::setUp();
$userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository.test');
2017-08-21 08:36:56 +00:00
$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();
}
/**
* @group NetworkCalls
*/
2017-08-21 08:36:56 +00:00
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')
2017-08-21 08:36:56 +00:00
->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]);
foreach ($reloadedEntries as $reloadedEntry) {
$this->assertNotEmpty($reloadedEntry->getContent());
}
2020-06-15 11:37:50 +00:00
$this->assertStringContainsString('Done', $tester->getDisplay());
2017-08-21 08:36:56 +00:00
}
/**
* @group NetworkCalls
*/
2017-08-21 08:36:56 +00:00
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');
2017-08-21 08:36:56 +00:00
$reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId());
$this->assertNotEmpty($reloadedAdminEntry->getContent());
$reloadedBobEntry = $entryRepository->find($this->bobEntry->getId());
$this->assertEmpty($reloadedBobEntry->getContent());
2020-06-15 11:37:50 +00:00
$this->assertStringContainsString('Done', $tester->getDisplay());
2017-08-21 08:36:56 +00:00
}
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,
]);
2020-06-15 11:37:50 +00:00
$this->assertStringContainsString('No entry to reload', $tester->getDisplay());
$this->assertStringNotContainsString('Done', $tester->getDisplay());
2017-08-21 08:36:56 +00:00
}
}