feat: Implement cleanup methods for nonassigned article files and images in ArticleRepository
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user