-<?php namespace Tests\Auth;
+<?php
+namespace Tests\Auth;
use BookStack\Auth\Access\UserInviteService;
use BookStack\Auth\User;
use BookStack\Notifications\UserInvite;
use Carbon\Carbon;
-use DB;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Str;
-use Notification;
use Tests\TestCase;
class UserInviteTest extends TestCase
{
-
public function test_user_creation_creates_invite()
{
Notification::fake();
$admin = $this->getAdmin();
- $this->actingAs($admin)->post('/settings/users/create', [
- 'name' => 'Barry',
+ $email = Str::random(16) . '@example.com';
+ $resp = $this->actingAs($admin)->post('/settings/users/create', [
+ 'name' => 'Barry',
+ 'email' => $email,
'send_invite' => 'true',
]);
+ $resp->assertRedirect('/settings/users');
- $newUser = User::query()->where('email', '=',
'[email protected]')->orderBy('id', 'desc')->first();
+ $newUser = User::query()->where('email', '=', $email)->orderBy('id', 'desc')->first();
Notification::assertSentTo($newUser, UserInvite::class);
$this->assertDatabaseHas('user_invites', [
- 'user_id' => $newUser->id
+ 'user_id' => $newUser->id,
]);
}
]);
$setPasswordResp->assertSee('Password set, you now have access to BookStack!');
$newPasswordValid = auth()->validate([
- 'email' => $user->email,
- 'password' => 'my test password'
+ 'email' => $user->email,
+ 'password' => 'my test password',
]);
$this->assertTrue($newPasswordValid);
$this->assertDatabaseMissing('user_invites', [
- 'user_id' => $user->id
+ 'user_id' => $user->id,
]);
}
$noPassword->assertSee('The password field is required.');
$this->assertDatabaseHas('user_invites', [
- 'user_id' => $user->id
+ 'user_id' => $user->id,
]);
}
$setPasswordPageResp->assertRedirect('/password/email');
$setPasswordPageResp->assertSessionHas('error', 'This invitation link has expired. You can instead try to reset your account password.');
}
-
-
-}
\ No newline at end of file
+}