X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/88d09a2a3b76a2d914d523dc03fcf695849ba1b7..refs/pull/691/head:/tests/ImageTest.php diff --git a/tests/ImageTest.php b/tests/ImageTest.php index 822cc969b..881f73b55 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -5,7 +5,6 @@ use BookStack\Page; class ImageTest extends TestCase { - /** * Get the path to our basic test image. * @return string @@ -54,20 +53,25 @@ class ImageTest extends TestCase */ protected function deleteImage($relPath) { - unlink(public_path($relPath)); + $path = public_path($relPath); + if (file_exists($path)) { + unlink($path); + } } public function test_image_upload() { $page = Page::first(); - $this->asAdmin(); $admin = $this->getAdmin(); + $this->actingAs($admin); + $imageName = 'first-image.png'; + $relPath = $this->getTestImagePath('gallery', $imageName); + $this->deleteImage($relPath); $upload = $this->uploadImage($imageName, $page->id); $upload->assertStatus(200); - $relPath = $this->getTestImagePath('gallery', $imageName); $this->assertTrue(file_exists(public_path($relPath)), 'Uploaded image not found at path: '. public_path($relPath)); @@ -180,4 +184,28 @@ class ImageTest extends TestCase $this->assertTrue($testImageData === $uploadedImageData, "Uploaded image file data does not match our test image as expected"); } + public function test_user_images_deleted_on_user_deletion() + { + $editor = $this->getEditor(); + $this->actingAs($editor); + + $imageName = 'profile.png'; + $relPath = $this->getTestImagePath('gallery', $imageName); + $this->deleteImage($relPath); + + $file = $this->getTestImage($imageName); + $this->call('POST', '/images/user/upload', [], [], ['file' => $file], []); + $this->call('POST', '/images/user/upload', [], [], ['file' => $file], []); + + $profileImages = Image::where('type', '=', 'user')->where('created_by', '=', $editor->id)->get(); + $this->assertTrue($profileImages->count() === 2, "Found profile images does not match upload count"); + + $userDelete = $this->asAdmin()->delete("/settings/users/{$editor->id}"); + $userDelete->assertStatus(302); + $this->assertDatabaseMissing('images', [ + 'type' => 'user', + 'created_by' => $editor->id + ]); + } + } \ No newline at end of file