fixed multilineIndent (#1669)
This commit is contained in:
@@ -8,6 +8,10 @@ you can upgrade your Kimai installation to the latest stable release.
|
|||||||
Check below if there are more version specific steps required, which need to be executed after the normal update process.
|
Check below if there are more version specific steps required, which need to be executed after the normal update process.
|
||||||
Perform EACH version specific task between your version and the new one, otherwise you risk data inconsistency or a broken installation.
|
Perform EACH version specific task between your version and the new one, otherwise you risk data inconsistency or a broken installation.
|
||||||
|
|
||||||
|
## [1.10](https://github.com/kevinpapst/kimai2/releases/tag/1.10)
|
||||||
|
|
||||||
|
- Invoice renderer `CSV` was removed
|
||||||
|
|
||||||
## [1.9](https://github.com/kevinpapst/kimai2/releases/tag/1.9)
|
## [1.9](https://github.com/kevinpapst/kimai2/releases/tag/1.9)
|
||||||
|
|
||||||
**New database tables and fields were created, don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
**New database tables and fields were created, don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
<?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\Invoice\Renderer;
|
|
||||||
|
|
||||||
use App\Invoice\RendererInterface;
|
|
||||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
||||||
|
|
||||||
final class CsvRenderer extends AbstractSpreadsheetRenderer implements RendererInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @return string[]
|
|
||||||
*/
|
|
||||||
protected function getFileExtensions()
|
|
||||||
{
|
|
||||||
return ['.csv'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function getContentType()
|
|
||||||
{
|
|
||||||
return 'text/csv';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Spreadsheet $spreadsheet
|
|
||||||
* @return string
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
protected function saveSpreadsheet(Spreadsheet $spreadsheet)
|
|
||||||
{
|
|
||||||
$filename = tempnam(sys_get_temp_dir(), 'kimai-invoice-csv');
|
|
||||||
if (false === $filename) {
|
|
||||||
throw new \Exception('Could not open temporary file');
|
|
||||||
}
|
|
||||||
|
|
||||||
$writer = IOFactory::createWriter($spreadsheet, 'Csv');
|
|
||||||
$writer->save($filename);
|
|
||||||
|
|
||||||
return $filename;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -105,16 +105,19 @@ class Extensions extends AbstractExtension
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$parts = explode("\r\n", $string);
|
$parts = [];
|
||||||
if (\count($parts) === 1) {
|
|
||||||
$parts = explode("\n", $string);
|
foreach (explode("\r\n", $string) as $part) {
|
||||||
|
foreach (explode("\n", $part) as $tmp) {
|
||||||
|
$parts[] = $tmp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$parts = array_map(function ($part) use ($indent) {
|
$parts = array_map(function ($part) use ($indent) {
|
||||||
return $indent . $part;
|
return $indent . $part;
|
||||||
}, $parts);
|
}, $parts);
|
||||||
|
|
||||||
return implode("\n", $parts);
|
return implode(PHP_EOL, $parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
<?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\Invoice\Renderer;
|
|
||||||
|
|
||||||
use App\Invoice\InvoiceModel;
|
|
||||||
use App\Invoice\Renderer\CsvRenderer;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \App\Invoice\Renderer\CsvRenderer
|
|
||||||
* @covers \App\Invoice\Renderer\AbstractRenderer
|
|
||||||
* @covers \App\Invoice\Renderer\AbstractSpreadsheetRenderer
|
|
||||||
* @covers \App\Invoice\Renderer\AdvancedValueBinder
|
|
||||||
* @group integration
|
|
||||||
*/
|
|
||||||
class CsvRendererTest extends TestCase
|
|
||||||
{
|
|
||||||
use RendererTestTrait;
|
|
||||||
|
|
||||||
public function testSupports()
|
|
||||||
{
|
|
||||||
$sut = $this->getAbstractRenderer(CsvRenderer::class);
|
|
||||||
|
|
||||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('default.html.twig')));
|
|
||||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('freelancer.html.twig')));
|
|
||||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('timesheet.html.twig')));
|
|
||||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('foo.html.twig')));
|
|
||||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx')));
|
|
||||||
$this->assertTrue($sut->supports($this->getInvoiceDocument('export.csv', true)));
|
|
||||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('spreadsheet.xlsx')));
|
|
||||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('open-spreadsheet.ods')));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTestModel()
|
|
||||||
{
|
|
||||||
yield [$this->getInvoiceModel(), '€1,947.99', 6, 4, 1, 2, 2];
|
|
||||||
yield [$this->getInvoiceModelOneEntry(), '$293.27', 2, 1, 0, 1, 0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider getTestModel
|
|
||||||
*/
|
|
||||||
public function testRender(InvoiceModel $model, $expectedRate, $expectedRows, $expectedDescriptions, $expectedUser1, $expectedUser2, $expectedUser3)
|
|
||||||
{
|
|
||||||
/** @var CsvRenderer $sut */
|
|
||||||
$sut = $this->getAbstractRenderer(CsvRenderer::class);
|
|
||||||
$document = $this->getInvoiceDocument('export.csv', true);
|
|
||||||
/** @var BinaryFileResponse $response */
|
|
||||||
$response = $sut->render($document, $model);
|
|
||||||
|
|
||||||
$file = $response->getFile();
|
|
||||||
$this->assertEquals('text/csv', $response->headers->get('Content-Type'));
|
|
||||||
$filename = $model->getInvoiceNumber() . '-customer_with_special_name.csv';
|
|
||||||
$this->assertEquals('attachment; filename=' . $filename, $response->headers->get('Content-Disposition'));
|
|
||||||
|
|
||||||
$this->assertTrue(file_exists($file->getRealPath()));
|
|
||||||
$content = file_get_contents($file->getRealPath());
|
|
||||||
|
|
||||||
$this->assertStringNotContainsString('${', $content);
|
|
||||||
$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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -113,7 +113,7 @@ trait RendererTestTrait
|
|||||||
$customer->setMetaField((new CustomerMeta())->setName('foo-customer')->setValue('bar-customer')->setIsVisible(true));
|
$customer->setMetaField((new CustomerMeta())->setName('foo-customer')->setValue('bar-customer')->setIsVisible(true));
|
||||||
|
|
||||||
$template = new InvoiceTemplate();
|
$template = new InvoiceTemplate();
|
||||||
$template->setTitle('a very *long* test invoice / template title with [special] character');
|
$template->setTitle('a very *long* test invoice / template title with [ßpecial] chäracter');
|
||||||
$template->setVat(19);
|
$template->setVat(19);
|
||||||
$template->setLanguage('en');
|
$template->setLanguage('en');
|
||||||
|
|
||||||
@@ -192,6 +192,14 @@ trait RendererTestTrait
|
|||||||
->setProject($project)
|
->setProject($project)
|
||||||
->setBegin(new \DateTime())
|
->setBegin(new \DateTime())
|
||||||
->setEnd(new \DateTime())
|
->setEnd(new \DateTime())
|
||||||
|
->setDescription(
|
||||||
|
"foo\n" .
|
||||||
|
"foo\r\n" .
|
||||||
|
'foo' . PHP_EOL .
|
||||||
|
"bar\n" .
|
||||||
|
"bar\r\n" .
|
||||||
|
'Hello'
|
||||||
|
)
|
||||||
->setMetaField((new TimesheetMeta())->setName('foo-timesheet3')->setValue('bluuuub')->setIsVisible(true))
|
->setMetaField((new TimesheetMeta())->setName('foo-timesheet3')->setValue('bluuuub')->setIsVisible(true))
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -204,6 +212,14 @@ trait RendererTestTrait
|
|||||||
->setProject($project)
|
->setProject($project)
|
||||||
->setBegin(new \DateTime())
|
->setBegin(new \DateTime())
|
||||||
->setEnd(new \DateTime())
|
->setEnd(new \DateTime())
|
||||||
|
->setDescription(
|
||||||
|
"foo\n" .
|
||||||
|
"foo\r\n" .
|
||||||
|
'foo' . PHP_EOL .
|
||||||
|
"bar\n" .
|
||||||
|
"bar\r\n" .
|
||||||
|
'Hello'
|
||||||
|
)
|
||||||
;
|
;
|
||||||
|
|
||||||
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5];
|
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5];
|
||||||
|
|||||||
@@ -85,5 +85,15 @@ class TextRendererTest extends KernelTestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
self::assertEquals(\count($model->getCalculator()->getEntries()), substr_count($content, PHP_EOL . '---' . PHP_EOL));
|
self::assertEquals(\count($model->getCalculator()->getEntries()), substr_count($content, PHP_EOL . '---' . PHP_EOL));
|
||||||
|
$this->assertStringContainsString(
|
||||||
|
'entry.description' . PHP_EOL .
|
||||||
|
' foo' . PHP_EOL .
|
||||||
|
' foo' . PHP_EOL .
|
||||||
|
' foo' . PHP_EOL .
|
||||||
|
' bar' . PHP_EOL .
|
||||||
|
' bar' . PHP_EOL .
|
||||||
|
' Hello',
|
||||||
|
$content
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,8 +65,14 @@ class TwigRendererTest extends KernelTestCase
|
|||||||
$filename = $model->getInvoiceNumber() . '-customer_with_special_name';
|
$filename = $model->getInvoiceNumber() . '-customer_with_special_name';
|
||||||
$this->assertStringContainsString('<title>' . $filename . '</title>', $content);
|
$this->assertStringContainsString('<title>' . $filename . '</title>', $content);
|
||||||
$this->assertStringContainsString('<h2 class="page-header">
|
$this->assertStringContainsString('<h2 class="page-header">
|
||||||
<span contenteditable="true">a very *long* test invoice / template title with [special] character</span>
|
<span contenteditable="true">a very *long* test invoice / template title with [ßpecial] chäracter</span>
|
||||||
</h2>', $content);
|
</h2>', $content);
|
||||||
$this->assertEquals(4, substr_count($content, 'activity description'));
|
$this->assertEquals(2, substr_count($content, 'activity description'));
|
||||||
|
$this->assertStringContainsString(nl2br("foo\n" .
|
||||||
|
"foo\r\n" .
|
||||||
|
'foo' . PHP_EOL .
|
||||||
|
"bar\n" .
|
||||||
|
"bar\r\n" .
|
||||||
|
'Hello'), $content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
start_date,start_timestamp,end_date,end_timestamp,duration,username,description,rate,amount,total
|
|
||||||
${entry.begin},${entry.begin_timestamp},${entry.end},${entry.end_timestamp},${entry.duration},${entry.user_name},${entry.description},${entry.rate},${entry.amount},${entry.total}
|
|
||||||
|
@@ -312,26 +312,25 @@ class ExtensionsTest extends TestCase
|
|||||||
[' ', null, ['']],
|
[' ', null, ['']],
|
||||||
[' ', '', ['']],
|
[' ', '', ['']],
|
||||||
[' ', 0, [' 0']],
|
[' ', 0, [' 0']],
|
||||||
[' ', 'sdfsdf
|
[' ', '1dfsdf
|
||||||
sdfsdf
|
sdfsdf' . PHP_EOL . "\n" .
|
||||||
|
' aksljdfh laksjd hflka sjhdf lakjhsdflak jsdfh' . "\n" .
|
||||||
aksljdfh laksjd hflka sjhdf lakjhsdflak jsdfh
|
'dfsdfsdfsdfsdf',
|
||||||
dfsdfsdfsdfsdf',
|
[' 1dfsdf', ' sdfsdf', ' ', ' aksljdfh laksjd hflka sjhdf lakjhsdflak jsdfh', ' dfsdfsdfsdfsdf']
|
||||||
[' sdfsdf', ' sdfsdf', ' ', ' aksljdfh laksjd hflka sjhdf lakjhsdflak jsdfh', ' dfsdfsdfsdfsdf']
|
|
||||||
],
|
],
|
||||||
['###', 'sdfsdf' . PHP_EOL .
|
['###', '2dfsdf' . PHP_EOL .
|
||||||
'sdfsdf' . PHP_EOL .
|
'sdfsdf' . PHP_EOL .
|
||||||
'' . PHP_EOL .
|
'' . "\r\n" .
|
||||||
' aksljdfh laksjd hflka sjhdf lakjhsdflak jsdfh' . PHP_EOL .
|
' aksljdfh laksjd hflka sjhdf lakjhsdflak jsdfh' . PHP_EOL .
|
||||||
'dfsdfsdfsdfsdf',
|
'dfsdfsdfsdfsdf',
|
||||||
['###sdfsdf', '###sdfsdf', '###', '### aksljdfh laksjd hflka sjhdf lakjhsdflak jsdfh', '###dfsdfsdfsdfsdf']
|
['###2dfsdf', '###sdfsdf', '###', '### aksljdfh laksjd hflka sjhdf lakjhsdflak jsdfh', '###dfsdfsdfsdfsdf']
|
||||||
],
|
],
|
||||||
[' ', 'sdfsdf' . "\r\n" .
|
[' ', '3dfsdf' . "\n" .
|
||||||
'sdfsdf' . "\r\n" .
|
'sdfsdf' . "\r\n" .
|
||||||
'' . "\r\n" .
|
'' . "\n" .
|
||||||
' aksljdfh laksjd hflka sjhdf lakjhsdflak jsdfh' . "\r\n" .
|
' aksljdfh laksjd hflka sjhdf lakjhsdflak jsdfh' . "\r\n" .
|
||||||
'dfsdfsdfsdfsdf',
|
'dfsdfsdfsdfsdf',
|
||||||
[' sdfsdf', ' sdfsdf', ' ', ' aksljdfh laksjd hflka sjhdf lakjhsdflak jsdfh', ' dfsdfsdfsdfsdf']
|
[' 3dfsdf', ' sdfsdf', ' ', ' aksljdfh laksjd hflka sjhdf lakjhsdflak jsdfh', ' dfsdfsdfsdfsdf']
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user