2017-08-21 08:36:56 +00:00
|
|
|
<?php
|
|
|
|
|
2024-02-19 00:30:12 +00:00
|
|
|
namespace Tests\Wallabag\Command;
|
2017-08-21 08:36:56 +00:00
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
2024-02-24 19:24:51 +00:00
|
|
|
use Tests\Wallabag\WallabagTestCase;
|
2024-02-19 00:30:12 +00:00
|
|
|
use Wallabag\Entity\Entry;
|
2024-02-24 01:34:03 +00:00
|
|
|
use Wallabag\Repository\EntryRepository;
|
|
|
|
use Wallabag\Repository\UserRepository;
|
2017-08-21 08:36:56 +00:00
|
|
|
|
2024-02-24 19:24:51 +00:00
|
|
|
class ReloadEntryCommandTest extends WallabagTestCase
|
2017-08-21 08:36:56 +00:00
|
|
|
{
|
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
|
|
|
|
|
|
|
/**
|
2024-01-01 18:11:01 +00:00
|
|
|
* @var Entry
|
2017-08-21 08:36:56 +00:00
|
|
|
*/
|
|
|
|
public $adminEntry;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Entry
|
|
|
|
*/
|
|
|
|
public $bobEntry;
|
|
|
|
|
2023-07-28 12:58:43 +00:00
|
|
|
/**
|
|
|
|
* @var Entry
|
|
|
|
*/
|
|
|
|
public $bobParsedEntry;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Entry
|
|
|
|
*/
|
|
|
|
public $bobNotParsedEntry;
|
|
|
|
|
2020-12-08 08:17:10 +00:00
|
|
|
protected function setUp(): void
|
2017-08-21 08:36:56 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2024-02-24 01:34:03 +00:00
|
|
|
$userRepository = static::getContainer()->get(UserRepository::class);
|
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);
|
|
|
|
|
2023-07-28 12:58:43 +00:00
|
|
|
$this->bobParsedEntry = new Entry($user);
|
|
|
|
$this->bobParsedEntry->setUrl($this->url);
|
|
|
|
$this->bobParsedEntry->setTitle('title foo');
|
|
|
|
$this->bobParsedEntry->setContent('');
|
|
|
|
$this->getEntityManager()->persist($this->bobParsedEntry);
|
|
|
|
|
|
|
|
$this->bobNotParsedEntry = new Entry($user);
|
|
|
|
$this->bobNotParsedEntry->setUrl($this->url);
|
|
|
|
$this->bobNotParsedEntry->setTitle('title foo');
|
|
|
|
$this->bobNotParsedEntry->setContent('');
|
|
|
|
$this->bobNotParsedEntry->setNotParsed(true);
|
|
|
|
$this->getEntityManager()->persist($this->bobNotParsedEntry);
|
|
|
|
|
2017-08-21 08:36:56 +00:00
|
|
|
$this->getEntityManager()->flush();
|
|
|
|
}
|
|
|
|
|
2020-03-10 21:22:51 +00:00
|
|
|
/**
|
|
|
|
* @group NetworkCalls
|
|
|
|
*/
|
2017-08-21 08:36:56 +00:00
|
|
|
public function testRunReloadEntryCommand()
|
|
|
|
{
|
2022-11-23 16:09:32 +00:00
|
|
|
$application = new Application($this->getTestClient()->getKernel());
|
2017-08-21 08:36:56 +00:00
|
|
|
|
|
|
|
$command = $application->find('wallabag:entry:reload');
|
|
|
|
$tester = new CommandTester($command);
|
2022-09-03 00:28:07 +00:00
|
|
|
$tester->execute([], [
|
2017-08-21 08:36:56 +00:00
|
|
|
'interactive' => false,
|
|
|
|
]);
|
|
|
|
|
2024-02-24 01:34:03 +00:00
|
|
|
$reloadedEntries = static::getContainer()
|
|
|
|
->get(EntryRepository::class)
|
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
|
|
|
}
|
|
|
|
|
2020-03-10 21:22:51 +00:00
|
|
|
/**
|
|
|
|
* @group NetworkCalls
|
|
|
|
*/
|
2017-08-21 08:36:56 +00:00
|
|
|
public function testRunReloadEntryWithUsernameCommand()
|
|
|
|
{
|
2022-11-23 16:09:32 +00:00
|
|
|
$application = new Application($this->getTestClient()->getKernel());
|
2017-08-21 08:36:56 +00:00
|
|
|
|
|
|
|
$command = $application->find('wallabag:entry:reload');
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
$tester->execute([
|
|
|
|
'username' => 'admin',
|
|
|
|
], [
|
|
|
|
'interactive' => false,
|
|
|
|
]);
|
|
|
|
|
2024-02-24 01:34:03 +00:00
|
|
|
$entryRepository = static::getContainer()->get(EntryRepository::class);
|
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
|
|
|
}
|
|
|
|
|
2023-07-28 12:58:43 +00:00
|
|
|
public function testRunReloadEntryWithNotParsedOption()
|
|
|
|
{
|
|
|
|
$application = new Application($this->getTestClient()->getKernel());
|
|
|
|
|
|
|
|
$command = $application->find('wallabag:entry:reload');
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
$tester->execute([
|
|
|
|
'--only-not-parsed' => true,
|
|
|
|
]);
|
|
|
|
|
2024-02-24 01:34:03 +00:00
|
|
|
$entryRepository = static::getContainer()->get(EntryRepository::class);
|
2023-07-28 12:58:43 +00:00
|
|
|
|
|
|
|
$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());
|
|
|
|
}
|
|
|
|
|
2017-08-21 08:36:56 +00:00
|
|
|
public function testRunReloadEntryWithoutEntryCommand()
|
|
|
|
{
|
2022-11-23 16:09:32 +00:00
|
|
|
$application = new Application($this->getTestClient()->getKernel());
|
2017-08-21 08:36:56 +00:00
|
|
|
|
|
|
|
$command = $application->find('wallabag:entry:reload');
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
$tester->execute([
|
|
|
|
'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
|
|
|
}
|
|
|
|
}
|