weekly quick-entry form (#2793)
This commit is contained in:
@@ -71,6 +71,7 @@ class DurationStringToSecondsTransformerTest extends TestCase
|
||||
['00:00', 0],
|
||||
['0', null],
|
||||
[null, null],
|
||||
['87600000000:00:00', 315360000000000],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -80,6 +81,8 @@ class DurationStringToSecondsTransformerTest extends TestCase
|
||||
['xxx'],
|
||||
[':::'],
|
||||
['0::0'],
|
||||
['87600000000:00:01'],
|
||||
[315360000000001],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -98,4 +98,14 @@ class DurationTypeTest extends TypeTestCase
|
||||
|
||||
self::assertArrayNotHasKey('duration_presets', $view->vars);
|
||||
}
|
||||
|
||||
public function testHasDurationInputClass()
|
||||
{
|
||||
$view = $this->factory->create(DurationType::class, 3600, [
|
||||
'attr' => ['class' => 'testing']
|
||||
])->createView();
|
||||
|
||||
self::assertArrayHasKey('class', $view->vars['attr']);
|
||||
self::assertStringContainsString('duration-input testing', $view->vars['attr']['class']);
|
||||
}
|
||||
}
|
||||
|
||||
133
tests/Form/Type/QuickEntryTimesheetTypeTest.php
Normal file
133
tests/Form/Type/QuickEntryTimesheetTypeTest.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?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\Form\Type;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Form\Type\QuickEntryTimesheetType;
|
||||
use Symfony\Component\Form\PreloadedExtension;
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
* @covers \App\Form\Type\QuickEntryTimesheetType
|
||||
*/
|
||||
class QuickEntryTimesheetTypeTest extends TypeTestCase
|
||||
{
|
||||
protected function getExtensions()
|
||||
{
|
||||
$auth = $this->createMock(Security::class);
|
||||
$auth->method('getUser')->willReturn(new User());
|
||||
$auth->method('isGranted')->willReturn(true);
|
||||
|
||||
$type = new QuickEntryTimesheetType($auth);
|
||||
|
||||
return [
|
||||
new PreloadedExtension([$type], []),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTestData()
|
||||
{
|
||||
yield [4.5, 16200];
|
||||
yield ['4,5', 16200];
|
||||
yield ['4:30', 16200];
|
||||
yield ['4h30m', 16200];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTestData
|
||||
*/
|
||||
public function testSubmitValidData($value, $expectedDuration)
|
||||
{
|
||||
$data = ['duration' => $value];
|
||||
|
||||
$model = $this->createDefaultModel();
|
||||
|
||||
$form = $this->factory->create(QuickEntryTimesheetType::class, $model);
|
||||
|
||||
$form->submit($data);
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertEquals($expectedDuration, $model->getDuration());
|
||||
$this->assertEquals($expectedDuration, $model->getDuration(true));
|
||||
}
|
||||
|
||||
private function createDefaultModel(): Timesheet
|
||||
{
|
||||
$begin = new \DateTime('2020-02-15 12:30:00');
|
||||
$end = new \DateTime('2020-02-15 14:00:00');
|
||||
|
||||
$model = new Timesheet();
|
||||
$model->setBegin($begin);
|
||||
$model->setEnd($end);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function testPresetPopulatesView()
|
||||
{
|
||||
$view = $this->factory->create(QuickEntryTimesheetType::class, $this->createDefaultModel(), [
|
||||
'duration_minutes' => 15,
|
||||
'duration_hours' => 5,
|
||||
])->createView();
|
||||
|
||||
$vars = $view->children['duration']->vars;
|
||||
|
||||
self::assertArrayHasKey('duration_presets', $vars);
|
||||
self::assertCount(20, $vars['duration_presets']);
|
||||
self::assertEquals('0:30', $vars['duration_presets'][1]);
|
||||
self::assertEquals('4:45', $vars['duration_presets'][18]);
|
||||
}
|
||||
|
||||
public function testPresetsAreNotGeneratedOnMissingHours()
|
||||
{
|
||||
$view = $this->factory->create(QuickEntryTimesheetType::class, $this->createDefaultModel())->createView();
|
||||
|
||||
$vars = $view->children['duration']->vars;
|
||||
|
||||
self::assertArrayNotHasKey('duration_presets', $vars);
|
||||
}
|
||||
|
||||
public function testPresetsAreNotGeneratedOnMissingMinutes()
|
||||
{
|
||||
$view = $this->factory->create(QuickEntryTimesheetType::class, $this->createDefaultModel(), [
|
||||
'duration_hours' => 5,
|
||||
])->createView();
|
||||
|
||||
$vars = $view->children['duration']->vars;
|
||||
|
||||
self::assertArrayNotHasKey('duration_presets', $vars);
|
||||
}
|
||||
|
||||
public function testPresetsAreNotGeneratedOnNegativeMinutes()
|
||||
{
|
||||
$view = $this->factory->create(QuickEntryTimesheetType::class, $this->createDefaultModel(), [
|
||||
'duration_minutes' => -1,
|
||||
'duration_hours' => 5,
|
||||
])->createView();
|
||||
|
||||
$vars = $view->children['duration']->vars;
|
||||
|
||||
self::assertArrayNotHasKey('duration_presets', $vars);
|
||||
}
|
||||
|
||||
public function testPresetsAreNotGeneratedOnNegativeHours()
|
||||
{
|
||||
$view = $this->factory->create(QuickEntryTimesheetType::class, $this->createDefaultModel(), [
|
||||
'duration_minutes' => 5,
|
||||
'duration_hours' => -1,
|
||||
])->createView();
|
||||
|
||||
$vars = $view->children['duration']->vars;
|
||||
|
||||
self::assertArrayNotHasKey('duration_presets', $vars);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user