mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-06 18:54:33 +08:00
Images: Added test to cover thubmnail regen endpoint
This commit is contained in:
@ -133,12 +133,21 @@ class FileProvider
|
|||||||
*/
|
*/
|
||||||
public function deleteAtRelativePath(string $path): void
|
public function deleteAtRelativePath(string $path): void
|
||||||
{
|
{
|
||||||
$fullPath = public_path($path);
|
$fullPath = $this->relativeToFullPath($path);
|
||||||
if (file_exists($fullPath)) {
|
if (file_exists($fullPath)) {
|
||||||
unlink($fullPath);
|
unlink($fullPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a relative path used by default in this provider to a full
|
||||||
|
* absolute local filesystem path.
|
||||||
|
*/
|
||||||
|
public function relativeToFullPath(string $path): string
|
||||||
|
{
|
||||||
|
return public_path($path);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete all uploaded files.
|
* Delete all uploaded files.
|
||||||
* To assist with cleanup.
|
* To assist with cleanup.
|
||||||
|
@ -552,6 +552,29 @@ class ImageTest extends TestCase
|
|||||||
$this->files->deleteAtRelativePath($relPath);
|
$this->files->deleteAtRelativePath($relPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_image_manager_regen_thumbnails()
|
||||||
|
{
|
||||||
|
$this->asEditor();
|
||||||
|
$imageName = 'first-image.png';
|
||||||
|
$relPath = $this->files->expectedImagePath('gallery', $imageName);
|
||||||
|
|
||||||
|
$this->files->uploadGalleryImage($this, $imageName, $this->entities->page()->id);
|
||||||
|
$image = Image::first();
|
||||||
|
|
||||||
|
$resp = $this->get("/images/edit/{$image->id}");
|
||||||
|
$this->withHtml($resp)->assertElementExists('button#image-manager-rebuild-thumbs');
|
||||||
|
|
||||||
|
$expectedThumbPath = dirname($relPath) . '/scaled-1680-/' . basename($relPath);
|
||||||
|
$this->files->deleteAtRelativePath($expectedThumbPath);
|
||||||
|
$this->assertFileDoesNotExist($this->files->relativeToFullPath($expectedThumbPath));
|
||||||
|
|
||||||
|
$resp = $this->put("/images/{$image->id}/rebuild-thumbnails");
|
||||||
|
$resp->assertOk();
|
||||||
|
|
||||||
|
$this->assertFileExists($this->files->relativeToFullPath($expectedThumbPath));
|
||||||
|
$this->files->deleteAtRelativePath($relPath);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getTestProfileImage()
|
protected function getTestProfileImage()
|
||||||
{
|
{
|
||||||
$imageName = 'profile.png';
|
$imageName = 'profile.png';
|
||||||
|
Reference in New Issue
Block a user