mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-30 04:23:11 +03:00
Fixed issue where more images than expected could be deleted
When deleting images, images within the same directory, that have a suffix of the delete image name, would also be deleted. Added test to cover.
This commit is contained in:
@ -262,10 +262,11 @@ class ImageTest extends TestCase
|
||||
$page = Page::first();
|
||||
$this->asAdmin();
|
||||
$imageName = 'first-image.png';
|
||||
$relPath = $this->getTestImagePath('gallery', $imageName);
|
||||
$this->deleteImage($relPath);
|
||||
|
||||
$this->uploadImage($imageName, $page->id);
|
||||
$image = Image::first();
|
||||
$relPath = $this->getTestImagePath('gallery', $imageName);
|
||||
|
||||
$delete = $this->delete( '/images/' . $image->id);
|
||||
$delete->assertStatus(200);
|
||||
@ -278,6 +279,31 @@ class ImageTest extends TestCase
|
||||
$this->assertFalse(file_exists(public_path($relPath)), 'Uploaded image has not been deleted as expected');
|
||||
}
|
||||
|
||||
public function test_image_delete_does_not_delete_similar_images()
|
||||
{
|
||||
$page = Page::first();
|
||||
$this->asAdmin();
|
||||
$imageName = 'first-image.png';
|
||||
|
||||
$relPath = $this->getTestImagePath('gallery', $imageName);
|
||||
$this->deleteImage($relPath);
|
||||
|
||||
$this->uploadImage($imageName, $page->id);
|
||||
$this->uploadImage($imageName, $page->id);
|
||||
$this->uploadImage($imageName, $page->id);
|
||||
|
||||
$image = Image::first();
|
||||
$folder = public_path(dirname($relPath));
|
||||
$imageCount = count(glob($folder . '/*'));
|
||||
|
||||
$delete = $this->delete( '/images/' . $image->id);
|
||||
$delete->assertStatus(200);
|
||||
|
||||
$newCount = count(glob($folder . '/*'));
|
||||
$this->assertEquals($imageCount - 1, $newCount, 'More files than expected have been deleted');
|
||||
$this->assertFalse(file_exists(public_path($relPath)), 'Uploaded image has not been deleted as expected');
|
||||
}
|
||||
|
||||
protected function getTestProfileImage()
|
||||
{
|
||||
$imageName = 'profile.png';
|
||||
|
Reference in New Issue
Block a user