1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-09-15 18:57:05 +00:00

handle expiration time using a parameter

This commit is contained in:
Martin Chaine 2025-06-03 17:20:22 +02:00
parent 5c823c91a3
commit e08c10af5d
No known key found for this signature in database
GPG key ID: 2D04DFDC89D53FDE
5 changed files with 76 additions and 38 deletions

View file

@ -2,10 +2,13 @@
namespace Tests\Wallabag\Command;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Tests\Wallabag\WallabagTestCase;
use Wallabag\Entity\EntryDeletion;
use Wallabag\Helper\EntryDeletionExpirationConfig;
use Wallabag\Repository\EntryDeletionRepository;
/**
* Test the purge entry deletions command.
@ -15,59 +18,67 @@ use Wallabag\Entity\EntryDeletion;
* - Admin user: 1 deletion from 1 day ago (entry_id: 1001)
* - Bob user: 1 deletion from 3 days ago (entry_id: 1003)
*/
class PurgeEntryDeletionsCommandTest extends WallabagTestCase
class PurgeEntryDeletionsCommandTest extends KernelTestCase
{
private EntryDeletionExpirationConfig $expirationConfig;
private EntryDeletionRepository $entryDeletionRepository;
protected function setUp(): void
{
self::bootKernel();
$this->expirationConfig = self::getContainer()->get(EntryDeletionExpirationConfig::class);
$this->expirationConfig->setExpirationDays(2);
$em = self::getContainer()->get(EntityManagerInterface::class);
$this->entryDeletionRepository = $em->getRepository(EntryDeletion::class);
}
public function testRunPurgeEntryDeletionsCommandWithDryRun()
{
$application = new Application($this->getTestClient()->getKernel());
$application = new Application(self::$kernel);
$command = $application->find('wallabag:purge-entry-deletions');
$dateStr = '-2 days';
$tester = new CommandTester($command);
$tester->execute([
'--older-than' => $dateStr,
'--dry-run' => true,
]);
$this->assertStringContainsString('Dry run mode enabled', $tester->getDisplay());
$this->assertSame(0, $tester->getStatusCode());
$em = $this->getEntityManager();
$count = $em->getRepository(EntryDeletion::class)->countAllBefore(new \DateTime($dateStr));
$count = $this->entryDeletionRepository->countAllBefore($this->expirationConfig->getCutoffDate());
$this->assertSame(2, $count);
}
public function testRunPurgeEntryDeletionsCommand()
{
$application = new Application($this->getTestClient()->getKernel());
$application = new Application(self::$kernel);
$command = $application->find('wallabag:purge-entry-deletions');
$dateStr = '-2 days';
$tester = new CommandTester($command);
$tester->setInputs(['yes']); // confirm deletion
$tester->execute(['--older-than' => $dateStr]);
$tester->execute([]);
$this->assertStringContainsString('Successfully deleted 2 records', $tester->getDisplay());
$this->assertSame(0, $tester->getStatusCode());
$em = $this->getEntityManager();
$count = $em->getRepository(EntryDeletion::class)->countAllBefore(new \DateTime($dateStr));
$count = $this->entryDeletionRepository->countAllBefore($this->expirationConfig->getCutoffDate());
$this->assertSame(0, $count);
$count = $em->getRepository(EntryDeletion::class)->countAllBefore(new \DateTime('now'));
$this->assertSame(1, $count);
$countAll = $this->entryDeletionRepository->countAllBefore(new \DateTime('now'));
$this->assertSame(1, $countAll);
}
public function testRunPurgeEntryDeletionsCommandWithNoRecords()
{
$application = new Application($this->getTestClient()->getKernel());
$this->expirationConfig->setExpirationDays(10);
$application = new Application(self::$kernel);
$command = $application->find('wallabag:purge-entry-deletions');
$tester = new CommandTester($command);
$tester->execute([
'--older-than' => '-1 year',
]);
$tester->execute([]);
$this->assertStringContainsString('No entry deletion records found', $tester->getDisplay());
$this->assertSame(0, $tester->getStatusCode());