Release 2.33.0 (#5438)
This commit is contained in:
@@ -28,10 +28,13 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
*/
|
||||
class CsvRendererTest extends AbstractRendererTestCase
|
||||
{
|
||||
protected function getAbstractRenderer(): CsvRenderer
|
||||
protected function getAbstractRenderer(bool $exportDecimal = false): CsvRenderer
|
||||
{
|
||||
$user = $this->createMock(User::class);
|
||||
$user->expects($this->any())->method('isExportDecimal')->willReturn($exportDecimal);
|
||||
|
||||
$security = $this->createMock(Security::class);
|
||||
$security->expects($this->any())->method('getUser')->willReturn(new User());
|
||||
$security->expects($this->any())->method('getUser')->willReturn($user);
|
||||
$security->expects($this->any())->method('isGranted')->willReturn(true);
|
||||
|
||||
$translator = $this->createMock(TranslatorInterface::class);
|
||||
@@ -53,16 +56,17 @@ class CsvRendererTest extends AbstractRendererTestCase
|
||||
public static function getTestModel(): array
|
||||
{
|
||||
return [
|
||||
['400', '2437.12', '1947.99', 7, 6, 1, 2, 2]
|
||||
['400', '2437.12', '1947.99', 7, 6, 1, 2, 2, false],
|
||||
['400', '2437.12', '1947.99', 7, 6, 1, 2, 2, true]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTestModel
|
||||
*/
|
||||
public function testRender(string $totalDuration, string $totalRate, string $expectedRate, int $expectedRows, int $expectedDescriptions, int $expectedUser1, int $expectedUser2, int $expectedUser3): void
|
||||
public function testRender(string $totalDuration, string $totalRate, string $expectedRate, int $expectedRows, int $expectedDescriptions, int $expectedUser1, int $expectedUser2, int $expectedUser3, bool $exportDecimal): void
|
||||
{
|
||||
$sut = $this->getAbstractRenderer();
|
||||
$sut = $this->getAbstractRenderer($exportDecimal);
|
||||
|
||||
/** @var BinaryFileResponse $response */
|
||||
$response = $this->render($sut);
|
||||
@@ -102,7 +106,7 @@ class CsvRendererTest extends AbstractRendererTestCase
|
||||
'2019-06-16',
|
||||
'12:00',
|
||||
'12:06',
|
||||
'0:06',
|
||||
($exportDecimal ? '0.11' : '0:06:40'),
|
||||
//'0.11',
|
||||
'EUR',
|
||||
'0',
|
||||
@@ -136,7 +140,7 @@ class CsvRendererTest extends AbstractRendererTestCase
|
||||
'2019-06-16',
|
||||
'12:00',
|
||||
'12:06',
|
||||
'0:06',
|
||||
($exportDecimal ? '0.11' : '0:06:40'),
|
||||
//'0.11',
|
||||
'EUR',
|
||||
'0',
|
||||
|
||||
@@ -17,6 +17,12 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
class DateFormatterTest extends TestCase
|
||||
{
|
||||
public function testGetFormat(): void
|
||||
{
|
||||
$formatter = new DateFormatter();
|
||||
self::assertEquals('yyyy-mm-dd', $formatter->getFormat());
|
||||
}
|
||||
|
||||
public function testFormatValueReturnsFormattedDateForDateTime(): void
|
||||
{
|
||||
$formatter = new DateFormatter();
|
||||
|
||||
@@ -17,38 +17,57 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
class DurationFormatterTest extends TestCase
|
||||
{
|
||||
public function testGetFormat(): void
|
||||
{
|
||||
$formatter = new DurationFormatter();
|
||||
self::assertEquals('[hh]:mm:ss', $formatter->getFormat());
|
||||
}
|
||||
|
||||
public function testFormatValueReturnsFormattedDurationQuiteLong(): void
|
||||
{
|
||||
$formatter = new DurationFormatter();
|
||||
$result = $formatter->formatValue(701213);
|
||||
self::assertInstanceOf(\DateInterval::class, $result);
|
||||
self::assertEquals('194:46:53', $result->format('%r%H:%I:%S'));
|
||||
}
|
||||
|
||||
public function testFormatValueReturnsFormattedDurationForNumericValue(): void
|
||||
{
|
||||
$formatter = new DurationFormatter();
|
||||
$result = $formatter->formatValue(7200);
|
||||
self::assertEquals('2:00', $result);
|
||||
$result = $formatter->formatValue(7213);
|
||||
self::assertInstanceOf(\DateInterval::class, $result);
|
||||
self::assertEquals('02:00:13', $result->format('%r%H:%I:%S'));
|
||||
}
|
||||
|
||||
public function testFormatValueReturnsZeroForNonNumericValue(): void
|
||||
{
|
||||
$formatter = new DurationFormatter();
|
||||
$result = $formatter->formatValue('not a number');
|
||||
self::assertEquals('0:00', $result);
|
||||
self::assertInstanceOf(\DateInterval::class, $result);
|
||||
self::assertEquals('00:00:00', $result->format('%r%H:%I:%S'));
|
||||
}
|
||||
|
||||
public function testFormatValueReturnsFormattedDurationForFloatValue(): void
|
||||
{
|
||||
$formatter = new DurationFormatter();
|
||||
$result = $formatter->formatValue(4500.5);
|
||||
self::assertEquals('1:15', $result);
|
||||
$result = $formatter->formatValue(4521.5);
|
||||
self::assertInstanceOf(\DateInterval::class, $result);
|
||||
self::assertEquals('01:15:21', $result->format('%r%H:%I:%S'));
|
||||
}
|
||||
|
||||
public function testFormatValueReturnsZeroForNullValue(): void
|
||||
{
|
||||
$formatter = new DurationFormatter();
|
||||
$result = $formatter->formatValue(null);
|
||||
self::assertEquals('0:00', $result);
|
||||
self::assertInstanceOf(\DateInterval::class, $result);
|
||||
self::assertEquals('00:00:00', $result->format('%r%H:%I:%S'));
|
||||
}
|
||||
|
||||
public function testFormatValueReturnsFormattedDurationForNegativeValue(): void
|
||||
{
|
||||
$formatter = new DurationFormatter();
|
||||
$result = $formatter->formatValue(-3600);
|
||||
self::assertEquals('-1:00', $result);
|
||||
self::assertInstanceOf(\DateInterval::class, $result);
|
||||
self::assertEquals('-01:00:00', $result->format('%r%H:%I:%S'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?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\Export\Package\CellFormatter;
|
||||
|
||||
use App\Export\Package\CellFormatter\DurationPlainFormatter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Export\Package\CellFormatter\DurationPlainFormatter
|
||||
*/
|
||||
class DurationPlainFormatterTest extends TestCase
|
||||
{
|
||||
public function testFormatValueReturnsFormattedDurationQuiteLong(): void
|
||||
{
|
||||
$formatter = new DurationPlainFormatter();
|
||||
$result = $formatter->formatValue(701213);
|
||||
self::assertEquals('194:46:53', $result);
|
||||
}
|
||||
|
||||
public function testFormatValueReturnsFormattedDurationForNumericValue(): void
|
||||
{
|
||||
$formatter = new DurationPlainFormatter();
|
||||
$result = $formatter->formatValue(8246);
|
||||
self::assertEquals('2:17:26', $result);
|
||||
}
|
||||
|
||||
public function testFormatValueReturnsZeroForNonNumericValue(): void
|
||||
{
|
||||
$formatter = new DurationPlainFormatter();
|
||||
$result = $formatter->formatValue('not a number');
|
||||
self::assertEquals('0:00:00', $result);
|
||||
}
|
||||
|
||||
public function testFormatValueReturnsFormattedDurationForFloatValue(): void
|
||||
{
|
||||
$formatter = new DurationPlainFormatter();
|
||||
$result = $formatter->formatValue(44513.5);
|
||||
self::assertEquals('12:21:53', $result);
|
||||
}
|
||||
|
||||
public function testFormatValueReturnsZeroForNullValue(): void
|
||||
{
|
||||
$formatter = new DurationPlainFormatter();
|
||||
$result = $formatter->formatValue(null);
|
||||
self::assertEquals('0:00:00', $result);
|
||||
}
|
||||
|
||||
public function testFormatValueReturnsFormattedDurationForNegativeValue(): void
|
||||
{
|
||||
$formatter = new DurationPlainFormatter();
|
||||
$result = $formatter->formatValue(-3600);
|
||||
self::assertEquals('-1:00:00', $result);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ namespace App\Tests\Export\Package;
|
||||
|
||||
use App\Entity\ExportableItem;
|
||||
use App\Export\Package\CellFormatter\CellFormatterInterface;
|
||||
use App\Export\Package\CellFormatter\DateFormatter;
|
||||
use App\Export\Package\Column;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -85,4 +86,17 @@ class ColumnTest extends TestCase
|
||||
$column = new Column('testName', $formatter);
|
||||
self::assertEquals('testName', $column->getHeader());
|
||||
}
|
||||
|
||||
public function testWithFormatReturnsNull(): void
|
||||
{
|
||||
$formatter = $this->createMock(CellFormatterInterface::class);
|
||||
$column = new Column('testName', $formatter);
|
||||
self::assertNull($column->getFormat());
|
||||
}
|
||||
|
||||
public function testWithFormatReturnsValueFromFormatter(): void
|
||||
{
|
||||
$column = new Column('testName', new DateFormatter());
|
||||
self::assertEquals('yyyy-mm-dd', $column->getFormat());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,84 +67,72 @@ abstract class AbstractRendererTestCase extends KernelTestCase
|
||||
$user2->method('getUsername')->willReturn('hello-world');
|
||||
|
||||
$timesheet = new Timesheet();
|
||||
$timesheet
|
||||
->setDuration(3600) // 60 minutes
|
||||
->setRate(293.27)
|
||||
->setUser($user1)
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
$timesheet->setDuration(3600);
|
||||
$timesheet->setRate(293.27);
|
||||
$timesheet->setUser($user1);
|
||||
$timesheet->setActivity($activity);
|
||||
$timesheet->setProject($project);
|
||||
$timesheet->setBegin(new \DateTime());
|
||||
$timesheet->setEnd(new \DateTime());
|
||||
|
||||
$timesheet2 = new Timesheet();
|
||||
$timesheet2
|
||||
->setDuration(400)
|
||||
->setRate(84.75)
|
||||
->setUser($user2)
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
$timesheet2->setDuration(400);
|
||||
$timesheet2->setRate(84.75);
|
||||
$timesheet2->setUser($user2);
|
||||
$timesheet2->setActivity($activity);
|
||||
$timesheet2->setProject($project);
|
||||
$timesheet2->setBegin(new \DateTime());
|
||||
$timesheet2->setEnd(new \DateTime());
|
||||
|
||||
$timesheet3 = new Timesheet();
|
||||
$timesheet3
|
||||
->setDuration(1800)
|
||||
->setRate(111.11)
|
||||
->setUser($user1)
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
$timesheet3->setDuration(1800);
|
||||
$timesheet3->setRate(111.11);
|
||||
$timesheet3->setUser($user1);
|
||||
$timesheet3->setActivity($activity);
|
||||
$timesheet3->setProject($project);
|
||||
$timesheet3->setBegin(new \DateTime());
|
||||
$timesheet3->setEnd(new \DateTime());
|
||||
|
||||
$timesheet4 = new Timesheet();
|
||||
$timesheet4
|
||||
->setDuration(400)
|
||||
->setRate(1947.99)
|
||||
->setUser($user2)
|
||||
->setDescription('== jhg ljhg ') // make sure that spreadsheets don't render it as formula
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
->addTag((new Tag())->setName('foo'))
|
||||
;
|
||||
$timesheet4->setDuration(400);
|
||||
$timesheet4->setRate(1947.99);
|
||||
$timesheet4->setUser($user2);
|
||||
$timesheet4->setDescription('== jhg ljhg '); // make sure that spreadsheets don't render it as formula
|
||||
$timesheet4->setActivity($activity);
|
||||
$timesheet4->setProject($project);
|
||||
$timesheet4->setBegin(new \DateTime());
|
||||
$timesheet4->setEnd(new \DateTime());
|
||||
$timesheet4->addTag((new Tag())->setName('foo'));
|
||||
|
||||
$userKevin = new User();
|
||||
$userKevin->setAlias('Kevin');
|
||||
$userKevin->setUserIdentifier('kevin');
|
||||
|
||||
$timesheet5 = new Timesheet();
|
||||
$timesheet5
|
||||
->setDuration(400)
|
||||
->setFixedRate(84)
|
||||
->setUser($userKevin)
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime('2019-06-16 12:00:00'))
|
||||
->setEnd(new \DateTime('2019-06-16 12:06:40'))
|
||||
->addTag((new Tag())->setName('foo'))
|
||||
->addTag((new Tag())->setName('bar'))
|
||||
->setMetaField((new TimesheetMeta())->setName('foo')->setValue('meta-bar')->setIsVisible(true))
|
||||
->setMetaField((new TimesheetMeta())->setName('foo2')->setValue('meta-bar2')->setIsVisible(true))
|
||||
;
|
||||
$timesheet5->setDuration(400);
|
||||
$timesheet5->setFixedRate(84);
|
||||
$timesheet5->setUser($userKevin);
|
||||
$timesheet5->setActivity($activity);
|
||||
$timesheet5->setProject($project);
|
||||
$timesheet5->setBegin(new \DateTime('2019-06-16 12:00:00'));
|
||||
$timesheet5->setEnd(new \DateTime('2019-06-16 12:06:40'));
|
||||
$timesheet5->addTag((new Tag())->setName('foo'));
|
||||
$timesheet5->addTag((new Tag())->setName('bar'));
|
||||
$timesheet5->setMetaField((new TimesheetMeta())->setName('foo')->setValue('meta-bar')->setIsVisible(true));
|
||||
$timesheet5->setMetaField((new TimesheetMeta())->setName('foo2')->setValue('meta-bar2')->setIsVisible(true));
|
||||
|
||||
$userNivek = new User();
|
||||
$userNivek->setAlias('niveK');
|
||||
$userNivek->setUserIdentifier('nivek');
|
||||
|
||||
$timesheet6 = new Timesheet();
|
||||
$timesheet6
|
||||
->setDuration(400)
|
||||
->setFixedRate(-100.92)
|
||||
->setUser($userNivek)
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime('2019-06-16 12:00:00'))
|
||||
->setEnd(new \DateTime('2019-06-16 12:06:40'))
|
||||
;
|
||||
$timesheet6->setDuration(400);
|
||||
$timesheet6->setFixedRate(-100.92);
|
||||
$timesheet6->setUser($userNivek);
|
||||
$timesheet6->setActivity($activity);
|
||||
$timesheet6->setProject($project);
|
||||
$timesheet6->setBegin(new \DateTime('2019-06-16 12:00:00'));
|
||||
$timesheet6->setEnd(new \DateTime('2019-06-16 12:06:40'));
|
||||
|
||||
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5, $timesheet6];
|
||||
|
||||
|
||||
@@ -65,67 +65,57 @@ abstract class AbstractRendererTestCase extends KernelTestCase
|
||||
$user2->method('getUserIdentifier')->willReturn('hello-world');
|
||||
|
||||
$timesheet = new Timesheet();
|
||||
$timesheet
|
||||
->setDuration(3600)
|
||||
->setRate(293.27)
|
||||
->setUser($user1)
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
$timesheet->setDuration(3600);
|
||||
$timesheet->setRate(293.27);
|
||||
$timesheet->setUser($user1);
|
||||
$timesheet->setActivity($activity);
|
||||
$timesheet->setProject($project);
|
||||
$timesheet->setBegin(new \DateTime());
|
||||
$timesheet->setEnd(new \DateTime());
|
||||
|
||||
$timesheet2 = new Timesheet();
|
||||
$timesheet2
|
||||
->setDuration(400)
|
||||
->setRate(84.75)
|
||||
->setUser($user2)
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
$timesheet2->setDuration(400);
|
||||
$timesheet2->setRate(84.75);
|
||||
$timesheet2->setUser($user2);
|
||||
$timesheet2->setActivity($activity);
|
||||
$timesheet2->setProject($project);
|
||||
$timesheet2->setBegin(new \DateTime());
|
||||
$timesheet2->setEnd(new \DateTime());
|
||||
|
||||
$timesheet3 = new Timesheet();
|
||||
$timesheet3
|
||||
->setDuration(1800)
|
||||
->setRate(111.11)
|
||||
->setUser($user1)
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
$timesheet3->setDuration(1800);
|
||||
$timesheet3->setRate(111.11);
|
||||
$timesheet3->setUser($user1);
|
||||
$timesheet3->setActivity($activity);
|
||||
$timesheet3->setProject($project);
|
||||
$timesheet3->setBegin(new \DateTime());
|
||||
$timesheet3->setEnd(new \DateTime());
|
||||
|
||||
$timesheet4 = new Timesheet();
|
||||
$timesheet4
|
||||
->setDuration(400)
|
||||
->setRate(1947.99)
|
||||
->setUser($user2)
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
->addTag((new Tag())->setName('foo'))
|
||||
;
|
||||
$timesheet4->setDuration(400);
|
||||
$timesheet4->setRate(1947.99);
|
||||
$timesheet4->setUser($user2);
|
||||
$timesheet4->setActivity($activity);
|
||||
$timesheet4->setProject($project);
|
||||
$timesheet4->setBegin(new \DateTime());
|
||||
$timesheet4->setEnd(new \DateTime());
|
||||
$timesheet4->addTag((new Tag())->setName('foo'));
|
||||
|
||||
$user = new User();
|
||||
$user->setUserIdentifier('kevin');
|
||||
|
||||
$timesheet5 = new Timesheet();
|
||||
$timesheet5
|
||||
->setDuration(400)
|
||||
->setFixedRate(84)
|
||||
->setUser($user)
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime('2019-06-16 12:00:00'))
|
||||
->setEnd(new \DateTime('2019-06-16 12:06:40'))
|
||||
->addTag((new Tag())->setName('foo'))
|
||||
->addTag((new Tag())->setName('bar'))
|
||||
->setMetaField((new TimesheetMeta())->setName('foo')->setValue('meta-bar')->setIsVisible(true))
|
||||
->setMetaField((new TimesheetMeta())->setName('foo2')->setValue('meta-bar2')->setIsVisible(true))
|
||||
;
|
||||
$timesheet5->setDuration(400);
|
||||
$timesheet5->setFixedRate(84);
|
||||
$timesheet5->setUser($user);
|
||||
$timesheet5->setActivity($activity);
|
||||
$timesheet5->setProject($project);
|
||||
$timesheet5->setBegin(new \DateTime('2019-06-16 12:00:00'));
|
||||
$timesheet5->setEnd(new \DateTime('2019-06-16 12:06:40'));
|
||||
$timesheet5->addTag((new Tag())->setName('foo'));
|
||||
$timesheet5->addTag((new Tag())->setName('bar'));
|
||||
$timesheet5->setMetaField((new TimesheetMeta())->setName('foo')->setValue('meta-bar')->setIsVisible(true));
|
||||
$timesheet5->setMetaField((new TimesheetMeta())->setName('foo2')->setValue('meta-bar2')->setIsVisible(true));
|
||||
|
||||
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user