new system-config to prevent overlapping records (#1720)
This commit is contained in:
@@ -217,16 +217,15 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $role the USER role to use for the request
|
||||
* @param HttpKernelBrowser $client the client to use
|
||||
* @param string $url the URL of the page displaying the initial form to submit
|
||||
* @param string $formSelector a selector to find the form to test
|
||||
* @param array $formData values to fill in the form
|
||||
* @param array $fieldNames array of form-fields that should fail
|
||||
* @param bool $disableValidation whether the form should validate before submitting or not
|
||||
*/
|
||||
protected function assertFormHasValidationError($role, $url, $formSelector, array $formData, array $fieldNames, $disableValidation = true)
|
||||
protected function assertHasValidationError(HttpKernelBrowser $client, $url, $formSelector, array $formData, array $fieldNames, $disableValidation = true)
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser($role);
|
||||
$crawler = $client->request('GET', $this->createUrl($url));
|
||||
$form = $crawler->filter($formSelector)->form();
|
||||
if ($disableValidation) {
|
||||
@@ -260,6 +259,20 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $role the USER role to use for the request
|
||||
* @param string $url the URL of the page displaying the initial form to submit
|
||||
* @param string $formSelector a selector to find the form to test
|
||||
* @param array $formData values to fill in the form
|
||||
* @param array $fieldNames array of form-fields that should fail
|
||||
* @param bool $disableValidation whether the form should validate before submitting or not
|
||||
*/
|
||||
protected function assertFormHasValidationError($role, $url, $formSelector, array $formData, array $fieldNames, $disableValidation = true)
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser($role);
|
||||
$this->assertHasValidationError($client, $url, $formSelector, $formData, $fieldNames, $disableValidation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HttpKernelBrowser $client
|
||||
*/
|
||||
|
||||
@@ -100,6 +100,7 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
||||
['name' => 'timesheet.mode', 'value' => 'duration_only'],
|
||||
['name' => 'timesheet.active_entries.default_begin', 'value' => '23:59'],
|
||||
['name' => 'timesheet.rules.allow_future_times', 'value' => false],
|
||||
['name' => 'timesheet.rules.allow_overlapping_records', 'value' => false],
|
||||
['name' => 'timesheet.active_entries.hard_limit', 'value' => 99],
|
||||
['name' => 'timesheet.active_entries.soft_limit', 'value' => 77],
|
||||
]
|
||||
@@ -114,6 +115,7 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
||||
$configService = static::$kernel->getContainer()->get(SystemConfiguration::class);
|
||||
$this->assertEquals('duration_only', $configService->find('timesheet.mode'));
|
||||
$this->assertEquals(false, $configService->find('timesheet.rules.allow_future_times'));
|
||||
$this->assertEquals(false, $configService->find('timesheet.rules.allow_overlapping_records'));
|
||||
$this->assertEquals(99, $configService->find('timesheet.active_entries.hard_limit'));
|
||||
$this->assertEquals(77, $configService->find('timesheet.active_entries.soft_limit'));
|
||||
}
|
||||
@@ -130,6 +132,7 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
||||
['name' => 'timesheet.mode', 'value' => 'foo'],
|
||||
['name' => 'timesheet.active_entries.default_begin', 'value' => '23:59'],
|
||||
['name' => 'timesheet.rules.allow_future_times', 'value' => 1],
|
||||
['name' => 'timesheet.rules.allow_overlapping_records', 'value' => 1],
|
||||
['name' => 'timesheet.active_entries.hard_limit', 'value' => -1],
|
||||
['name' => 'timesheet.active_entries.soft_limit', 'value' => -1],
|
||||
]
|
||||
@@ -137,8 +140,8 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
||||
],
|
||||
[
|
||||
'#system_configuration_form_timesheet_configuration_0_value', // mode
|
||||
'#system_configuration_form_timesheet_configuration_3_value', // hard_limit
|
||||
'#system_configuration_form_timesheet_configuration_4_value', // soft_limit
|
||||
'#system_configuration_form_timesheet_configuration_4_value', // hard_limit
|
||||
'#system_configuration_form_timesheet_configuration_5_value', // soft_limit
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
@@ -9,10 +9,12 @@
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\Configuration;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\TimesheetMeta;
|
||||
use App\Entity\User;
|
||||
use App\Form\Type\DateRangeType;
|
||||
use App\Repository\ConfigurationRepository;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
use App\Tests\Mocks\TimesheetTestMetaFieldSubscriberMock;
|
||||
|
||||
@@ -250,6 +252,115 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals($expected->format(\DateTime::ATOM), $timesheet->getEnd()->format(\DateTime::ATOM));
|
||||
}
|
||||
|
||||
public function testCreateActionWithFromAndToValuesTwice()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$this->request($client, '/timesheet/create?from=2018-08-02T20%3A00%3A00&to=2018-08-02T20%3A30%3A00');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$form = $client->getCrawler()->filter('form[name=timesheet_edit_form]')->form();
|
||||
$client->submit($form, [
|
||||
'timesheet_edit_form' => [
|
||||
'hourlyRate' => 100,
|
||||
'project' => 1,
|
||||
'activity' => 1,
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertIsRedirect($client, $this->createUrl('/timesheet/'));
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
$this->assertHasFlashSuccess($client);
|
||||
|
||||
$em = $this->getEntityManager();
|
||||
/** @var Timesheet $timesheet */
|
||||
$timesheet = $em->getRepository(Timesheet::class)->find(1);
|
||||
$this->assertInstanceOf(\DateTime::class, $timesheet->getBegin());
|
||||
$this->assertInstanceOf(\DateTime::class, $timesheet->getEnd());
|
||||
$this->assertEquals(50, $timesheet->getRate());
|
||||
|
||||
$expected = new \DateTime('2018-08-02T20:00:00');
|
||||
$this->assertEquals($expected->format(\DateTime::ATOM), $timesheet->getBegin()->format(\DateTime::ATOM));
|
||||
|
||||
$expected = new \DateTime('2018-08-02T20:30:00');
|
||||
$this->assertEquals($expected->format(\DateTime::ATOM), $timesheet->getEnd()->format(\DateTime::ATOM));
|
||||
|
||||
// create a second entry that is overlapping
|
||||
$this->request($client, '/timesheet/create?from=2018-08-02T20%3A02%3A00&to=2018-08-02T20%3A20%3A00');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$form = $client->getCrawler()->filter('form[name=timesheet_edit_form]')->form();
|
||||
$client->submit($form, [
|
||||
'timesheet_edit_form' => [
|
||||
'hourlyRate' => 100,
|
||||
'project' => 1,
|
||||
'activity' => 1,
|
||||
]
|
||||
]);
|
||||
$this->assertIsRedirect($client, $this->createUrl('/timesheet/'));
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
$this->assertHasFlashSuccess($client);
|
||||
}
|
||||
|
||||
public function testCreateActionWithFromAndToValuesTwiceFailsOnOverlappingRecord()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$this->request($client, '/timesheet/create?from=2018-08-02T20%3A00%3A00&to=2018-08-02T20%3A30%3A00');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$form = $client->getCrawler()->filter('form[name=timesheet_edit_form]')->form();
|
||||
$client->submit($form, [
|
||||
'timesheet_edit_form' => [
|
||||
'hourlyRate' => 100,
|
||||
'project' => 1,
|
||||
'activity' => 1,
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertIsRedirect($client, $this->createUrl('/timesheet/'));
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
$this->assertHasFlashSuccess($client);
|
||||
|
||||
$em = $this->getEntityManager();
|
||||
/** @var Timesheet $timesheet */
|
||||
$timesheet = $em->getRepository(Timesheet::class)->find(1);
|
||||
$this->assertInstanceOf(\DateTime::class, $timesheet->getBegin());
|
||||
$this->assertInstanceOf(\DateTime::class, $timesheet->getEnd());
|
||||
$this->assertEquals(50, $timesheet->getRate());
|
||||
|
||||
$expected = new \DateTime('2018-08-02T20:00:00');
|
||||
$this->assertEquals($expected->format(\DateTime::ATOM), $timesheet->getBegin()->format(\DateTime::ATOM));
|
||||
|
||||
$expected = new \DateTime('2018-08-02T20:30:00');
|
||||
$this->assertEquals($expected->format(\DateTime::ATOM), $timesheet->getEnd()->format(\DateTime::ATOM));
|
||||
|
||||
/** @var ConfigurationRepository $configurations */
|
||||
$configurations = $em->getRepository(Configuration::class);
|
||||
$config = new Configuration();
|
||||
$config->setName('timesheet.rules.allow_overlapping_records');
|
||||
$config->setValue(false);
|
||||
$configurations->saveConfiguration($config);
|
||||
|
||||
// create a second entry that is overlapping fails due to the changed config above
|
||||
$this->assertHasValidationError(
|
||||
$client,
|
||||
'/timesheet/create?from=2018-08-02T20%3A02%3A00&to=2018-08-02T20%3A20%3A00',
|
||||
'form[name=timesheet_edit_form]',
|
||||
[
|
||||
'timesheet_edit_form' => [
|
||||
'hourlyRate' => 100,
|
||||
'project' => 1,
|
||||
'activity' => 1,
|
||||
]
|
||||
],
|
||||
['#timesheet_edit_form_begin']
|
||||
);
|
||||
|
||||
$configurations->clearCache();
|
||||
}
|
||||
|
||||
public function testCreateActionWithBeginAndEndAndTagValues()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
Reference in New Issue
Block a user