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
$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);
+ }
}