X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/ee24635e06a8c01d751f80caba47c57f76e8989d..refs/pull/4467/head:/tests/Uploads/AvatarTest.php diff --git a/tests/Uploads/AvatarTest.php b/tests/Uploads/AvatarTest.php index eeaae09dc..363c1fa95 100644 --- a/tests/Uploads/AvatarTest.php +++ b/tests/Uploads/AvatarTest.php @@ -2,15 +2,14 @@ namespace Tests\Uploads; -use BookStack\Auth\User; use BookStack\Exceptions\HttpFetchException; use BookStack\Uploads\HttpFetcher; +use BookStack\Uploads\UserAvatars; +use BookStack\Users\Models\User; use Tests\TestCase; class AvatarTest extends TestCase { - use UsesImages; - protected function createUserRequest($user): User { $this->asAdmin()->post('/settings/users/create', [ @@ -29,12 +28,12 @@ class AvatarTest extends TestCase $http->shouldReceive('fetch') ->once()->with($url) - ->andReturn($this->getTestImageContent()); + ->andReturn($this->files->pngImageData()); } protected function deleteUserImage(User $user) { - $this->deleteImage($user->avatar->path); + $this->files->deleteAtRelativePath($user->avatar->path); } public function test_gravatar_fetched_on_user_create() @@ -112,4 +111,28 @@ class AvatarTest extends TestCase $this->createUserRequest($user); $this->assertTrue($logger->hasError('Failed to save user avatar image')); } + + public function test_exception_message_on_failed_fetch() + { + // set wrong url + config()->set([ + 'services.disable_services' => false, + 'services.avatar_url' => 'http_malformed_url/${email}/${hash}/${size}', + ]); + + $user = User::factory()->make(); + $avatar = app()->make(UserAvatars::class); + $url = 'http_malformed_url/' . urlencode(strtolower($user->email)) . '/' . md5(strtolower($user->email)) . '/500'; + $logger = $this->withTestLogger(); + + $avatar->fetchAndAssignToUser($user); + + $this->assertTrue($logger->hasError('Failed to save user avatar image')); + $exception = $logger->getRecords()[0]['context']['exception']; + $this->assertEquals(new HttpFetchException( + 'Cannot get image from ' . $url, + 6, + (new HttpFetchException('Could not resolve host: http_malformed_url', 6)) + ), $exception); + } }