fixed multilineIndent (#1669)
This commit is contained in:
@@ -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));
|
||||
|
||||
$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->setLanguage('en');
|
||||
|
||||
@@ -192,6 +192,14 @@ trait RendererTestTrait
|
||||
->setProject($project)
|
||||
->setBegin(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))
|
||||
;
|
||||
|
||||
@@ -204,6 +212,14 @@ trait RendererTestTrait
|
||||
->setProject($project)
|
||||
->setBegin(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];
|
||||
|
||||
@@ -85,5 +85,15 @@ class TextRendererTest extends KernelTestCase
|
||||
}
|
||||
}
|
||||
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';
|
||||
$this->assertStringContainsString('<title>' . $filename . '</title>', $content);
|
||||
$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);
|
||||
$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}
|
||||
|
Reference in New Issue
Block a user