@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Laravel\Fortify\Features;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->skipUnlessFortifyHas(Features::registration());
|
||||
config(['fortify.public_registration_default' => true]);
|
||||
});
|
||||
|
||||
test('registration screen can be rendered', function () {
|
||||
@@ -25,3 +27,44 @@ test('new users can register', function () {
|
||||
|
||||
$this->assertAuthenticated();
|
||||
});
|
||||
|
||||
test('administrators can disable and re-enable public registration from Users', function () {
|
||||
$admin = User::factory()->create(['helpdesk_admin' => true]);
|
||||
$settingsUrl = '/admin/users/public-registration';
|
||||
|
||||
$this->actingAs($admin)->get('/admin/users')
|
||||
->assertOk()
|
||||
->assertSee('Allow public registration');
|
||||
|
||||
$this->put($settingsUrl, ['enabled' => '0'])->assertRedirect('/admin/users');
|
||||
|
||||
auth()->logout();
|
||||
$this->get('/register')->assertNotFound();
|
||||
$this->postJson('/register', [
|
||||
'name' => 'New User',
|
||||
'email' => 'public@example.com',
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
])->assertNotFound();
|
||||
$this->assertDatabaseMissing('users', ['email' => 'public@example.com']);
|
||||
$this->get('/login')->assertOk()->assertDontSee('href="'.url('/register').'"', false);
|
||||
$this->view('stylist-theme-frontend::welcome')->assertDontSee('href="'.url('/register').'"', false);
|
||||
|
||||
config(['fortify.public_registration_default' => false]);
|
||||
$this->actingAs($admin)->put($settingsUrl, ['enabled' => '1'])->assertRedirect('/admin/users');
|
||||
|
||||
auth()->logout();
|
||||
$this->get('/register')->assertOk();
|
||||
$this->get('/login')->assertOk()->assertSee('href="'.url('/register').'"', false);
|
||||
});
|
||||
|
||||
test('only administrators can change public registration', function () {
|
||||
$settingsUrl = '/admin/users/public-registration';
|
||||
$this->put($settingsUrl, ['enabled' => '0'])->assertRedirect(route('login'));
|
||||
|
||||
$this->actingAs(User::factory()->create())
|
||||
->put($settingsUrl, ['enabled' => '0'])->assertForbidden();
|
||||
|
||||
auth()->logout();
|
||||
$this->get('/register')->assertOk();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user