X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/a3ead5062acc169ae3486d90ac2befe3db86bfe6..refs/pull/3365/head:/tests/User/UserManagementTest.php diff --git a/tests/User/UserManagementTest.php b/tests/User/UserManagementTest.php index 94970df4f..5870b6827 100644 --- a/tests/User/UserManagementTest.php +++ b/tests/User/UserManagementTest.php @@ -3,11 +3,14 @@ namespace Tests\User; use BookStack\Actions\ActivityType; +use BookStack\Auth\Access\UserInviteService; use BookStack\Auth\Role; use BookStack\Auth\User; use BookStack\Entities\Models\Page; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; +use Mockery\MockInterface; +use RuntimeException; use Tests\TestCase; class UserManagementTest extends TestCase @@ -179,4 +182,56 @@ class UserManagementTest extends TestCase $resp = $this->followRedirects($resp); $resp->assertSee('cannot delete the guest user'); } + + public function test_user_create_language_reflects_default_system_locale() + { + $langs = ['en', 'fr', 'hr']; + foreach ($langs as $lang) { + config()->set('app.locale', $lang); + $resp = $this->asAdmin()->get('/settings/users/create'); + $resp->assertElementExists('select[name="language"] option[value="' . $lang . '"][selected]'); + } + } + + public function test_user_creation_is_not_performed_if_the_invitation_sending_fails() + { + /** @var User $user */ + $user = User::factory()->make(); + $adminRole = Role::getRole('admin'); + + // Simulate an invitation sending failure + $this->mock(UserInviteService::class, function (MockInterface $mock) { + $mock->shouldReceive('sendInvitation')->once()->andThrow(RuntimeException::class); + }); + + $this->asAdmin()->post('/settings/users/create', [ + 'name' => $user->name, + 'email' => $user->email, + 'send_invite' => 'true', + 'roles[' . $adminRole->id . ']' => 'true', + ]); + + // Since the invitation failed, the user should not exist in the database + $this->assertDatabaseMissing('users', $user->only('name', 'email')); + } + + public function test_user_create_activity_is_not_persisted_if_the_invitation_sending_fails() + { + /** @var User $user */ + $user = User::factory()->make(); + $adminRole = Role::getRole('admin'); + + $this->mock(UserInviteService::class, function (MockInterface $mock) { + $mock->shouldReceive('sendInvitation')->once()->andThrow(RuntimeException::class); + }); + + $this->asAdmin()->post('/settings/users/create', [ + 'name' => $user->name, + 'email' => $user->email, + 'send_invite' => 'true', + 'roles[' . $adminRole->id . ']' => 'true', + ]); + + $this->assertDatabaseMissing('activities', ['type' => 'USER_CREATE']); + } }