Skip to content

NOW MANAGED ON CODEBERG

Added test case for avatar failed fetch

Dan Browne5a96b0cb078
diff --git a/app/Uploads/UserAvatars.php b/app/Uploads/UserAvatars.php
index 92b06bc8a..b3b9d5951 100644
--- a/app/Uploads/UserAvatars.php
+++ b/app/Uploads/UserAvatars.php
@@ -3,6 +3,7 @@
use BookStack\Auth\User;
use BookStack\Exceptions\HttpFetchException;
use Exception;
+use Illuminate\Support\Facades\Log;
class UserAvatars
{
diff --git a/tests/Uploads/AvatarTest.php b/tests/Uploads/AvatarTest.php
index ecf7037a9..efaa016dd 100644
--- a/tests/Uploads/AvatarTest.php
+++ b/tests/Uploads/AvatarTest.php
@@ -1,7 +1,9 @@
<?php namespace Tests\Uploads;
use BookStack\Auth\User;
+use BookStack\Exceptions\HttpFetchException;
use BookStack\Uploads\HttpFetcher;
+use Illuminate\Support\Facades\Log;
use Tests\TestCase;
class AvatarTest extends TestCase
@@ -11,7 +13,7 @@ class AvatarTest extends TestCase
protected function createUserRequest($user)
{
- $resp = $this->asAdmin()->post('/settings/users/create', [
+ $this->asAdmin()->post('/settings/users/create', [
'name' => $user->name,
'email' => $user->email,
'password' => 'testing',
@@ -22,8 +24,7 @@ class AvatarTest extends TestCase
protected function assertImageFetchFrom(string $url)
{
- $http = \Mockery::mock(HttpFetcher::class);
- $this->app->instance(HttpFetcher::class, $http);
+ $http = $this->mock(HttpFetcher::class);
$http->shouldReceive('fetch')
->once()->with($url)
@@ -55,6 +56,7 @@ class AvatarTest extends TestCase
public function test_custom_url_used_if_set()
{
config()->set([
+ 'services.disable_services' => false,
'services.avatar_url' => 'https://example.com/${email}/${hash}/${size}',
]);
@@ -74,11 +76,26 @@ class AvatarTest extends TestCase
$user = factory(User::class)->make();
- $http = \Mockery::mock(HttpFetcher::class);
- $this->app->instance(HttpFetcher::class, $http);
+ $http = $this->mock(HttpFetcher::class);
$http->shouldNotReceive('fetch');
$this->createUserRequest($user);
}
+ public function test_no_failure_but_error_logged_on_failed_avatar_fetch()
+ {
+ config()->set([
+ 'services.disable_services' => false,
+ ]);
+
+ $http = $this->mock(HttpFetcher::class);
+ $http->shouldReceive('fetch')->andThrow(new HttpFetchException());
+
+ $logger = $this->withTestLogger();
+
+ $user = factory(User::class)->make();
+ $this->createUserRequest($user);
+ $this->assertTrue($logger->hasError('Failed to save user avatar image'));
+ }
+
}