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, ]; }