2023-06-21 13:51:03 +02:00
|
|
|
<?php
|
|
|
|
|
2024-02-19 01:30:12 +01:00
|
|
|
namespace Tests\Wallabag\Command;
|
2023-06-21 13:51:03 +02:00
|
|
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
|
|
|
use Symfony\Component\Console\Exception\RuntimeException;
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
2024-02-24 20:24:51 +01:00
|
|
|
use Tests\Wallabag\WallabagTestCase;
|
2024-02-19 01:30:12 +01:00
|
|
|
use Wallabag\Entity\Entry;
|
2023-06-21 13:51:03 +02:00
|
|
|
|
2024-02-24 20:24:51 +01:00
|
|
|
class UpdatePicturesPathCommandTest extends WallabagTestCase
|
2023-06-21 13:51:03 +02:00
|
|
|
{
|
|
|
|
public function testRunUpdatePicturesPathCommandWithoutOldURL()
|
|
|
|
{
|
|
|
|
$this->expectException(RuntimeException::class);
|
|
|
|
$this->expectExceptionMessage('Not enough arguments (missing: "old-url")');
|
|
|
|
$application = new Application($this->getTestClient()->getKernel());
|
|
|
|
|
|
|
|
$command = $application->find('wallabag:update-pictures-path');
|
|
|
|
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
$tester->execute([]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunGenerateUrlHashesCommandForUser()
|
|
|
|
{
|
|
|
|
$application = new Application($this->getTestClient()->getKernel());
|
|
|
|
$this->logInAs('admin');
|
|
|
|
|
|
|
|
$url = 'https://wallabag.org/news/20230620-new-release-wallabag-260/';
|
|
|
|
|
|
|
|
$command = $application->find('wallabag:update-pictures-path');
|
|
|
|
|
|
|
|
$client = $this->getTestClient();
|
|
|
|
$em = $client->getContainer()->get(EntityManagerInterface::class);
|
|
|
|
$entry = new Entry($this->getLoggedInUser());
|
|
|
|
$entry->setUrl($url);
|
|
|
|
$entry->setPreviewPicture('https://old-url.test/mypicture.jpg');
|
|
|
|
$entry->setContent('my great article with a picture <img src="https://old-url.test/mypicture.jpg" />');
|
|
|
|
$em->persist($entry);
|
|
|
|
$em->flush();
|
|
|
|
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
$tester->execute([
|
|
|
|
'old-url' => 'https://old-url.test',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertStringContainsString('Finished updating.', $tester->getDisplay());
|
|
|
|
|
|
|
|
$entry = $em->getRepository(Entry::class)->findOneByUrl($url);
|
|
|
|
$this->assertSame($entry->getPreviewPicture(), $client->getContainer()->getParameter('domain_name') . '/mypicture.jpg');
|
|
|
|
|
2024-02-19 01:30:12 +01:00
|
|
|
$query = $em->createQuery('DELETE FROM Wallabag\Entity\Entry e WHERE e.url = :url');
|
2023-06-21 13:51:03 +02:00
|
|
|
$query->setParameter('url', $url);
|
|
|
|
$query->execute();
|
|
|
|
}
|
|
|
|
}
|