enable us to disable registration
tests / ci (push) Waiting to run

This commit is contained in:
Mark Gregory
2026-11-16 10:12:10 +00:00
parent ff2ef836c6
commit 523d4f087f
11 changed files with 150 additions and 6 deletions
+43
View File
@@ -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();
});