Timesheet validator: prevent overbooking budgets (#2422)
This commit is contained in:
@@ -9,10 +9,14 @@
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\Activity;
|
||||
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\ActivityFixtures;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
use App\Tests\Mocks\TimesheetTestMetaFieldSubscriberMock;
|
||||
|
||||
@@ -369,6 +373,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
['name' => 'timesheet.active_entries.default_begin', 'value' => '08:00'],
|
||||
['name' => 'timesheet.rules.allow_future_times', 'value' => true],
|
||||
['name' => 'timesheet.rules.allow_overlapping_records', 'value' => false],
|
||||
['name' => 'timesheet.rules.allow_overbooking_budget', 'value' => true],
|
||||
['name' => 'timesheet.rules.lockdown_period_start', 'value' => null],
|
||||
['name' => 'timesheet.rules.lockdown_period_end', 'value' => null],
|
||||
['name' => 'timesheet.rules.lockdown_grace_period', 'value' => null],
|
||||
@@ -406,6 +411,58 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateActionWithOverbookedActivity()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
|
||||
$fixture = new ActivityFixtures();
|
||||
$fixture->setAmount(1);
|
||||
$fixture->setIsGlobal(true);
|
||||
$fixture->setIsVisible(true);
|
||||
$fixture->setCallback(function (Activity $activity) {
|
||||
$activity->setBudget(1000);
|
||||
$activity->setTimeBudget(3600);
|
||||
});
|
||||
$activities = $this->importFixture($fixture);
|
||||
/** @var Activity $activity */
|
||||
$activity = $activities[0];
|
||||
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setAmount(1);
|
||||
$fixture->setActivities([$activity]);
|
||||
$fixture->setUser($this->getUserByRole(User::ROLE_USER));
|
||||
$timesheets = $this->importFixture($fixture);
|
||||
$id = $timesheets[0]->getId();
|
||||
|
||||
$this->request($client, '/timesheet/' . $id . '/edit');
|
||||
|
||||
$response = $client->getResponse();
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
|
||||
/** @var ConfigurationRepository $repository */
|
||||
$repository = $this->getEntityManager()->getRepository(Configuration::class);
|
||||
$config = new Configuration();
|
||||
$config->setName('timesheet.rules.allow_overbooking_budget');
|
||||
$config->setValue(false);
|
||||
$repository->saveConfiguration($config);
|
||||
|
||||
$this->assertHasValidationError(
|
||||
$client,
|
||||
'/timesheet/' . $id . '/edit',
|
||||
'form[name=timesheet_edit_form]',
|
||||
[
|
||||
'timesheet_edit_form' => [
|
||||
'hourlyRate' => 100,
|
||||
'begin' => '2020-02-18 01:00',
|
||||
'end' => '2020-02-18 02:10',
|
||||
'project' => 1,
|
||||
'activity' => $activity->getId(),
|
||||
]
|
||||
],
|
||||
['#timesheet_edit_form_activity']
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateActionWithBeginAndEndAndTagValues()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
Reference in New Issue
Block a user