293 lines
13 KiB
PHP
293 lines
13 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Kimai time-tracking app.
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace App\Tests\Controller;
|
|
|
|
use App\Configuration\SystemConfiguration;
|
|
use App\Entity\User;
|
|
|
|
/**
|
|
* @group integration
|
|
*/
|
|
class SystemConfigurationControllerTest extends ControllerBaseTest
|
|
{
|
|
public function testIsSecure()
|
|
{
|
|
$this->assertUrlIsSecured('/admin/system-config/');
|
|
$this->assertUrlIsSecuredForRole(User::ROLE_ADMIN, '/admin/system-config/');
|
|
}
|
|
|
|
public function testIndexAction()
|
|
{
|
|
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
|
$this->assertAccessIsGranted($client, '/admin/system-config/');
|
|
|
|
$expectedForms = $this->getTestDataForms();
|
|
|
|
$result = $client->getCrawler()->filter('section.content div.box.box-primary');
|
|
$this->assertEquals(count($expectedForms), count($result));
|
|
|
|
$result = $client->getCrawler()->filter('section.content div.box.box-primary form');
|
|
$this->assertEquals(count($expectedForms), count($result));
|
|
|
|
foreach ($expectedForms as $formConfig) {
|
|
$result = $client->getCrawler()->filter($formConfig[0]);
|
|
$this->assertEquals(1, count($result));
|
|
$form = $result->form();
|
|
$this->assertStringEndsWith($formConfig[1], $form->getUri());
|
|
$this->assertEquals('POST', $form->getMethod());
|
|
}
|
|
}
|
|
|
|
public function getTestDataForms()
|
|
{
|
|
return [
|
|
['form[name=system_configuration_form_timesheet]', $this->createUrl('/admin/system-config/update/timesheet')],
|
|
['form[name=system_configuration_form_form_customer]', $this->createUrl('/admin/system-config/update/form_customer')],
|
|
['form[name=system_configuration_form_theme]', $this->createUrl('/admin/system-config/update/theme')],
|
|
['form[name=system_configuration_form_calendar]', $this->createUrl('/admin/system-config/update/calendar')],
|
|
];
|
|
}
|
|
|
|
public function testUpdateTimesheetConfig()
|
|
{
|
|
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
|
$this->assertAccessIsGranted($client, '/admin/system-config/');
|
|
|
|
$configService = $client->getContainer()->get(SystemConfiguration::class);
|
|
$this->assertEquals('default', $configService->find('timesheet.mode'));
|
|
$this->assertEquals(true, $configService->find('timesheet.rules.allow_future_times'));
|
|
$this->assertEquals(1, $configService->find('timesheet.active_entries.hard_limit'));
|
|
$this->assertEquals(1, $configService->find('timesheet.active_entries.soft_limit'));
|
|
|
|
$form = $client->getCrawler()->filter('form[name=system_configuration_form_timesheet]')->form();
|
|
$client->submit($form, [
|
|
'system_configuration_form_timesheet' => [
|
|
'configuration' => [
|
|
['name' => 'timesheet.mode', 'value' => 'duration_only'],
|
|
['name' => 'timesheet.rules.allow_future_times', 'value' => false],
|
|
['name' => 'timesheet.active_entries.hard_limit', 'value' => 99],
|
|
['name' => 'timesheet.active_entries.soft_limit', 'value' => 77],
|
|
]
|
|
]
|
|
]);
|
|
|
|
$this->assertIsRedirect($client, $this->createUrl('/admin/system-config/'));
|
|
$client->followRedirect();
|
|
$this->assertTrue($client->getResponse()->isSuccessful());
|
|
$this->assertHasFlashSaveSuccess($client);
|
|
|
|
$configService = $client->getContainer()->get(SystemConfiguration::class);
|
|
$this->assertEquals('duration_only', $configService->find('timesheet.mode'));
|
|
$this->assertEquals(false, $configService->find('timesheet.rules.allow_future_times'));
|
|
$this->assertEquals(99, $configService->find('timesheet.active_entries.hard_limit'));
|
|
$this->assertEquals(77, $configService->find('timesheet.active_entries.soft_limit'));
|
|
}
|
|
|
|
public function testUpdateTimesheetConfigValidation()
|
|
{
|
|
$this->assertFormHasValidationError(
|
|
User::ROLE_SUPER_ADMIN,
|
|
'/admin/system-config/',
|
|
'form[name=system_configuration_form_timesheet]',
|
|
[
|
|
'system_configuration_form_timesheet' => [
|
|
'configuration' => [
|
|
['name' => 'timesheet.mode', 'value' => 'foo'],
|
|
['name' => 'timesheet.rules.allow_future_times', 'value' => 1],
|
|
['name' => 'timesheet.active_entries.hard_limit', 'value' => -1],
|
|
['name' => 'timesheet.active_entries.soft_limit', 'value' => -1],
|
|
]
|
|
]
|
|
],
|
|
[
|
|
'#system_configuration_form_timesheet_configuration_0_value', // mode
|
|
'#system_configuration_form_timesheet_configuration_2_value', // hard_limit
|
|
'#system_configuration_form_timesheet_configuration_3_value', // soft_limit
|
|
],
|
|
true
|
|
);
|
|
}
|
|
|
|
public function testUpdateCustomerConfig()
|
|
{
|
|
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
|
$this->assertAccessIsGranted($client, '/admin/system-config/');
|
|
|
|
$configService = $client->getContainer()->get(SystemConfiguration::class);
|
|
$this->assertEquals('Europe/Berlin', $configService->find('defaults.customer.timezone'));
|
|
$this->assertEquals('DE', $configService->find('defaults.customer.country'));
|
|
$this->assertEquals('EUR', $configService->find('defaults.customer.currency'));
|
|
|
|
$form = $client->getCrawler()->filter('form[name=system_configuration_form_form_customer]')->form();
|
|
$client->submit($form, [
|
|
'system_configuration_form_form_customer' => [
|
|
'configuration' => [
|
|
['name' => 'defaults.customer.timezone', 'value' => 'Atlantic/Canary'],
|
|
['name' => 'defaults.customer.country', 'value' => 'BB'],
|
|
['name' => 'defaults.customer.currency', 'value' => 'GBP'],
|
|
]
|
|
]
|
|
]);
|
|
|
|
$this->assertIsRedirect($client, $this->createUrl('/admin/system-config/'));
|
|
$client->followRedirect();
|
|
$this->assertTrue($client->getResponse()->isSuccessful());
|
|
$this->assertHasFlashSaveSuccess($client);
|
|
|
|
$configService = $client->getContainer()->get(SystemConfiguration::class);
|
|
$this->assertEquals('Atlantic/Canary', $configService->find('defaults.customer.timezone'));
|
|
$this->assertEquals('BB', $configService->find('defaults.customer.country'));
|
|
$this->assertEquals('GBP', $configService->find('defaults.customer.currency'));
|
|
}
|
|
|
|
public function testUpdateCustomerConfigValidation()
|
|
{
|
|
$this->assertFormHasValidationError(
|
|
User::ROLE_SUPER_ADMIN,
|
|
'/admin/system-config/',
|
|
'form[name=system_configuration_form_form_customer]',
|
|
[
|
|
'system_configuration_form_form_customer' => [
|
|
'configuration' => [
|
|
['name' => 'defaults.customer.timezone', 'value' => 'XX'],
|
|
['name' => 'defaults.customer.country', 'value' => 1],
|
|
['name' => 'defaults.customer.currency', 'value' => 'XXX'],
|
|
]
|
|
]
|
|
],
|
|
[
|
|
'#system_configuration_form_form_customer_configuration_0_value',
|
|
'#system_configuration_form_form_customer_configuration_1_value',
|
|
'#system_configuration_form_form_customer_configuration_2_value',
|
|
],
|
|
true
|
|
);
|
|
}
|
|
|
|
public function testUpdateThemeConfig()
|
|
{
|
|
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
|
$this->assertAccessIsGranted($client, '/admin/system-config/');
|
|
|
|
$configService = $client->getContainer()->get(SystemConfiguration::class);
|
|
$this->assertEquals(false, $configService->find('timesheet.markdown_content'));
|
|
$this->assertNull($configService->find('theme.select_type'));
|
|
|
|
$form = $client->getCrawler()->filter('form[name=system_configuration_form_theme]')->form();
|
|
$client->submit($form, [
|
|
'system_configuration_form_theme' => [
|
|
'configuration' => [
|
|
['name' => 'theme.select_type', 'value' => 'selectpicker'],
|
|
['name' => 'timesheet.markdown_content', 'value' => 1],
|
|
]
|
|
]
|
|
]);
|
|
|
|
$this->assertIsRedirect($client, $this->createUrl('/admin/system-config/'));
|
|
$client->followRedirect();
|
|
$this->assertTrue($client->getResponse()->isSuccessful());
|
|
$this->assertHasFlashSaveSuccess($client);
|
|
|
|
$configService = $client->getContainer()->get(SystemConfiguration::class);
|
|
$this->assertEquals('selectpicker', $configService->find('theme.select_type'));
|
|
$this->assertEquals(true, $configService->find('timesheet.markdown_content'));
|
|
}
|
|
|
|
public function testUpdateThemeConfigValidation()
|
|
{
|
|
$this->assertFormHasValidationError(
|
|
User::ROLE_SUPER_ADMIN,
|
|
'/admin/system-config/',
|
|
'form[name=system_configuration_form_theme]',
|
|
[
|
|
'system_configuration_form_theme' => [
|
|
'configuration' => [
|
|
['name' => 'theme.select_type', 'value' => 'foo'],
|
|
['name' => 'timesheet.markdown_content', 'value' => 1],
|
|
]
|
|
]
|
|
],
|
|
[
|
|
'#system_configuration_form_theme_configuration_0_value',
|
|
],
|
|
true
|
|
);
|
|
}
|
|
|
|
public function testUpdateCalendarConfig()
|
|
{
|
|
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
|
$this->assertAccessIsGranted($client, '/admin/system-config/');
|
|
|
|
$configService = $client->getContainer()->get(SystemConfiguration::class);
|
|
$this->assertTrue($configService->find('calendar.week_numbers'));
|
|
$this->assertTrue($configService->find('calendar.weekends'));
|
|
$this->assertEquals('08:00', $configService->find('calendar.businessHours.begin'));
|
|
$this->assertEquals('20:00', $configService->find('calendar.businessHours.end'));
|
|
$this->assertEquals('00:00', $configService->find('calendar.visibleHours.begin'));
|
|
$this->assertEquals('24:00', $configService->find('calendar.visibleHours.end'));
|
|
|
|
$form = $client->getCrawler()->filter('form[name=system_configuration_form_calendar]')->form();
|
|
$client->submit($form, [
|
|
'system_configuration_form_calendar' => [
|
|
'configuration' => [
|
|
['name' => 'calendar.week_numbers', 'value' => false],
|
|
['name' => 'calendar.weekends', 'value' => false],
|
|
['name' => 'calendar.businessHours.begin', 'value' => '10:00'],
|
|
['name' => 'calendar.businessHours.end', 'value' => '16:00'],
|
|
['name' => 'calendar.visibleHours.begin', 'value' => '05:17'],
|
|
['name' => 'calendar.visibleHours.end', 'value' => '21:43'],
|
|
]
|
|
]
|
|
]);
|
|
|
|
$this->assertIsRedirect($client, $this->createUrl('/admin/system-config/'));
|
|
$client->followRedirect();
|
|
$this->assertTrue($client->getResponse()->isSuccessful());
|
|
$this->assertHasFlashSaveSuccess($client);
|
|
|
|
$configService = $client->getContainer()->get(SystemConfiguration::class);
|
|
$this->assertFalse($configService->find('calendar.week_numbers'));
|
|
$this->assertFalse($configService->find('calendar.weekends'));
|
|
$this->assertEquals('10:00', $configService->find('calendar.businessHours.begin'));
|
|
$this->assertEquals('16:00', $configService->find('calendar.businessHours.end'));
|
|
$this->assertEquals('05:17', $configService->find('calendar.visibleHours.begin'));
|
|
$this->assertEquals('21:43', $configService->find('calendar.visibleHours.end'));
|
|
}
|
|
|
|
public function testUpdateCalendarConfigValidation()
|
|
{
|
|
$this->assertFormHasValidationError(
|
|
User::ROLE_SUPER_ADMIN,
|
|
'/admin/system-config/',
|
|
'form[name=system_configuration_form_calendar]',
|
|
[
|
|
'system_configuration_form_calendar' => [
|
|
'configuration' => [
|
|
['name' => 'calendar.week_numbers', 'value' => 'foo'],
|
|
['name' => 'calendar.weekends', 'value' => 'bar'],
|
|
['name' => 'calendar.businessHours.begin', 'value' => '25:13'],
|
|
['name' => 'calendar.businessHours.end', 'value' => null],
|
|
['name' => 'calendar.visibleHours.begin', 'value' => 'aa:bb'],
|
|
['name' => 'calendar.visibleHours.end', 'value' => ''],
|
|
]
|
|
]
|
|
],
|
|
[
|
|
'#system_configuration_form_calendar_configuration_2_value',
|
|
'#system_configuration_form_calendar_configuration_3_value',
|
|
'#system_configuration_form_calendar_configuration_4_value',
|
|
'#system_configuration_form_calendar_configuration_5_value',
|
|
],
|
|
true
|
|
);
|
|
}
|
|
}
|