Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)

This commit is contained in:
Kevin Papst
2022-12-31 21:19:55 +01:00
committed by GitHub
parent 95e06746bd
commit 90a0fd8a22
2164 changed files with 83700 additions and 86426 deletions

View File

@@ -40,7 +40,7 @@ abstract class AbstractCalculatorTest extends TestCase
protected function getEmptyModel()
{
$customer = new Customer();
$customer = new Customer('foo');
$template = new InvoiceTemplate();
$query = new InvoiceQuery();
@@ -54,7 +54,7 @@ abstract class AbstractCalculatorTest extends TestCase
protected function assertDescription(CalculatorInterface $sut, $addProject = false, $addActivity = false)
{
$customer = new Customer();
$customer = new Customer('foo');
$template = new InvoiceTemplate();
$template->setVat(19);

View File

@@ -35,7 +35,7 @@ class ActivityInvoiceCalculatorTest extends AbstractCalculatorTest
public function testWithMultipleEntries()
{
$customer = new Customer();
$customer = new Customer('foo');
$template = new InvoiceTemplate();
$template->setVat(19);
@@ -132,7 +132,7 @@ class ActivityInvoiceCalculatorTest extends AbstractCalculatorTest
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5, $timesheet6, $timesheet7, $timesheet8];
$query = new InvoiceQuery();
$query->setActivity($activity1);
$query->addActivity($activity1);
$model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);

View File

@@ -36,7 +36,7 @@ class DateInvoiceCalculatorTest extends AbstractCalculatorTest
public function testWithMultipleEntries()
{
$customer = new Customer();
$customer = new Customer('foo');
$template = new InvoiceTemplate();
$template->setVat(19);

View File

@@ -33,7 +33,7 @@ class DefaultCalculatorTest extends AbstractCalculatorTest
public function testWithMultipleEntries()
{
$date = new \DateTime();
$customer = new Customer();
$customer = new Customer('foo');
$template = new InvoiceTemplate();
$template->setVat(19);

View File

@@ -37,7 +37,7 @@ class PriceInvoiceCalculatorTest extends AbstractCalculatorTest
public function testWithMultipleEntries()
{
$customer = new Customer();
$customer = new Customer('foo');
$template = new InvoiceTemplate();
$template->setVat(19);

View File

@@ -36,7 +36,7 @@ class ProjectInvoiceCalculatorTest extends AbstractCalculatorTest
public function testWithMultipleEntries()
{
$customer = new Customer();
$customer = new Customer('foo');
$template = new InvoiceTemplate();
$template->setVat(19);

View File

@@ -36,7 +36,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
public function testWithMultipleEntries()
{
$customer = new Customer();
$customer = new Customer('foo');
$template = new InvoiceTemplate();
$template->setVat(19);
@@ -89,7 +89,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$entries = [$timesheet, $timesheet2, $timesheet3];
$query = new InvoiceQuery();
$query->setActivity($activity);
$query->addActivity($activity);
$model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);
@@ -121,7 +121,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
public function testWithMultipleEntriesDifferentRates()
{
$customer = new Customer();
$customer = new Customer('foo');
$template = new InvoiceTemplate();
$template->setVat(19);
@@ -171,7 +171,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$entries = [$timesheet, $timesheet2, $timesheet3];
$query = new InvoiceQuery();
$query->setActivity($activity);
$query->addActivity($activity);
$model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);
@@ -202,7 +202,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
public function testWithMixedRateTypes()
{
$customer = new Customer();
$customer = new Customer('foo');
$template = new InvoiceTemplate();
$template->setVat(19);
@@ -250,7 +250,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$entries = [$timesheet, $timesheet2, $timesheet3];
$query = new InvoiceQuery();
$query->setActivity($activity);
$query->addActivity($activity);
$model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);

View File

@@ -34,7 +34,7 @@ class UserInvoiceCalculatorTest extends AbstractCalculatorTest
public function testWithMultipleEntries()
{
$customer = new Customer();
$customer = new Customer('foo');
$template = new InvoiceTemplate();
$template->setVat(19);
@@ -103,7 +103,7 @@ class UserInvoiceCalculatorTest extends AbstractCalculatorTest
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5];
$query = new InvoiceQuery();
$query->setActivity($activity);
$query->addActivity($activity);
$model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);

View File

@@ -36,7 +36,7 @@ class WeeklyInvoiceCalculatorTest extends AbstractCalculatorTest
public function testWithMultipleEntries()
{
$customer = new Customer();
$customer = new Customer('foo');
$template = new InvoiceTemplate();
$template->setVat(19);

View File

@@ -32,7 +32,7 @@ class InvoiceItemDefaultHydratorTest extends TestCase
$this->assertEntryStructure($result, $metaFields);
$result = $sut->hydrate($model->getCalculator()->getEntries()[1]);
$metaFields = ['entry.meta.foo-timesheet2'];
$metaFields = ['entry.meta.foo-timesheet', 'entry.meta.foo-timesheet2'];
$this->assertEntryStructure($result, $metaFields);
}

View File

@@ -29,10 +29,6 @@ class InvoiceModelActivityHydratorTest extends TestCase
$result = $sut->hydrate($model);
$this->assertModelStructure($result);
$model->getQuery()->setActivities([]);
$result = $sut->hydrate($model);
self::assertEmpty($result);
}
protected function assertModelStructure(array $model)

View File

@@ -57,6 +57,7 @@ class InvoiceModelCustomerHydratorTest extends TestCase
'customer.budget_open_plain',
'customer.time_budget_open',
'customer.time_budget_open_plain',
'customer.invoice_text',
];
$givenKeys = array_keys($model);

View File

@@ -62,16 +62,16 @@ class InvoiceModelDefaultHydratorTest extends TestCase
'template.vat_id',
'template.contact',
'template.payment_details',
'query.begin',
'query.end',
'query.day',
'query.month',
'query.month_number',
'query.year',
'query.begin',
'query.begin_day',
'query.begin_month',
'query.begin_month_number',
'query.begin_year',
'query.end',
'query.end_day',
'query.end_month',
'query.end_month_number',

View File

@@ -29,10 +29,6 @@ class InvoiceModelProjectHydratorTest extends TestCase
$result = $sut->hydrate($model);
$this->assertModelStructure($result);
$model->getQuery()->setProjects([]);
$result = $sut->hydrate($model);
self::assertEmpty($result);
}
protected function assertModelStructure(array $model)

View File

@@ -14,6 +14,7 @@ use App\Entity\InvoiceTemplate;
use App\Entity\Project;
use App\Invoice\InvoiceFilename;
use App\Invoice\NumberGenerator\DateNumberGenerator;
use App\Invoice\NumberGeneratorInterface;
use App\Repository\InvoiceRepository;
use App\Repository\Query\InvoiceQuery;
use App\Tests\Mocks\InvoiceModelFactoryFactory;
@@ -24,9 +25,9 @@ use PHPUnit\Framework\TestCase;
*/
class InvoiceFilenameTest extends TestCase
{
public function testInvoiceFilename()
public function testInvoiceFilename(): void
{
$customer = new Customer();
$customer = new Customer('foo');
$template = new InvoiceTemplate();
$model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
@@ -38,12 +39,6 @@ class InvoiceFilenameTest extends TestCase
$sut = new InvoiceFilename($model);
self::assertEquals($datePrefix, $sut->getFilename());
self::assertEquals($datePrefix, (string) $sut);
$customer->setName('foo');
$sut = new InvoiceFilename($model);
self::assertEquals($datePrefix . '-foo', $sut->getFilename());
self::assertEquals($datePrefix . '-foo', (string) $sut);
@@ -73,7 +68,7 @@ class InvoiceFilenameTest extends TestCase
self::assertEquals($datePrefix . '-ss_n_--Demo_ProjecT1', $sut->getFilename());
}
private function getNumberGeneratorSut()
private function getNumberGeneratorSut(): NumberGeneratorInterface
{
$repository = $this->createMock(InvoiceRepository::class);
$repository

View File

@@ -31,13 +31,10 @@ class InvoiceItemTest extends TestCase
self::assertIsArray($sut->getAdditionalFields());
self::assertEmpty($sut->getAdditionalFields());
self::assertNull($sut->getAdditionalField('foo'));
self::assertNull($sut->getMetaFieldValue('foo'));
self::assertEquals('bar', $sut->getAdditionalField('foo', 'bar'));
self::assertNull($sut->getAdditionalField('foo'));
self::assertNull($sut->getMetaFieldValue('foo'));
self::assertInstanceOf(InvoiceItem::class, $sut->addAdditionalField('foo', 'bar2'));
self::assertEquals('bar2', $sut->getAdditionalField('foo'));
self::assertEquals('bar2', $sut->getMetaFieldValue('foo'));
self::assertEquals(0, $sut->getAmount());
self::assertNull($sut->getBegin());
self::assertNull($sut->getActivity());

View File

@@ -11,7 +11,6 @@ namespace App\Tests\Invoice;
use App\Entity\Customer;
use App\Entity\InvoiceTemplate;
use App\Entity\Timesheet;
use App\Invoice\Calculator\DefaultCalculator;
use App\Invoice\InvoiceModel;
use App\Repository\Query\InvoiceQuery;
@@ -33,7 +32,6 @@ class InvoiceModelTest extends TestCase
self::assertNull($sut->getCustomer());
self::assertNull($sut->getDueDate());
self::assertNull($sut->getCalculator());
self::assertNull($sut->getNumberGenerator());
self::assertEmpty($sut->getEntries());
self::assertIsArray($sut->getEntries());
@@ -67,7 +65,7 @@ class InvoiceModelTest extends TestCase
self::assertInstanceOf(InvoiceModel::class, $sut->setQuery($query));
self::assertSame($query, $sut->getQuery());
$customer = new Customer();
$customer = new Customer('foo');
self::assertInstanceOf(InvoiceModel::class, $sut->setCustomer($customer));
self::assertSame($customer, $sut->getCustomer());
@@ -77,11 +75,7 @@ class InvoiceModelTest extends TestCase
$generator = new IncrementingNumberGenerator();
self::assertInstanceOf(InvoiceModel::class, $sut->setNumberGenerator($generator));
self::assertSame($generator, $sut->getNumberGenerator());
$number = $sut->getInvoiceNumber();
$first = $sut->getNumberGenerator()->getInvoiceNumber();
$second = $sut->getNumberGenerator()->getInvoiceNumber();
self::assertEquals(((int) $first + 1), $second);
self::assertEquals($number, $sut->getInvoiceNumber());
$template = new InvoiceTemplate();
@@ -91,16 +85,4 @@ class InvoiceModelTest extends TestCase
/* @phpstan-ignore-next-line */
self::assertInstanceOf(\DateTime::class, $sut->getDueDate());
}
/**
* @group legacy
*/
public function testDeprecations()
{
$sut = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$entries = [new Timesheet()];
self::assertInstanceOf(InvoiceModel::class, $sut->setEntries($entries));
self::assertSame($entries, $sut->getEntries());
}
}

View File

@@ -9,26 +9,24 @@
namespace App\Tests\Invoice\NumberGenerator;
use App\Configuration\SystemConfiguration;
use App\Entity\Customer;
use App\Entity\User;
use App\Invoice\NumberGenerator\ConfigurableNumberGenerator;
use App\Repository\InvoiceRepository;
use App\Tests\Invoice\DebugFormatter;
use App\Tests\Mocks\InvoiceModelFactoryFactory;
use App\Tests\Mocks\SystemConfigurationFactory;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Invoice\NumberGenerator\ConfigurableNumberGenerator
* @covers \App\Utils\NumberGenerator
*/
class ConfigurableNumberGeneratorTest extends TestCase
{
private function getSut(string $format, int $counter = 1)
{
$config = $this->createMock(SystemConfiguration::class);
$config->expects($this->any())
->method('find')
->willReturn($format);
$config = SystemConfigurationFactory::createStub(['invoice' => ['number_format' => $format]]);
$repository = $this->createMock(InvoiceRepository::class);
$repository
@@ -147,8 +145,7 @@ class ConfigurableNumberGeneratorTest extends TestCase
*/
public function testGetInvoiceNumber(string $format, string $expectedInvoiceNumber, \DateTime $invoiceDate, int $counter = 1)
{
$customer = new Customer();
$customer->setName('Acme company');
$customer = new Customer('Acme company');
$customer->setNumber('0815');
$user = $this->createMock(User::class);
@@ -199,7 +196,7 @@ class ConfigurableNumberGeneratorTest extends TestCase
$sut = $this->getSut($format);
$model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setInvoiceDate($invoiceDate);
$model->setCustomer(new Customer());
$model->setCustomer(new Customer('foo'));
$sut->setModel($model);
$sut->getInvoiceNumber();

View File

@@ -16,16 +16,10 @@ class IncrementingNumberGenerator implements NumberGeneratorInterface
{
private $counter = 0;
/**
* @param InvoiceModel $model
*/
public function setModel(InvoiceModel $model)
public function setModel(InvoiceModel $model): void
{
}
/**
* @return string
*/
public function getInvoiceNumber(): string
{
return $this->counter++;

View File

@@ -9,10 +9,10 @@
namespace App\Tests\Invoice\Renderer;
use App\Entity\InvoiceDocument;
use App\Invoice\InvoiceModel;
use App\Invoice\Renderer\AbstractRenderer;
use App\Invoice\RendererInterface;
use App\Model\InvoiceDocument;
use Symfony\Component\HttpFoundation\Response;
class DebugRenderer extends AbstractRenderer implements RendererInterface

View File

@@ -9,11 +9,11 @@
namespace App\Tests\Invoice\Renderer;
use App\Entity\InvoiceDocument;
use App\Invoice\InvoiceItem;
use App\Invoice\InvoiceItemHydrator;
use App\Invoice\InvoiceModel;
use App\Invoice\InvoiceModelHydrator;
use App\Model\InvoiceDocument;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response;
@@ -23,7 +23,7 @@ class DebugRendererTest extends TestCase
public function getTestModel()
{
yield [$this->getInvoiceModel(), '1,947.99', 5, 5, 1, 2, 2, true, [['entry.meta.foo-timesheet'], ['entry.meta.foo-timesheet2'], ['entry.meta.foo-timesheet'], ['entry.meta.foo-timesheet3']]];
yield [$this->getInvoiceModel(), '1,947.99', 5, 5, 1, 2, 2, true, [['entry.meta.foo-timesheet'], ['entry.meta.foo-timesheet', 'entry.meta.foo-timesheet2'], ['entry.meta.foo-timesheet'], ['entry.meta.foo-timesheet3']]];
yield [$this->getInvoiceModelOneEntry(), '293.27', 1, 1, 0, 1, 0, false, []];
}
@@ -69,11 +69,10 @@ class DebugRendererTest extends TestCase
}
$begin = $model->getQuery()->getBegin();
self::assertEquals($begin->format('m'), $data['model']['query.month_number']);
self::assertEquals($begin->format('d'), $data['model']['query.day']);
// TODO check values or formats?
self::assertEquals('2020.08.12', $data['model']['invoice.first']);
self::assertEquals('2021.03.12', $data['model']['invoice.last']);
self::assertEquals($begin->format('m'), $data['model']['query.begin_month_number']);
self::assertEquals($begin->format('d'), $data['model']['query.begin_day']);
self::assertEquals('20.08.12', $data['model']['invoice.first']);
self::assertEquals('21.03.12', $data['model']['invoice.last']);
}
protected function assertModelStructure(array $model, int $projectCounter = 0, int $activityCounter = 0)
@@ -108,16 +107,16 @@ class DebugRendererTest extends TestCase
'template.vat_id',
'template.contact',
'template.payment_details',
'query.begin',
'query.day',
'query.end',
'query.month',
'query.month_number',
'query.year',
'query.begin',
'query.begin_day',
'query.begin_month',
'query.begin_month_number',
'query.begin_year',
'query.end',
'query.end_day',
'query.end_month',
'query.end_month_number',
@@ -141,6 +140,7 @@ class DebugRendererTest extends TestCase
'customer.time_budget_open_plain',
'customer.mobile',
'customer.meta.foo-customer',
'customer.invoice_text',
'activity.id',
'activity.name',
'activity.comment',
@@ -158,12 +158,6 @@ class DebugRendererTest extends TestCase
'testFromModelHydrator',
];
if ($activityCounter === 1) {
$keys = array_merge($keys, [
'activity',
]);
}
if ($activityCounter > 1) {
$keys = array_merge($keys, [
'activity.1.budget_open',
@@ -198,11 +192,7 @@ class DebugRendererTest extends TestCase
'project.time_budget_open',
'project.time_budget_open_plain',
]);
if ($projectCounter === 1) {
$keys = array_merge($keys, [
'project',
]);
}
if ($projectCounter > 1) {
$keys = array_merge($keys, [
'project.1.id',

View File

@@ -26,10 +26,10 @@ class DocxRendererTest extends TestCase
{
$sut = $this->getAbstractRenderer(DocxRenderer::class);
$this->assertFalse($sut->supports($this->getInvoiceDocument('default.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('freelancer.pdf.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('invoice.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('service-date.pdf.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('timesheet.html.twig')));
$this->assertTrue($sut->supports($this->getInvoiceDocument('company.docx')));
$this->assertTrue($sut->supports($this->getInvoiceDocument('company.docx', true)));
$this->assertFalse($sut->supports($this->getInvoiceDocument('spreadsheet.xlsx', true)));
$this->assertFalse($sut->supports($this->getInvoiceDocument('open-spreadsheet.ods', true)));
}
@@ -39,7 +39,7 @@ class DocxRendererTest extends TestCase
/** @var DocxRenderer $sut */
$sut = $this->getAbstractRenderer(DocxRenderer::class);
$model = $this->getInvoiceModel();
$document = $this->getInvoiceDocument('company.docx');
$document = $this->getInvoiceDocument('company.docx', true);
/** @var BinaryFileResponse $response */
$response = $sut->render($document, $model);
@@ -50,18 +50,6 @@ class DocxRendererTest extends TestCase
$this->assertTrue(file_exists($file->getRealPath()));
// TODO test document content?
/*
$content = file_get_contents($file->getRealPath());
$this->assertNotContains('${', $content);
$this->assertStringContainsString(',"1,947.99" ', $content);
$this->assertEquals(6, substr_count($content, PHP_EOL));
$this->assertEquals(5, substr_count($content, 'activity description'));
$this->assertEquals(1, substr_count($content, ',"kevin",'));
$this->assertEquals(2, substr_count($content, ',"hello-world",'));
$this->assertEquals(2, substr_count($content, ',"foo-bar",'));
*/
ob_start();
$response->sendContent();
$content2 = ob_get_clean();

View File

@@ -1,75 +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\Renderer\JsonRenderer;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
/**
* @covers \App\Invoice\Renderer\AbstractTwigRenderer
* @covers \App\Invoice\Renderer\JsonRenderer
* @group integration
*/
class JsonRendererTest extends KernelTestCase
{
use RendererTestTrait;
public function testSupports()
{
$loader = new FilesystemLoader();
$env = new Environment($loader);
$sut = new JsonRenderer($env);
$this->assertFalse($sut->supports($this->getInvoiceDocument('default.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('timesheet.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('spreadsheet.xlsx', true)));
$this->assertFalse($sut->supports($this->getInvoiceDocument('open-spreadsheet.ods', true)));
$this->assertFalse($sut->supports($this->getInvoiceDocument('text.txt.twig')));
$this->assertTrue($sut->supports($this->getInvoiceDocument('javascript.json.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('xml.xml.twig')));
}
public function testRender()
{
$kernel = self::bootKernel();
/** @var Environment $twig */
$twig = $kernel->getContainer()->get('twig');
$stack = $kernel->getContainer()->get('request_stack');
$request = new Request();
$request->setLocale('en');
$stack->push($request);
/** @var FilesystemLoader $loader */
$loader = $twig->getLoader();
$loader->addPath($this->getInvoiceTemplatePath(), 'invoice');
$sut = new JsonRenderer($twig);
$model = $this->getInvoiceModel();
$document = $this->getInvoiceDocument('javascript.json.twig');
$response = $sut->render($document, $model);
self::assertEquals('application/json', $response->headers->get('Content-Type'));
$content = $response->getContent();
$json = json_decode($content, true);
$expected = $model->toArray();
$expected['items'] = [];
foreach ($model->getCalculator()->getEntries() as $entry) {
$expected['items'][] = $model->itemToArray($entry);
}
self::assertEquals($expected, $json);
}
}

View File

@@ -28,10 +28,10 @@ class OdsRendererTest extends TestCase
{
$sut = $this->getAbstractRenderer(OdsRenderer::class);
$this->assertFalse($sut->supports($this->getInvoiceDocument('default.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('freelancer.pdf.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('invoice.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('service-date.pdf.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('timesheet.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx', true)));
$this->assertFalse($sut->supports($this->getInvoiceDocument('spreadsheet.xlsx', true)));
$this->assertTrue($sut->supports($this->getInvoiceDocument('open-spreadsheet.ods', true)));
}

View File

@@ -10,11 +10,11 @@
namespace App\Tests\Invoice\Renderer;
use App\Invoice\Renderer\PdfRenderer;
use App\Pdf\HtmlToPdfConverter;
use App\Pdf\MPdfConverter;
use App\Tests\Mocks\FileHelperFactory;
use App\Utils\MPdfConverter;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Twig\Environment;
use Twig\Loader\ArrayLoader;
use Twig\Loader\FilesystemLoader;
@@ -28,27 +28,14 @@ class PdfRendererTest extends KernelTestCase
{
use RendererTestTrait;
public function testDisposition()
{
$env = new Environment(new ArrayLoader([]));
$sut = new PdfRenderer($env, $this->createMock(MPdfConverter::class));
$this->assertEquals(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $sut->getDisposition());
$sut->setDispositionInline(false);
$this->assertEquals(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $sut->getDisposition());
$sut->setDispositionInline(true);
$this->assertEquals(ResponseHeaderBag::DISPOSITION_INLINE, $sut->getDisposition());
$sut->setDispositionInline(false);
$this->assertEquals(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $sut->getDisposition());
}
public function testSupports()
{
$env = new Environment(new ArrayLoader([]));
$sut = new PdfRenderer($env, $this->createMock(MPdfConverter::class));
$sut = new PdfRenderer($env, $this->createMock(HtmlToPdfConverter::class));
$this->assertTrue($sut->supports($this->getInvoiceDocument('default.pdf.twig', true)));
$this->assertTrue($sut->supports($this->getInvoiceDocument('freelancer.pdf.twig')));
$this->assertTrue($sut->supports($this->getInvoiceDocument('service-date.pdf.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('timesheet.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx', true)));
$this->assertFalse($sut->supports($this->getInvoiceDocument('spreadsheet.xlsx', true)));
$this->assertFalse($sut->supports($this->getInvoiceDocument('open-spreadsheet.ods', true)));
}
@@ -57,8 +44,8 @@ class PdfRendererTest extends KernelTestCase
{
$kernel = self::bootKernel();
/** @var Environment $twig */
$twig = $kernel->getContainer()->get('twig');
$stack = $kernel->getContainer()->get('request_stack');
$twig = self::getContainer()->get('twig');
$stack = self::getContainer()->get('request_stack');
$cacheDir = $kernel->getContainer()->getParameter('kernel.cache_dir');
$request = new Request();
@@ -75,5 +62,11 @@ class PdfRendererTest extends KernelTestCase
$response = $sut->render($document, $model);
$this->assertEquals('application/pdf', $response->headers->get('Content-Type'));
$this->assertStringContainsString('attachment; filename', $response->headers->get('Content-Disposition'));
$this->assertNotEmpty($response->getContent());
$sut->setDispositionInline(true);
$response = $sut->render($document, $model);
$this->assertStringContainsString('inline; filename', $response->headers->get('Content-Disposition'));
}
}

View File

@@ -9,12 +9,11 @@
namespace App\Tests\Invoice\Renderer;
use App\Configuration\LanguageFormattings;
use App\Configuration\LocaleService;
use App\Entity\Activity;
use App\Entity\ActivityMeta;
use App\Entity\Customer;
use App\Entity\CustomerMeta;
use App\Entity\InvoiceDocument;
use App\Entity\InvoiceTemplate;
use App\Entity\Project;
use App\Entity\ProjectMeta;
@@ -28,25 +27,20 @@ use App\Invoice\InvoiceFormatter;
use App\Invoice\InvoiceModel;
use App\Invoice\NumberGenerator\DateNumberGenerator;
use App\Invoice\Renderer\AbstractRenderer;
use App\Model\InvoiceDocument;
use App\Repository\InvoiceRepository;
use App\Repository\Query\InvoiceQuery;
use App\Tests\Mocks\InvoiceModelFactoryFactory;
use Doctrine\Common\Collections\ArrayCollection;
trait RendererTestTrait
{
/**
* @return string
*/
protected function getInvoiceTemplatePath()
protected function getInvoiceTemplatePath(): string
{
return __DIR__ . '/../../../templates/invoice/renderer/';
}
/**
* @param string $filename
* @return InvoiceDocument
*/
protected function getInvoiceDocument(string $filename, bool $testOnly = false)
protected function getInvoiceDocument(string $filename, bool $testOnly = false): InvoiceDocument
{
if (!$testOnly) {
return new InvoiceDocument(
@@ -59,11 +53,7 @@ trait RendererTestTrait
);
}
/**
* @param string $classname
* @return AbstractRenderer
*/
protected function getAbstractRenderer(string $classname)
protected function getAbstractRenderer(string $classname): AbstractRenderer
{
return new $classname();
}
@@ -72,13 +62,13 @@ trait RendererTestTrait
{
$languages = [
'en' => [
'date' => 'Y.m.d',
'duration' => '%h:%m h',
'date' => 'yy.MM.dd',
'time' => 'H:i',
'rtl' => false,
]
];
$formattings = new LanguageFormattings($languages);
$formattings = new LocaleService($languages);
return new DefaultInvoiceFormatter($formattings, 'en');
}
@@ -86,15 +76,14 @@ trait RendererTestTrait
protected function getInvoiceModel(): InvoiceModel
{
$user = new User();
$user->setUsername('one-user');
$user->setUserIdentifier('one-user');
$user->setTitle('user title');
$user->setAlias('genious alias');
$user->setEmail('fantastic@four');
$user->addPreference((new UserPreference())->setName('kitty')->setValue('kat'));
$user->addPreference((new UserPreference())->setName('hello')->setValue('world'));
$user->addPreference(new UserPreference('kitty', 'kat'));
$user->addPreference(new UserPreference('hello', 'world'));
$customer = new Customer();
$customer->setName('customer,with/special#name');
$customer = new Customer('customer,with/special#name');
$customer->setAddress('Foo' . PHP_EOL . 'Street' . PHP_EOL . '1111 City');
$customer->setCurrency('EUR');
$customer->setMetaField((new CustomerMeta())->setName('foo-customer')->setValue('bar-customer')->setIsVisible(true));
@@ -104,35 +93,57 @@ trait RendererTestTrait
$template->setVat(19);
$template->setLanguage('en');
$project = new Project();
$project->setName('project name');
$project->setCustomer($customer);
$project->setMetaField((new ProjectMeta())->setName('foo-project')->setValue('bar-project')->setIsVisible(true));
$pMeta = new ProjectMeta();
$pMeta->setName('foo-project')->setValue('bar-project')->setIsVisible(true);
$project = $this->createMock(Project::class);
$project->method('getId')->willReturn(0);
$project->method('getName')->willReturn('project name');
$project->method('getCustomer')->willReturn($customer);
$project->method('getMetaFields')->willReturn(new ArrayCollection([$pMeta]));
$project->method('getVisibleMetaFields')->willReturn([$pMeta]);
$activity = new Activity();
$activity->setName('activity description');
$activity->setProject($project);
$activity->setMetaField((new ActivityMeta())->setName('foo-activity')->setValue('bar-activity')->setIsVisible(true));
$aMeta = new ActivityMeta();
$aMeta->setName('foo-activity');
$aMeta->setValue('bar-activity');
$aMeta->setIsVisible(true);
$activity = $this->createMock(Activity::class);
$activity->method('getId')->willReturn(0);
$activity->method('getName')->willReturn('activity description');
$activity->method('getProject')->willReturn($project);
$activity->method('getMetaFields')->willReturn(new ArrayCollection([$aMeta]));
$activity->method('getVisibleMetaFields')->willReturn([$aMeta]);
$project2 = new Project();
$project2->setName('project 2 name');
$project2->setCustomer($customer);
$project2->setMetaField((new ProjectMeta())->setName('foo-project')->setValue('bar-project2')->setIsVisible(true));
$pMeta2 = new ProjectMeta();
$pMeta2->setName('foo-project')->setValue('bar-project2')->setIsVisible(true);
$project2 = $this->createMock(Project::class);
$project2->method('getId')->willReturn(1);
$project2->method('getName')->willReturn('project 2 name');
$project2->method('getCustomer')->willReturn($customer);
$project2->method('getMetaFields')->willReturn(new ArrayCollection([$pMeta2]));
$project2->method('getVisibleMetaFields')->willReturn([$pMeta2]);
$activity2 = new Activity();
$activity2->setName('activity 1 description');
$activity2->setProject($project2);
$activity2->setMetaField((new ActivityMeta())->setName('foo-activity')->setValue('bar-activity2')->setIsVisible(true));
$aMeta2 = new ActivityMeta();
$aMeta2->setName('foo-activity');
$aMeta2->setValue('bar-activity2');
$aMeta2->setIsVisible(true);
$activity2 = $this->createMock(Activity::class);
$activity2->method('getId')->willReturn(1);
$activity2->method('getName')->willReturn('activity 1 description');
$activity2->method('getProject')->willReturn($project2);
$activity2->method('getMetaFields')->willReturn(new ArrayCollection([$aMeta2]));
$activity2->method('getVisibleMetaFields')->willReturn([$aMeta2]);
$userMethods = ['getId', 'getPreferenceValue', 'getUsername'];
$userMethods = ['getId', 'getPreferenceValue', 'getUsername', 'getUserIdentifier'];
$user1 = $this->getMockBuilder(User::class)->onlyMethods($userMethods)->disableOriginalConstructor()->getMock();
$user1->method('getId')->willReturn(1);
$user1->method('getPreferenceValue')->willReturn('50');
$user1->method('getUsername')->willReturn('foo-bar');
$user1->method('getUserIdentifier')->willReturn('foo-bar');
$user2 = $this->getMockBuilder(User::class)->onlyMethods($userMethods)->disableOriginalConstructor()->getMock();
$user2->method('getId')->willReturn(2);
$user2->method('getUsername')->willReturn('hello-world');
$user2->method('getUserIdentifier')->willReturn('hello-world');
$timesheet = new Timesheet();
$timesheet
@@ -191,15 +202,18 @@ trait RendererTestTrait
->setMetaField((new TimesheetMeta())->setName('foo-timesheet3')->setValue('bluuuub')->setIsVisible(true))
;
$userKevin = new User();
$userKevin->setUserIdentifier('kevin');
$timesheet5 = new Timesheet();
$timesheet5
->setDuration(400)
->setFixedRate(84)
->setUser((new User())->setUsername('kevin'))
->setUser($userKevin)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime('2021-03-12 07:13:00'))
->setEnd(new \DateTime('2021-03-12 07:17:40'))
->setBegin(new \DateTime('2021-03-12 12:13:00'))
->setEnd(new \DateTime('2021-03-12 12:17:40'))
->setDescription(
"foo\n" .
"foo\r\n" .
@@ -252,21 +266,21 @@ trait RendererTestTrait
protected function getInvoiceModelOneEntry(): InvoiceModel
{
$user = new User();
$user->setUsername('one-user');
$user->setUserIdentifier('one-user');
$user->setTitle('user title');
$user->setAlias('genious alias');
$user->setEmail('fantastic@four');
$user->addPreference((new UserPreference())->setName('kitty')->setValue('kat'));
$user->addPreference((new UserPreference())->setName('hello')->setValue('world'));
$user->addPreference(new UserPreference('kitty', 'kat'));
$user->addPreference(new UserPreference('hello', 'world'));
$customer = new Customer();
$customer->setName('customer,with/special#name');
$customer = new Customer('customer,with/special#name');
$customer->setCurrency('USD');
$customer->setMetaField((new CustomerMeta())->setName('foo-customer')->setValue('bar-customer')->setIsVisible(true));
$template = new InvoiceTemplate();
$template->setTitle('a test invoice template title');
$template->setVat(19);
$template->setLanguage('it');
$project = new Project();
$project->setName('project name');
@@ -278,11 +292,11 @@ trait RendererTestTrait
$activity->setProject($project);
$activity->setMetaField((new ActivityMeta())->setName('foo-activity')->setValue('bar-activity')->setIsVisible(true));
$userMethods = ['getId', 'getPreferenceValue', 'getUsername'];
$user1 = $this->getMockBuilder(User::class)->onlyMethods($userMethods)->disableOriginalConstructor()->getMock();
$user1 = $this->createMock(User::class);
$user1->method('getId')->willReturn(1);
$user1->method('getPreferenceValue')->willReturn('50');
$user1->method('getUsername')->willReturn('foo-bar');
$user1->method('getUserIdentifier')->willReturn('foo-bar');
$timesheet = new Timesheet();
$timesheet
@@ -299,6 +313,7 @@ trait RendererTestTrait
$query = new InvoiceQuery();
$query->addActivity($activity);
$query->addProject($project);
$query->setBegin(new \DateTime());
$query->setEnd(new \DateTime());

View File

@@ -1,98 +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\Renderer\TextRenderer;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
/**
* @covers \App\Invoice\Renderer\AbstractTwigRenderer
* @covers \App\Invoice\Renderer\TextRenderer
* @group integration
*/
class TextRendererTest extends KernelTestCase
{
use RendererTestTrait;
public function testSupports()
{
$loader = new FilesystemLoader();
$env = new Environment($loader);
$sut = new TextRenderer($env);
$this->assertFalse($sut->supports($this->getInvoiceDocument('default.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('freelancer.pdf.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('timesheet.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('spreadsheet.xlsx', true)));
$this->assertFalse($sut->supports($this->getInvoiceDocument('open-spreadsheet.ods', true)));
$this->assertTrue($sut->supports($this->getInvoiceDocument('text.txt.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('javascript.json.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('xml.xml.twig')));
}
public function testRender()
{
$kernel = self::bootKernel();
/** @var Environment $twig */
$twig = $kernel->getContainer()->get('twig');
$stack = $kernel->getContainer()->get('request_stack');
$request = new Request();
$request->setLocale('en');
$stack->push($request);
/** @var FilesystemLoader $loader */
$loader = $twig->getLoader();
$loader->addPath($this->getInvoiceTemplatePath(), 'invoice');
$sut = new TextRenderer($twig);
$model = $this->getInvoiceModel();
$document = $this->getInvoiceDocument('text.txt.twig');
$response = $sut->render($document, $model);
self::assertEquals('text/plain', $response->headers->get('Content-Type'));
$content = $response->getContent();
foreach ($model->toArray() as $key => $value) {
if (null === $value || '' === $value) {
self::assertStringContainsString(sprintf("%s\n", $key), $content);
} else {
self::assertStringContainsString(sprintf("%s\n %s", $key, explode("\n", $value)[0]), $content);
}
}
foreach ($model->getCalculator()->getEntries() as $entry) {
foreach ($model->itemToArray($entry) as $key => $value) {
if (null === $value || '' === $value) {
self::assertStringContainsString(sprintf("%s\n", $key), $content);
} else {
self::assertStringContainsString(sprintf("%s\n %s", $key, explode("\n", $value)[0]), $content);
}
}
}
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

@@ -30,10 +30,10 @@ class TwigRendererTest extends KernelTestCase
$env = new Environment($loader);
$sut = new TwigRenderer($env);
$this->assertTrue($sut->supports($this->getInvoiceDocument('default.html.twig')));
$this->assertTrue($sut->supports($this->getInvoiceDocument('invoice.html.twig')));
$this->assertTrue($sut->supports($this->getInvoiceDocument('timesheet.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('freelancer.pdf.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('service-date.pdf.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx', true)));
$this->assertFalse($sut->supports($this->getInvoiceDocument('spreadsheet.xlsx', true)));
$this->assertFalse($sut->supports($this->getInvoiceDocument('open-spreadsheet.ods', true)));
}
@@ -42,8 +42,8 @@ class TwigRendererTest extends KernelTestCase
{
$kernel = self::bootKernel();
/** @var Environment $twig */
$twig = $kernel->getContainer()->get('twig');
$stack = $kernel->getContainer()->get('request_stack');
$twig = self::getContainer()->get('twig');
$stack = self::getContainer()->get('request_stack');
$request = new Request();
$request->setLocale('en');
$stack->push($request);
@@ -65,7 +65,9 @@ class TwigRendererTest extends KernelTestCase
$filename = $model->getInvoiceNumber() . '-customer_with_special_name';
$this->assertStringContainsString('<title>' . $filename . '</title>', $content);
$this->assertStringContainsString('<span contenteditable="true">a very *long* test invoice / template title with [ßpecial] chäracter</span>', $content);
$this->assertEquals(3, substr_count($content, 'activity description'));
// 3 timesheets have a description and therefor do not render the activity
// 2 timesheets have no description and the correct activity assigned
$this->assertEquals(2, substr_count($content, 'activity description'));
$this->assertStringContainsString(nl2br("foo\n" .
"foo\r\n" .
'foo' . PHP_EOL .

View File

@@ -29,10 +29,10 @@ class XlsxRendererTest extends TestCase
{
$sut = $this->getAbstractRenderer(XlsxRenderer::class);
$this->assertFalse($sut->supports($this->getInvoiceDocument('default.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('freelancer.pdf.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('invoice.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('service-date.pdf.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('timesheet.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx', true)));
$this->assertTrue($sut->supports($this->getInvoiceDocument('spreadsheet.xlsx', true)));
$this->assertFalse($sut->supports($this->getInvoiceDocument('open-spreadsheet.ods', true)));
}

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\Renderer\XmlRenderer;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
/**
* @covers \App\Invoice\Renderer\AbstractTwigRenderer
* @covers \App\Invoice\Renderer\XmlRenderer
* @group integration
*/
class XmlRendererTest extends KernelTestCase
{
use RendererTestTrait;
public function testSupports()
{
$loader = new FilesystemLoader();
$env = new Environment($loader);
$sut = new XmlRenderer($env);
$this->assertFalse($sut->supports($this->getInvoiceDocument('default.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('freelancer.pdf.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('timesheet.html.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('javascript.json.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('spreadsheet.xlsx', true)));
$this->assertFalse($sut->supports($this->getInvoiceDocument('open-spreadsheet.ods', true)));
$this->assertFalse($sut->supports($this->getInvoiceDocument('text.txt.twig')));
$this->assertFalse($sut->supports($this->getInvoiceDocument('javascript.json.twig')));
$this->assertTrue($sut->supports($this->getInvoiceDocument('xml.xml.twig')));
}
public function testRender()
{
$kernel = self::bootKernel();
/** @var Environment $twig */
$twig = $kernel->getContainer()->get('twig');
$stack = $kernel->getContainer()->get('request_stack');
$request = new Request();
$request->setLocale('en');
$stack->push($request);
/** @var FilesystemLoader $loader */
$loader = $twig->getLoader();
$loader->addPath($this->getInvoiceTemplatePath(), 'invoice');
$sut = new XmlRenderer($twig);
$model = $this->getInvoiceModel();
$document = $this->getInvoiceDocument('xml.xml.twig');
$response = $sut->render($document, $model);
self::assertEquals('application/xml', $response->headers->get('Content-Type'));
$content = $response->getContent();
$xml = new \SimpleXMLElement($content);
$expected = $model->toArray();
foreach ($xml as $element) {
$name = $element->getName();
if ($name === 'items') {
continue;
}
self::assertEquals((string) $expected[$name], (string) $element);
}
self::assertEquals(\count($model->getCalculator()->getEntries()), \count($xml->items->item));
}
}

View File

@@ -9,10 +9,9 @@
namespace App\Tests\Invoice;
use App\Configuration\LanguageFormattings;
use App\Configuration\LocaleService;
use App\Entity\Customer;
use App\Entity\Invoice;
use App\Entity\InvoiceDocument;
use App\Entity\InvoiceTemplate;
use App\Entity\Project;
use App\Entity\Timesheet;
@@ -21,6 +20,7 @@ use App\Invoice\InvoiceItemRepositoryInterface;
use App\Invoice\NumberGenerator\DateNumberGenerator;
use App\Invoice\Renderer\TwigRenderer;
use App\Invoice\ServiceInvoice;
use App\Model\InvoiceDocument;
use App\Repository\InvoiceDocumentRepository;
use App\Repository\InvoiceRepository;
use App\Repository\Query\InvoiceQuery;
@@ -39,12 +39,12 @@ class ServiceInvoiceTest extends TestCase
$languages = [
'en' => [
'date' => 'Y.m.d',
'duration' => '%h:%m h',
'duration' => '%h:%m',
'time' => 'H:i',
]
];
$formattings = new LanguageFormattings($languages);
$formattings = new LocaleService($languages);
$repo = new InvoiceDocumentRepository($paths);
$invoiceRepo = $this->createMock(InvoiceRepository::class);
@@ -116,71 +116,20 @@ class ServiceInvoiceTest extends TestCase
$this->expectExceptionMessage('Cannot create invoice model without template');
$query = new InvoiceQuery();
$query->setCustomers([new Customer()]);
$query->setCustomers([new Customer('foo')]);
$sut = $this->getSut([]);
$sut->createModel($query);
}
/**
* @group legacy
*/
public function testCreateModelSetsFallbackLanguage()
{
$template = new InvoiceTemplate();
$template->setNumberGenerator('date');
self::assertNull($template->getLanguage());
$query = new InvoiceQuery();
$query->setCustomers([new Customer()]);
$query->setTemplate($template);
$sut = $this->getSut([]);
$sut->addCalculator(new DefaultCalculator());
$sut->addNumberGenerator($this->getNumberGeneratorSut());
$model = $sut->createModel($query);
self::assertEquals('en', $model->getTemplate()->getLanguage());
}
/**
* @group legacy
*/
public function testFindInvoiceItemsWithoutCustomer()
{
$sut = $this->getSut([]);
$query = new InvoiceQuery();
$items = $sut->findInvoiceItems($query);
self::assertEquals([], $items);
}
/**
* @group legacy
*/
public function testFindInvoiceItemsWithCustomer()
{
$sut = $this->getSut([]);
$query = new InvoiceQuery();
$query->setCustomers([new Customer(), new Customer()]);
$items = $sut->findInvoiceItems($query);
self::assertEquals([], $items);
}
public function testCreateModelUsesTemplateLanguage()
{
$template = new InvoiceTemplate();
$template->setNumberGenerator('date');
$template->setLanguage('de');
self::assertEquals('de', $template->getLanguage());
$template->setLanguage('it');
$query = new InvoiceQuery();
$query->setCustomers([new Customer()]);
$query->setCustomers([new Customer('foo')]);
$query->setTemplate($template);
$sut = $this->getSut([]);
@@ -189,13 +138,13 @@ class ServiceInvoiceTest extends TestCase
$model = $sut->createModel($query);
self::assertEquals('de', $model->getTemplate()->getLanguage());
self::assertEquals('it', $model->getTemplate()->getLanguage());
}
public function testBeginAndEndDateFallback()
{
$timezone = new \DateTimeZone('Europe/Vienna');
$customer = new Customer();
$customer = new Customer('foo');
$project = new Project();
$project->setCustomer($customer);
@@ -237,10 +186,8 @@ class ServiceInvoiceTest extends TestCase
$template->setNumberGenerator('date');
$template->setLanguage('de');
self::assertEquals('de', $template->getLanguage());
$query = new InvoiceQuery();
$query->setCustomers([new Customer(), $customer]);
$query->setCustomers([new Customer('foo'), $customer]);
$query->setTemplate($template);
self::assertNull($query->getBegin());
self::assertNull($query->getEnd());
@@ -266,21 +213,29 @@ class ServiceInvoiceTest extends TestCase
$customer1 = $this->createMock(Customer::class);
$customer1->method('getId')->willReturn(1);
$customer1->method('getName')->willReturn('customer1');
$customer1->method('isVisible')->willReturn(true);
$project1 = new Project();
$project1->setCustomer($customer1);
$customer2 = $this->createMock(Customer::class);
$customer2->method('getId')->willReturn(2);
$customer2->method('getName')->willReturn('customer2');
$customer2->method('isVisible')->willReturn(true);
$project2 = new Project();
$project2->setCustomer($customer2);
$customer3 = $this->createMock(Customer::class);
$customer3->method('getId')->willReturn(3);
$customer3->method('getName')->willReturn('customer3');
$customer3->method('isVisible')->willReturn(true);
$project3 = new Project();
$project3->setCustomer($customer3);
$customer4 = $this->createMock(Customer::class);
$customer4->method('getId')->willReturn(4);
$customer4->method('getName')->willReturn('customer4');
$customer4->method('isVisible')->willReturn(true);
$project4 = new Project();
$project4->setCustomer($customer4);
@@ -344,7 +299,7 @@ class ServiceInvoiceTest extends TestCase
self::assertEquals('de', $template->getLanguage());
$query = new InvoiceQuery();
$query->setCustomers([$customer3, new Customer(), $customer1, $customer3]);
$query->setCustomers([$customer3, new Customer('tröööt'), $customer1, $customer3]);
$query->setTemplate($template);
self::assertNull($query->getBegin());
self::assertNull($query->getEnd());

Binary file not shown.

View File

@@ -8,7 +8,7 @@
<div class="col-xs-12">
<h2 class="page-header">
<span contenteditable="true">{{ model.template.title }}</span>
<small class="pull-right">{{ 'label.date'|trans({}, 'messages', language) }}: {{ model.invoiceDate|date_short }}</small>
<small class="pull-right">{{ 'date'|trans({}, 'messages', language) }}: {{ model.invoiceDate|date_short }}</small>
</h2>
</div>
</div>
@@ -21,7 +21,7 @@
{{ model.template.address|trim|nl2br }}
{% if model.template.vatId is not empty %}
<br>
{{ 'label.vat_id'|trans({}, 'messages', language) }}:
{{ 'vat_id'|trans({}, 'messages', language) }}:
{{ model.template.vatId }}
{% endif %}
</address>
@@ -34,15 +34,15 @@
{{ model.customer.address|nl2br }}
{% if model.customer.vatId is not empty %}
<br>
{{ 'label.vat_id'|trans({}, 'messages', language) }}: {{ model.customer.vatId }}
{{ 'vat_id'|trans({}, 'messages', language) }}: {{ model.customer.vatId }}
{% endif %}
{% if model.customer.number is not empty %}
<br>
{{ 'label.number'|trans({}, 'messages', language) }}: {{ model.customer.number }}
{{ 'number'|trans({}, 'messages', language) }}: {{ model.customer.number }}
{% endif %}
{% if model.query.project is not empty and model.query.project.orderNumber is not empty %}
<br>
{{ 'label.orderNumber'|trans({}, 'messages', language) }}: {{ model.query.project.orderNumber }}
{{ 'orderNumber'|trans({}, 'messages', language) }}: {{ model.query.project.orderNumber }}
{% endif %}
</address>
</div>
@@ -67,11 +67,11 @@
<table class="table">
<thead>
<tr>
<th>{{ 'label.date'|trans({}, 'messages', language) }}</th>
<th>{{ 'label.description'|trans({}, 'messages', language) }}</th>
<th class="text-right">{{ 'label.unit_price'|trans({}, 'messages', language) }}</th>
<th class="text-right">{{ 'label.amount'|trans({}, 'messages', language) }}</th>
<th class="text-right">{{ 'label.total_rate'|trans({}, 'messages', language) }}</th>
<th>{{ 'date'|trans({}, 'messages', language) }}</th>
<th>{{ 'description'|trans({}, 'messages', language) }}</th>
<th class="text-right">{{ 'unit_price'|trans({}, 'messages', language) }}</th>
<th class="text-right">{{ 'amount'|trans({}, 'messages', language) }}</th>
<th class="text-right">{{ 'total_rate'|trans({}, 'messages', language) }}</th>
</tr>
</thead>
<tbody>
@@ -136,11 +136,11 @@
<footer class="footer">
<p>
<strong>{{ 'label.address'|trans({}, 'messages', language) }}</strong>: {{ model.template.company }} &ndash; {{ model.template.address|replace({"\n": ' &ndash; ', "\r\n": ' &ndash; ', "\r": ' &ndash; '})|raw }}
<strong>{{ 'address'|trans({}, 'messages', language) }}</strong>: {{ model.template.company }} &ndash; {{ model.template.address|replace({"\n": ' &ndash; ', "\r\n": ' &ndash; ', "\r": ' &ndash; '})|raw }}
<br>
<strong>{{ 'label.invoice_bank_account'|trans({}, 'messages', language) }}</strong>: {{ model.template.paymentDetails|replace({"\n": ' &ndash; ', "\r\n": ' &ndash; ', "\r": ' &ndash; '})|raw }}
<strong>{{ 'invoice_bank_account'|trans({}, 'messages', language) }}</strong>: {{ model.template.paymentDetails|replace({"\n": ' &ndash; ', "\r\n": ' &ndash; ', "\r": ' &ndash; '})|raw }}
<br>
<strong>{{ 'label.contact'|trans({}, 'messages', language) }}</strong>: {{ model.template.contact|replace({"\n": ' &ndash; ', "\r\n": ' &ndash; ', "\r": ' &ndash; '})|raw }}
<strong>{{ 'contact'|trans({}, 'messages', language) }}</strong>: {{ model.template.contact|replace({"\n": ' &ndash; ', "\r\n": ' &ndash; ', "\r": ' &ndash; '})|raw }}
</p>
</footer>