invoices: choose language and duration format (#1438)

This commit is contained in:
Kevin Papst
2020-02-04 20:27:36 +01:00
committed by GitHub
parent 75dcae6fbe
commit 986d922855
64 changed files with 1559 additions and 541 deletions

View File

@@ -0,0 +1,93 @@
<?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\Hydrator;
use App\Invoice\Hydrator\InvoiceItemDefaultHydrator;
use App\Tests\Invoice\Renderer\RendererTestTrait;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Invoice\Hydrator\InvoiceItemDefaultHydrator
*/
class InvoiceItemDefaultHydratorTest extends TestCase
{
use RendererTestTrait;
public function testHydrate()
{
$model = $this->getInvoiceModel();
$sut = new InvoiceItemDefaultHydrator();
$sut->setInvoiceModel($model);
$result = $sut->hydrate($model->getCalculator()->getEntries()[0]);
$metaFields = ['entry.meta.foo-timesheet'];
$this->assertEntryStructure($result, $metaFields);
$result = $sut->hydrate($model->getCalculator()->getEntries()[1]);
$metaFields = ['entry.meta.foo-timesheet2'];
$this->assertEntryStructure($result, $metaFields);
}
protected function assertEntryStructure(array $model, array $metaFields)
{
$keys = [
'entry.row',
'entry.description',
'entry.amount',
'entry.rate',
'entry.rate_nc',
'entry.rate_plain',
'entry.total',
'entry.total_nc',
'entry.total_plain',
'entry.currency',
'entry.duration',
'entry.duration_decimal',
'entry.duration_minutes',
'entry.begin',
'entry.begin_time',
'entry.begin_timestamp',
'entry.end',
'entry.end_time',
'entry.end_timestamp',
'entry.date',
'entry.user_id',
'entry.user_name',
'entry.user_alias',
'entry.user_title',
'entry.activity',
'entry.activity_id',
'entry.activity.meta.foo-activity',
'entry.project',
'entry.project_id',
'entry.project.meta.foo-project',
'entry.customer',
'entry.customer_id',
'entry.customer.meta.foo-customer',
'entry.category',
'entry.type',
];
$keys = array_merge($keys, $metaFields);
foreach ($keys as $key) {
$this->assertArrayHasKey($key, $model);
}
$expectedKeys = array_merge([], $keys);
sort($expectedKeys);
$givenKeys = array_keys($model);
sort($givenKeys);
$this->assertEquals($expectedKeys, $givenKeys);
$this->assertEquals(count($keys), count($givenKeys));
}
}

View File

@@ -0,0 +1,58 @@
<?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\Hydrator;
use App\Invoice\Hydrator\InvoiceModelActivityHydrator;
use App\Tests\Invoice\Renderer\RendererTestTrait;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Invoice\Hydrator\InvoiceModelActivityHydrator
*/
class InvoiceModelActivityHydratorTest extends TestCase
{
use RendererTestTrait;
public function testHydrate()
{
$model = $this->getInvoiceModel();
$sut = new InvoiceModelActivityHydrator();
$result = $sut->hydrate($model);
$this->assertModelStructure($result);
$model->getQuery()->setActivity(null);
$result = $sut->hydrate($model);
self::assertEmpty($result);
}
protected function assertModelStructure(array $model)
{
$keys = [
'activity.id',
'activity.name',
'activity.comment',
'activity.fixed_rate',
'activity.fixed_rate_nc',
'activity.fixed_rate_plain',
'activity.hourly_rate',
'activity.hourly_rate_nc',
'activity.hourly_rate_plain',
'activity.meta.foo-activity',
];
$givenKeys = array_keys($model);
sort($keys);
sort($givenKeys);
$this->assertEquals($keys, $givenKeys);
}
}

View File

@@ -0,0 +1,65 @@
<?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\Hydrator;
use App\Invoice\Hydrator\InvoiceModelCustomerHydrator;
use App\Tests\Invoice\Renderer\RendererTestTrait;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Invoice\Hydrator\InvoiceModelCustomerHydrator
*/
class InvoiceModelCustomerHydratorTest extends TestCase
{
use RendererTestTrait;
public function testHydrate()
{
$model = $this->getInvoiceModel();
$sut = new InvoiceModelCustomerHydrator();
$result = $sut->hydrate($model);
$this->assertModelStructure($result);
$model->setCustomer(null);
$result = $sut->hydrate($model);
self::assertEmpty($result);
}
protected function assertModelStructure(array $model)
{
$keys = [
'customer.id',
'customer.address',
'customer.name',
'customer.contact',
'customer.company',
'customer.vat',
'customer.country',
'customer.number',
'customer.homepage',
'customer.comment',
'customer.fixed_rate',
'customer.fixed_rate_nc',
'customer.fixed_rate_plain',
'customer.hourly_rate',
'customer.hourly_rate_nc',
'customer.hourly_rate_plain',
'customer.meta.foo-customer',
];
$givenKeys = array_keys($model);
sort($keys);
sort($givenKeys);
$this->assertEquals($keys, $givenKeys);
}
}

View File

@@ -0,0 +1,76 @@
<?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\Hydrator;
use App\Invoice\Hydrator\InvoiceModelDefaultHydrator;
use App\Tests\Invoice\Renderer\RendererTestTrait;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Invoice\Hydrator\InvoiceModelDefaultHydrator
*/
class InvoiceModelDefaultHydratorTest extends TestCase
{
use RendererTestTrait;
public function testHydrate()
{
$model = $this->getInvoiceModel();
$sut = new InvoiceModelDefaultHydrator();
$result = $sut->hydrate($model);
$this->assertModelStructure($result);
}
protected function assertModelStructure(array $model, $hasProject = true)
{
$keys = [
'invoice.due_date',
'invoice.date',
'invoice.number',
'invoice.currency',
'invoice.currency_symbol',
'invoice.vat',
'invoice.tax',
'invoice.tax_nc',
'invoice.tax_plain',
'invoice.total_time',
'invoice.duration_decimal',
'invoice.total',
'invoice.total_nc',
'invoice.total_plain',
'invoice.subtotal',
'invoice.subtotal_nc',
'invoice.subtotal_plain',
'template.name',
'template.company',
'template.address',
'template.title',
'template.payment_terms',
'template.due_days',
'template.vat_id',
'template.contact',
'template.payment_details',
'query.begin',
'query.day',
'query.end',
'query.month',
'query.month_number',
'query.year',
];
$givenKeys = array_keys($model);
sort($keys);
sort($givenKeys);
$this->assertEquals($keys, $givenKeys);
}
}

View File

@@ -0,0 +1,68 @@
<?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\Hydrator;
use App\Invoice\Hydrator\InvoiceModelProjectHydrator;
use App\Tests\Invoice\Renderer\RendererTestTrait;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Invoice\Hydrator\InvoiceModelProjectHydrator
*/
class InvoiceModelProjectHydratorTest extends TestCase
{
use RendererTestTrait;
public function testHydrate()
{
$model = $this->getInvoiceModel();
$sut = new InvoiceModelProjectHydrator();
$result = $sut->hydrate($model);
$this->assertModelStructure($result);
$model->getQuery()->setProject(null);
$result = $sut->hydrate($model);
self::assertEmpty($result);
}
protected function assertModelStructure(array $model)
{
$keys = [
'project.id',
'project.name',
'project.comment',
'project.order_date',
'project.order_number',
'project.fixed_rate',
'project.fixed_rate_nc',
'project.fixed_rate_plain',
'project.hourly_rate',
'project.hourly_rate_nc',
'project.hourly_rate_plain',
'project.meta.foo-project',
'project.start_date',
'project.end_date',
'project.budget_money',
'project.budget_money_nc',
'project.budget_money_plain',
'project.budget_time',
'project.budget_time_decimal',
'project.budget_time_minutes',
];
$givenKeys = array_keys($model);
sort($keys);
sort($givenKeys);
$this->assertEquals($keys, $givenKeys);
}
}

View File

@@ -0,0 +1,50 @@
<?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\Hydrator;
use App\Invoice\Hydrator\InvoiceModelUserHydrator;
use App\Tests\Invoice\Renderer\RendererTestTrait;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Invoice\Hydrator\InvoiceModelUserHydrator
*/
class InvoiceModelUserHydratorTest extends TestCase
{
use RendererTestTrait;
public function testHydrate()
{
$model = $this->getInvoiceModel();
$sut = new InvoiceModelUserHydrator();
$result = $sut->hydrate($model);
$this->assertModelStructure($result);
}
protected function assertModelStructure(array $model)
{
$keys = [
'user.alias',
'user.email',
'user.name',
'user.title',
'user.meta.hello',
'user.meta.kitty',
];
$givenKeys = array_keys($model);
sort($keys);
sort($givenKeys);
$this->assertEquals($keys, $givenKeys);
}
}