71 lines
2.4 KiB
PHP
Executable File
71 lines
2.4 KiB
PHP
Executable File
<?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 () {
|
|
$response = $this->get(route('register'));
|
|
|
|
$response->assertOk();
|
|
});
|
|
|
|
test('new users can register', function () {
|
|
$response = $this->post(route('register.store'), [
|
|
'name' => 'John Doe',
|
|
'email' => 'test@example.com',
|
|
'password' => 'password',
|
|
'password_confirmation' => 'password',
|
|
]);
|
|
|
|
$response->assertSessionHasNoErrors()
|
|
->assertRedirect(route('dashboard', absolute: false));
|
|
|
|
$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();
|
|
});
|