fixed multilineIndent (#1669)

This commit is contained in:
Kevin Papst
2020-04-28 17:13:02 +02:00
committed by GitHub
parent 46a7b13293
commit ad2698dae2
9 changed files with 57 additions and 154 deletions

View File

@@ -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()));
}
}

View File

@@ -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];

View File

@@ -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
);
}
}

View File

@@ -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);
}
}