feat: Implement cleanup methods for nonassigned article files and images in ArticleRepository

This commit is contained in:
2026-02-06 08:57:22 +01:00
parent e33978e1bb
commit 6c21b835da
12 changed files with 110 additions and 35 deletions

View File

@@ -57,4 +57,46 @@ class ArticleRepositoryTest extends TestCase
$this->assertNull($article);
}
public function testDeleteNonassignedFilesDeletesDbRows(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('select')
->with('pp_articles_files', '*', ['article_id' => null])
->willReturn([
['id' => 1, 'src' => '/this/path/does/not/exist-file.tmp']
]);
$mockDb->expects($this->once())
->method('delete')
->with('pp_articles_files', ['article_id' => null]);
$repository = new ArticleRepository($mockDb);
$repository->deleteNonassignedFiles();
$this->assertTrue(true);
}
public function testDeleteNonassignedImagesDeletesDbRows(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('select')
->with('pp_articles_images', '*', ['article_id' => null])
->willReturn([
['id' => 1, 'src' => '/this/path/does/not/exist-image.tmp']
]);
$mockDb->expects($this->once())
->method('delete')
->with('pp_articles_images', ['article_id' => null]);
$repository = new ArticleRepository($mockDb);
$repository->deleteNonassignedImages();
$this->assertTrue(true);
}
}