mirror of
https://github.com/kevinpapst/kimai2.git
synced 2025-04-30 15:30:11 +00:00

* fix missing locales * bump composer packages * changed translations * assert timezone on customer * include user accountNumber in excel export * improve next customer number calculation * fix z-index of contextmenu / action dropdown
148 lines
4.2 KiB
PHP
148 lines
4.2 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\Export\Renderer;
|
|
|
|
use App\Export\Renderer\CsvRenderer;
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
|
|
/**
|
|
* @covers \App\Export\Base\CsvRenderer
|
|
* @covers \App\Export\Base\AbstractSpreadsheetRenderer
|
|
* @covers \App\Export\Base\RendererTrait
|
|
* @covers \App\Export\Renderer\CsvRenderer
|
|
* @group integration
|
|
*/
|
|
class CsvRendererTest extends AbstractRendererTest
|
|
{
|
|
public function testConfiguration(): void
|
|
{
|
|
$sut = $this->getAbstractRenderer(CsvRenderer::class);
|
|
|
|
$this->assertEquals('csv', $sut->getId());
|
|
$this->assertEquals('csv', $sut->getTitle());
|
|
$this->assertEquals('csv', $sut->getIcon());
|
|
}
|
|
|
|
public function getTestModel()
|
|
{
|
|
return [
|
|
['400', '2437.12', ' EUR 1,947.99 ', 7, 6, 1, 2, 2]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider getTestModel
|
|
*/
|
|
public function testRender($totalDuration, $totalRate, $expectedRate, $expectedRows, $expectedDescriptions, $expectedUser1, $expectedUser2, $expectedUser3): void
|
|
{
|
|
$sut = $this->getAbstractRenderer(CsvRenderer::class);
|
|
|
|
/** @var BinaryFileResponse $response */
|
|
$response = $this->render($sut);
|
|
|
|
$file = $response->getFile();
|
|
$prefix = date('Ymd');
|
|
$this->assertEquals('text/csv', $response->headers->get('Content-Type'));
|
|
$this->assertEquals('attachment; filename=' . $prefix . '-Customer_Name-project_name.csv', $response->headers->get('Content-Disposition'));
|
|
|
|
$this->assertTrue(file_exists($file->getRealPath()));
|
|
$content = file_get_contents($file->getRealPath());
|
|
|
|
$this->assertStringContainsString('"' . $expectedRate . '"', $content);
|
|
$this->assertEquals($expectedRows, substr_count($content, PHP_EOL));
|
|
$this->assertEquals($expectedDescriptions, substr_count($content, 'activity description'));
|
|
$this->assertEquals($expectedUser1, substr_count($content, ',"kevin",'));
|
|
$this->assertEquals($expectedUser3, substr_count($content, ',"hello-world",'));
|
|
$this->assertEquals($expectedUser2, substr_count($content, ',"foo-bar",'));
|
|
|
|
ob_start();
|
|
$response->sendContent();
|
|
$content2 = ob_get_clean();
|
|
|
|
$this->assertEquals($content, $content2);
|
|
$this->assertFalse(file_exists($file->getRealPath()));
|
|
|
|
$all = [];
|
|
$rows = str_getcsv($content2, PHP_EOL);
|
|
foreach ($rows as $row) {
|
|
$all[] = str_getcsv($row);
|
|
}
|
|
|
|
$expected = [
|
|
'2019-06-16',
|
|
'12:00',
|
|
'12:06',
|
|
'400',
|
|
'0',
|
|
'',
|
|
'kevin',
|
|
'kevin',
|
|
'',
|
|
'Customer Name',
|
|
'project name',
|
|
'activity description',
|
|
'',
|
|
'',
|
|
'',
|
|
'foo,bar',
|
|
'',
|
|
' EUR 84.00 ',
|
|
'meta-bar',
|
|
'meta-bar2',
|
|
'customer-bar',
|
|
'',
|
|
'project-foo2',
|
|
'activity-bar',
|
|
'timesheet',
|
|
'work',
|
|
'A-0123456789',
|
|
'DE-9876543210',
|
|
'ORDER-123',
|
|
];
|
|
|
|
$expected2 = [
|
|
'2019-06-16',
|
|
'12:00',
|
|
'12:06',
|
|
'400',
|
|
'0',
|
|
'',
|
|
'nivek',
|
|
'nivek',
|
|
'',
|
|
'Customer Name',
|
|
'project name',
|
|
'activity description',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
' EUR -100.92',
|
|
'',
|
|
'',
|
|
'customer-bar',
|
|
'',
|
|
'project-foo2',
|
|
'activity-bar',
|
|
'timesheet',
|
|
'work',
|
|
'A-0123456789',
|
|
'DE-9876543210',
|
|
'ORDER-123',
|
|
];
|
|
|
|
self::assertEquals(7, \count($all));
|
|
self::assertEquals($expected, $all[5]);
|
|
self::assertEquals($expected2, $all[6]);
|
|
self::assertEquals(\count($expected), \count($all[0]));
|
|
self::assertEquals('foo', $all[4][15]);
|
|
}
|
|
}
|