138 lines
4.7 KiB
PHP
138 lines
4.7 KiB
PHP
<?php
|
|
|
|
/** @noinspection ALL */
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Sinnbeck\DomAssertions\Asserts\AssertForm;
|
|
use Sinnbeck\DomAssertions\Asserts\AssertSelect;
|
|
|
|
use function Pest\Laravel\get;
|
|
use function Pest\Laravel\post;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('allows administrators to access the settings page', function () {
|
|
actAsAdmin();
|
|
get(route('audition-settings'))
|
|
->assertOk()
|
|
->assertViewIs('admin.audition-settings');
|
|
});
|
|
it('does not allow normal users to access the settings page', function () {
|
|
// Arrange
|
|
actAsNormal();
|
|
// Act & Assert
|
|
get(route('audition-settings'))
|
|
->assertSessionHas('error', 'You are not authorized to perform this action')
|
|
->assertRedirect(route('dashboard'));
|
|
});
|
|
it('does not allow guests to access the settings page', function () {
|
|
// Act & Assert
|
|
get(route('audition-settings'))
|
|
->assertRedirect(route('home'));
|
|
});
|
|
it('has a field with forms for each audition setting', function () {
|
|
// Arrange
|
|
actAsAdmin();
|
|
// Act
|
|
$response = get(route('audition-settings'));
|
|
// Assert
|
|
$response->assertOk();
|
|
$response->assertFormExists('#settingsForm', function (AssertForm $form) {
|
|
$form->hasMethod('POST')
|
|
->hasAction(route('audition-settings-save'))
|
|
->hasCSRF()
|
|
->containsInput([
|
|
'name' => 'auditionName',
|
|
'value' => auditionSetting('auditionName'),
|
|
])
|
|
->containsInput([
|
|
'name' => 'auditionAbbreviation',
|
|
'value' => auditionSetting('auditionAbbreviation'),
|
|
])
|
|
->containsInput([
|
|
'name' => 'registrationCode',
|
|
'value' => auditionSetting('registrationCode'),
|
|
])
|
|
->containsInput([
|
|
'name' => 'advanceTo',
|
|
'value' => auditionSetting('advanceTo'),
|
|
])
|
|
->containsInput([
|
|
'name' => 'organizerName',
|
|
'value' => auditionSetting('organizerName'),
|
|
])
|
|
->containsInput([
|
|
'name' => 'organizerEmail',
|
|
'value' => auditionSetting('organizerEmail'),
|
|
])
|
|
->containsInput([
|
|
'name' => 'late_fee',
|
|
'value' => number_format(auditionSetting('late_fee') / 100, 2),
|
|
])
|
|
->containsInput([
|
|
'name' => 'school_fee',
|
|
'value' => number_format(auditionSetting('school_fee') / 100, 2),
|
|
])
|
|
->containsTextarea([
|
|
'name' => 'payment_address',
|
|
'value' => auditionSetting('payment_address'),
|
|
])
|
|
->containsInput([
|
|
'name' => 'payment_city',
|
|
'value' => auditionSetting('payment_city'),
|
|
])
|
|
->containsInput([
|
|
'name' => 'payment_state',
|
|
'value' => auditionSetting('payment_state'),
|
|
])
|
|
->containsInput([
|
|
'name' => 'payment_zip',
|
|
'value' => auditionSetting('payment_zip'),
|
|
'type' => 'number',
|
|
])
|
|
->containsInput([
|
|
'name' => 'olympic_scoring',
|
|
'type' => 'checkbox',
|
|
])
|
|
->containsInput([
|
|
'name' => 'judging_enabled',
|
|
'type' => 'checkbox',
|
|
])
|
|
->findSelect('#fee_structure', function (AssertSelect $select) {
|
|
$select->containsOption([
|
|
'value' => 'oneFeePerEntry',
|
|
'text' => 'One fee per entry',
|
|
])
|
|
->containsOption([
|
|
'value' => 'oneFeePerStudent',
|
|
'text' => 'One fee per student - one late fee per student if any of their entries are late',
|
|
]);
|
|
});
|
|
});
|
|
});
|
|
it('can update audition settings', function () {
|
|
// Arrange
|
|
actAsAdmin();
|
|
$newData = [
|
|
'auditionName' => 'New Audition Name',
|
|
'auditionAbbreviation' => 'NAN',
|
|
'registrationCode' => 'NEWCODE',
|
|
'advanceTo' => 'next',
|
|
'organizerName' => 'New Organizer Name',
|
|
'organizerEmail' => 'newemail@new.com',
|
|
'late_fee' => 150.00,
|
|
'school_fee' => 200.00,
|
|
'payment_address' => '123 New St',
|
|
'payment_city' => 'New City',
|
|
'payment_state' => 'NS',
|
|
'payment_zip' => 12345,
|
|
'fee_structure' => 'oneFeePerEntry',
|
|
];
|
|
// Act
|
|
$response = post(route('audition-settings-save'), $newData);
|
|
// Act & Assert
|
|
$response->assertRedirect(route('audition-settings'))
|
|
->assertSessionHasNoErrors()
|
|
->assertSessionHas('success', 'Settings Saved');
|
|
});
|