87 lines
2.8 KiB
PHP
87 lines
2.8 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('auth settings page can be rendered', function () {
|
|
$this->actingAsAdmin()
|
|
->get('/settings/auth')
|
|
->assertOk();
|
|
});
|
|
|
|
test('update auth settings', function () {
|
|
Setting::set('app_name', 'bar');
|
|
|
|
$data = authSettingsData();
|
|
|
|
$this->actingAsAdmin()
|
|
->from('/settings/auth')
|
|
->post('/settings/auth', $data)
|
|
->assertRedirect('/settings/auth');
|
|
|
|
assertAuthSettingsWereUpdated($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 = authSettingsData();
|
|
|
|
$data['app_name'] = 'bar';
|
|
|
|
$this->actingAs($userA)
|
|
->from('/settings/auth')
|
|
->post('/settings/auth', $data)
|
|
->assertStatus(403);
|
|
|
|
$this->assertNotEquals('bar', (string) Setting::get('app_name'));
|
|
|
|
$this->actingAs($userB)
|
|
->from('/settings/auth')
|
|
->post('/settings/auth', $data)
|
|
->assertRedirect('/settings/auth');
|
|
|
|
$this->assertEquals('bar', (string) Setting::get('app_name'));
|
|
});
|
|
|
|
function assertAuthSettingsWereUpdated(array $data)
|
|
{
|
|
test()->assertEquals((string) $data['remember_me'], (string) Setting::get('remember_me'));
|
|
test()->assertEquals((string) $data['forgot_password'], (string) Setting::get('forgot_password'));
|
|
test()->assertEquals((string) $data['login_reset_token_lifetime'], (string) Setting::get('login_reset_token_lifetime'));
|
|
test()->assertEquals((string) $data['throttle_enabled'], (string) Setting::get('throttle_enabled'));
|
|
test()->assertEquals((string) $data['throttle_attempts'], (string) Setting::get('throttle_attempts'));
|
|
test()->assertEquals((string) $data['throttle_lockout_time'], (string) Setting::get('throttle_lockout_time'));
|
|
test()->assertEquals((string) $data['reg_enabled'], (string) Setting::get('reg_enabled'));
|
|
test()->assertEquals((string) $data['tos'], (string) Setting::get('tos'));
|
|
test()->assertEquals((string) $data['reg_email_confirmation'], (string) Setting::get('reg_email_confirmation'));
|
|
}
|
|
|
|
function authSettingsData(): array
|
|
{
|
|
return [
|
|
'remember_me' => 1,
|
|
'forgot_password' => 1,
|
|
'login_reset_token_lifetime' => 123,
|
|
'throttle_enabled' => 1,
|
|
'throttle_attempts' => 10,
|
|
'throttle_lockout_time' => 2,
|
|
'reg_enabled' => 1,
|
|
'tos' => 1,
|
|
'reg_email_confirmation' => 1,
|
|
];
|
|
}
|