mirror of
https://github.com/wallabag/wallabag.git
synced 2026-11-05 20:13:53 +01:00
154 lines
4.8 KiB
PHP
154 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace Wallabag\Tests\Integration\Command;
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
use Wallabag\Entity\Entry;
|
|
use Wallabag\Repository\EntryRepository;
|
|
use Wallabag\Tests\Integration\WallabagKernelTestCase;
|
|
|
|
class ReloadEntryCommandTest extends WallabagKernelTestCase
|
|
{
|
|
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;
|
|
|
|
/**
|
|
* @var Entry
|
|
*/
|
|
public $bobParsedEntry;
|
|
|
|
/**
|
|
* @var Entry
|
|
*/
|
|
public $bobNotParsedEntry;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->adminEntry = new Entry($this->getUser('admin'));
|
|
$this->adminEntry->setUrl($this->url);
|
|
$this->adminEntry->setTitle('title foo');
|
|
$this->adminEntry->setContent('');
|
|
$this->getEntityManager()->persist($this->adminEntry);
|
|
|
|
$bob = $this->getUser('bob');
|
|
$this->bobEntry = new Entry($bob);
|
|
$this->bobEntry->setUrl($this->url);
|
|
$this->bobEntry->setTitle('title foo');
|
|
$this->bobEntry->setContent('');
|
|
$this->getEntityManager()->persist($this->bobEntry);
|
|
|
|
$this->bobParsedEntry = new Entry($bob);
|
|
$this->bobParsedEntry->setUrl($this->url);
|
|
$this->bobParsedEntry->setTitle('title foo');
|
|
$this->bobParsedEntry->setContent('');
|
|
$this->getEntityManager()->persist($this->bobParsedEntry);
|
|
|
|
$this->bobNotParsedEntry = new Entry($bob);
|
|
$this->bobNotParsedEntry->setUrl($this->url);
|
|
$this->bobNotParsedEntry->setTitle('title foo');
|
|
$this->bobNotParsedEntry->setContent('');
|
|
$this->bobNotParsedEntry->setNotParsed(true);
|
|
$this->getEntityManager()->persist($this->bobNotParsedEntry);
|
|
|
|
$this->getEntityManager()->flush();
|
|
}
|
|
|
|
/**
|
|
* @group NetworkCalls
|
|
*/
|
|
public function testRunReloadEntryCommand()
|
|
{
|
|
$application = $this->createApplication();
|
|
|
|
$command = $application->find('wallabag:entry:reload');
|
|
$tester = new CommandTester($command);
|
|
$tester->execute([], [
|
|
'interactive' => false,
|
|
]);
|
|
|
|
$reloadedEntries = static::getContainer()
|
|
->get(EntryRepository::class)
|
|
->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]);
|
|
|
|
foreach ($reloadedEntries as $reloadedEntry) {
|
|
$this->assertNotEmpty($reloadedEntry->getContent());
|
|
}
|
|
|
|
$this->assertStringContainsString('Done', $tester->getDisplay());
|
|
}
|
|
|
|
/**
|
|
* @group NetworkCalls
|
|
*/
|
|
public function testRunReloadEntryWithUsernameCommand()
|
|
{
|
|
$application = $this->createApplication();
|
|
|
|
$command = $application->find('wallabag:entry:reload');
|
|
$tester = new CommandTester($command);
|
|
$tester->execute([
|
|
'username' => 'admin',
|
|
], [
|
|
'interactive' => false,
|
|
]);
|
|
|
|
$entryRepository = static::getContainer()->get(EntryRepository::class);
|
|
|
|
$reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId());
|
|
$this->assertNotEmpty($reloadedAdminEntry->getContent());
|
|
|
|
$reloadedBobEntry = $entryRepository->find($this->bobEntry->getId());
|
|
$this->assertEmpty($reloadedBobEntry->getContent());
|
|
|
|
$this->assertStringContainsString('Done', $tester->getDisplay());
|
|
}
|
|
|
|
public function testRunReloadEntryWithNotParsedOption()
|
|
{
|
|
$application = $this->createApplication();
|
|
|
|
$command = $application->find('wallabag:entry:reload');
|
|
$tester = new CommandTester($command);
|
|
$tester->execute([
|
|
'--only-not-parsed' => true,
|
|
]);
|
|
|
|
$entryRepository = static::getContainer()->get(EntryRepository::class);
|
|
|
|
$reloadedBobParsedEntry = $entryRepository->find($this->bobParsedEntry->getId());
|
|
$this->assertEmpty($reloadedBobParsedEntry->getContent());
|
|
|
|
$reloadedBobNotParsedEntry = $entryRepository->find($this->bobNotParsedEntry->getId());
|
|
$this->assertNotEmpty($reloadedBobNotParsedEntry->getContent());
|
|
|
|
$this->assertStringContainsString('Done', $tester->getDisplay());
|
|
}
|
|
|
|
public function testRunReloadEntryWithoutEntryCommand()
|
|
{
|
|
$application = $this->createApplication();
|
|
|
|
$command = $application->find('wallabag:entry:reload');
|
|
$tester = new CommandTester($command);
|
|
$tester->execute([
|
|
'username' => 'empty',
|
|
], [
|
|
'interactive' => false,
|
|
]);
|
|
|
|
$this->assertStringContainsString('No entry to reload', $tester->getDisplay());
|
|
$this->assertStringNotContainsString('Done', $tester->getDisplay());
|
|
}
|
|
}
|