Files
ppeasy_vg12/tests/Feature/Web/SettingsTest.php
T
2026-10-09 08:21:06 +02:00

110 lines
3.3 KiB
PHP

<?php
use Facades\Tests\Setup\RoleFactory;
use Facades\Tests\Setup\UserFactory;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->artisan('db:seed');
});
test('update general settings', function () {
Setting::set('app_name', 'bar');
$this->assertEquals('bar', Setting::get('app_name'));
$this->actingAsAdmin()
->from('/settings/general')
->post('/settings/general', ['app_name' => 'foo'])
->assertRedirect('/settings/general');
$this->assertEquals('foo', Setting::get('app_name'));
});
test('only users with appropriate permission can update general settings', function () {
Setting::set('app_name', 'bar');
$roleA = RoleFactory::create();
$roleB = RoleFactory::withPermissions('settings.general')->create();
$userA = UserFactory::role($roleA)->create();
$userB = UserFactory::role($roleB)->create();
$this->actingAs($userA)
->from('/settings/general')
->post('/settings/general', ['app_name' => 'foo'])
->assertStatus(403);
$this->assertEquals('bar', Setting::get('app_name'));
$this->actingAs($userB)
->from('/settings/general')
->post('/settings/general', ['app_name' => 'foo'])
->assertRedirect('/settings/general');
$this->assertEquals('foo', Setting::get('app_name'));
});
test('update auth settings', function () {
Setting::set('app_name', 'bar');
$data = settingsPageAuthData();
$this->actingAsAdmin()
->from('/settings/auth')
->post('/settings/auth', $data)
->assertRedirect('/settings/auth');
assertSettingsPageAuthUpdated($data);
});
test('only users with appropriate permission can update auth settings', function () {
Setting::set('app_name', 'foo');
$roleA = RoleFactory::create();
$roleB = RoleFactory::withPermissions('settings.auth')->create();
$userA = UserFactory::role($roleA)->create();
$userB = UserFactory::role($roleB)->create();
$data = ['app_name' => 'bar'];
$this->actingAs($userA)
->from('/settings/auth')
->post('/settings/auth', $data)
->assertStatus(403);
$this->assertEquals('foo', Setting::get('app_name'));
$this->actingAs($userB)
->from('/settings/auth')
->post('/settings/auth', $data)
->assertRedirect('/settings/auth');
$this->assertEquals('bar', Setting::get('app_name'));
});
function assertSettingsPageAuthUpdated(array $data)
{
test()->assertEquals($data['remember_me'], Setting::get('remember_me'));
test()->assertEquals($data['forgot_password'], Setting::get('forgot_password'));
test()->assertEquals($data['login_reset_token_lifetime'], Setting::get('login_reset_token_lifetime'));
test()->assertEquals($data['throttle_enabled'], Setting::get('throttle_enabled'));
test()->assertEquals($data['throttle_attempts'], Setting::get('throttle_attempts'));
test()->assertEquals($data['throttle_lockout_time'], Setting::get('throttle_lockout_time'));
}
function settingsPageAuthData(): array
{
return [
'remember_me' => 1,
'forgot_password' => 1,
'login_reset_token_lifetime' => 123,
'throttle_enabled' => 1,
'throttle_attempts' => 10,
'throttle_lockout_time' => 2,
];
}