mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-23 03:12:32 +01:00
Updated user avatar reset to clear relation id in database
Added test to cover. For #3977
This commit is contained in:
parent
811be3a36a
commit
03ad288aaa
@ -164,6 +164,8 @@ class UserController extends Controller
|
||||
// Delete the profile image if reset option is in request
|
||||
if ($request->has('profile_image_reset')) {
|
||||
$this->imageRepo->destroyImage($user->avatar);
|
||||
$user->image_id = 0;
|
||||
$user->save();
|
||||
}
|
||||
|
||||
$redirectUrl = userCan('users-manage') ? '/settings/users' : "/settings/users/{$user->id}";
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Tests\Settings;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
use Tests\Uploads\UsesImages;
|
||||
|
||||
|
@ -6,14 +6,18 @@ use BookStack\Actions\ActivityType;
|
||||
use BookStack\Auth\Access\UserInviteService;
|
||||
use BookStack\Auth\Role;
|
||||
use BookStack\Auth\User;
|
||||
use BookStack\Uploads\Image;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use Mockery\MockInterface;
|
||||
use RuntimeException;
|
||||
use Tests\TestCase;
|
||||
use Tests\Uploads\UsesImages;
|
||||
|
||||
class UserManagementTest extends TestCase
|
||||
{
|
||||
use UsesImages;
|
||||
|
||||
public function test_user_creation()
|
||||
{
|
||||
/** @var User $user */
|
||||
@ -274,4 +278,33 @@ class UserManagementTest extends TestCase
|
||||
$resp->assertSessionHasErrors(['language' => 'The language may not be greater than 15 characters.']);
|
||||
$resp->assertSessionHasErrors(['language' => 'The language may only contain letters, numbers, dashes and underscores.']);
|
||||
}
|
||||
|
||||
public function test_user_avatar_update_and_reset()
|
||||
{
|
||||
$user = $this->users->viewer();
|
||||
$avatarFile = $this->getTestImage('avatar-icon.png');
|
||||
|
||||
$this->assertEquals(0, $user->image_id);
|
||||
|
||||
$upload = $this->asAdmin()->call('PUT', "/settings/users/{$user->id}", [
|
||||
'name' => 'Barry Scott',
|
||||
], [], ['profile_image' => $avatarFile], []);
|
||||
$upload->assertRedirect('/settings/users');
|
||||
|
||||
$user->refresh();
|
||||
$this->assertNotEquals(0, $user->image_id);
|
||||
/** @var Image $image */
|
||||
$image = Image::query()->findOrFail($user->image_id);
|
||||
$this->assertFileExists(public_path($image->path));
|
||||
|
||||
$reset = $this->put("/settings/users/{$user->id}", [
|
||||
'name' => 'Barry Scott',
|
||||
'profile_image_reset' => 'true',
|
||||
]);
|
||||
$upload->assertRedirect('/settings/users');
|
||||
|
||||
$user->refresh();
|
||||
$this->assertFileDoesNotExist(public_path($image->path));
|
||||
$this->assertEquals(0, $user->image_id);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user