|
6 | 6 | use BookStack\Auth\Access\UserInviteService; |
7 | 7 | use BookStack\Auth\Role; |
8 | 8 | use BookStack\Auth\User; |
| 9 | +use BookStack\Uploads\Image; |
9 | 10 | use Illuminate\Support\Facades\Hash; |
10 | 11 | use Illuminate\Support\Str; |
11 | 12 | use Mockery\MockInterface; |
12 | 13 | use RuntimeException; |
13 | 14 | use Tests\TestCase; |
| 15 | +use Tests\Uploads\UsesImages; |
14 | 16 |
|
15 | 17 | class UserManagementTest extends TestCase |
16 | 18 | { |
| 19 | + use UsesImages; |
| 20 | + |
17 | 21 | public function test_user_creation() |
18 | 22 | { |
19 | 23 | /** @var User $user */ |
@@ -274,4 +278,33 @@ public function test_user_create_update_fails_if_locale_is_invalid() |
274 | 278 | $resp->assertSessionHasErrors(['language' => 'The language may not be greater than 15 characters.']); |
275 | 279 | $resp->assertSessionHasErrors(['language' => 'The language may only contain letters, numbers, dashes and underscores.']); |
276 | 280 | } |
| 281 | + |
| 282 | + public function test_user_avatar_update_and_reset() |
| 283 | + { |
| 284 | + $user = $this->users->viewer(); |
| 285 | + $avatarFile = $this->getTestImage('avatar-icon.png'); |
| 286 | + |
| 287 | + $this->assertEquals(0, $user->image_id); |
| 288 | + |
| 289 | + $upload = $this->asAdmin()->call('PUT', "/settings/users/{$user->id}", [ |
| 290 | + 'name' => 'Barry Scott', |
| 291 | + ], [], ['profile_image' => $avatarFile], []); |
| 292 | + $upload->assertRedirect('/settings/users'); |
| 293 | + |
| 294 | + $user->refresh(); |
| 295 | + $this->assertNotEquals(0, $user->image_id); |
| 296 | + /** @var Image $image */ |
| 297 | + $image = Image::query()->findOrFail($user->image_id); |
| 298 | + $this->assertFileExists(public_path($image->path)); |
| 299 | + |
| 300 | + $reset = $this->put("/settings/users/{$user->id}", [ |
| 301 | + 'name' => 'Barry Scott', |
| 302 | + 'profile_image_reset' => 'true', |
| 303 | + ]); |
| 304 | + $upload->assertRedirect('/settings/users'); |
| 305 | + |
| 306 | + $user->refresh(); |
| 307 | + $this->assertFileDoesNotExist(public_path($image->path)); |
| 308 | + $this->assertEquals(0, $user->image_id); |
| 309 | + } |
277 | 310 | } |
0 commit comments