support custom fields for timesheets, customers, projects and activities (#871)

This commit is contained in:
Kevin Papst
2019-06-26 00:39:05 +02:00
committed by GitHub
parent 994c671fd8
commit d8621f0b7a
103 changed files with 2567 additions and 238 deletions

View File

@@ -20,14 +20,14 @@ class DebugRendererTest extends TestCase
public function getTestModel()
{
yield [$this->getInvoiceModel(), '1,947.99', 5, 5, 1, 2, 2, true];
yield [$this->getInvoiceModelOneEntry(), '293.27', 1, 1, 0, 1, 0, false];
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->getInvoiceModelOneEntry(), '293.27', 1, 1, 0, 1, 0, false, []];
}
/**
* @dataProvider getTestModel
*/
public function testRender(InvoiceModel $model, $expectedRate, $expectedRows, $expectedDescriptions, $expectedUser1, $expectedUser2, $expectedUser3, $hasProject)
public function testRender(InvoiceModel $model, $expectedRate, $expectedRows, $expectedDescriptions, $expectedUser1, $expectedUser2, $expectedUser3, $hasProject, $metaFields = [])
{
$document = new InvoiceDocument(new \SplFileInfo(__DIR__ . '/DebugRenderer.php'));
$sut = new DebugRenderer();
@@ -39,14 +39,16 @@ class DebugRendererTest extends TestCase
$rows = $data['entries'];
$this->assertEquals($expectedRows, count($rows));
$i = 0;
foreach ($rows as $row) {
$this->assertEntryStructure($row);
$meta = isset($metaFields[$i]) ? $metaFields[$i++] : [];
$this->assertEntryStructure($row, $meta);
}
// TODO check values or formats?
}
protected function assertModelStructure(array $model, $hasProject = true)
protected function assertModelStructure(array $model, $hasProject = true, $hasActivity = false)
{
$keys = [
'invoice.due_date',
@@ -77,6 +79,11 @@ class DebugRendererTest extends TestCase
'customer.number',
'customer.homepage',
'customer.comment',
'customer.meta.foo-customer',
'activity.id',
'activity.name',
'activity.comment',
'activity.meta.foo-activity',
];
if ($hasProject) {
@@ -85,6 +92,15 @@ class DebugRendererTest extends TestCase
'project.name',
'project.comment',
'project.order_number',
'project.meta.foo-project',
]);
}
if ($hasActivity) {
$keys = array_merge($keys, [
'activity.id',
'activity.name',
'activity.comment',
]);
}
@@ -95,7 +111,7 @@ class DebugRendererTest extends TestCase
$this->assertEquals($keys, $givenKeys);
}
protected function assertEntryStructure(array $model)
protected function assertEntryStructure(array $model, array $metaFields)
{
$keys = [
'entry.row',
@@ -125,6 +141,8 @@ class DebugRendererTest extends TestCase
'entry.customer_id',
];
$keys = array_merge($keys, $metaFields);
foreach ($keys as $key) {
$this->assertArrayHasKey($key, $model);
}
@@ -134,7 +152,7 @@ class DebugRendererTest extends TestCase
$givenKeys = array_keys($model);
sort($givenKeys);
$this->assertEquals(count($keys), count($givenKeys));
$this->assertEquals($expectedKeys, $givenKeys);
$this->assertEquals(count($keys), count($givenKeys));
}
}

View File

@@ -11,11 +11,15 @@ namespace App\Tests\Invoice\Renderer;
use App\Configuration\LanguageFormattings;
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;
use App\Entity\Timesheet;
use App\Entity\TimesheetMeta;
use App\Entity\User;
use App\Invoice\Calculator\DefaultCalculator;
use App\Invoice\NumberGenerator\DateNumberGenerator;
@@ -85,6 +89,8 @@ trait RendererTestTrait
{
$customer = new Customer();
$customer->setCurrency('EUR');
$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);
@@ -92,10 +98,12 @@ trait RendererTestTrait
$project = new Project();
$project->setName('project name');
$project->setCustomer($customer);
$project->setMetaField((new ProjectMeta())->setName('foo-project')->setValue('bar-project')->setIsVisible(true));
$activity = new Activity();
$activity->setName('activity description');
$activity->setProject($project);
$activity->setMetaField((new ActivityMeta())->setName('foo-activity')->setValue('bar-activity')->setIsVisible(true));
$userMethods = ['getId', 'getPreferenceValue', 'getUsername'];
$user1 = $this->getMockBuilder(User::class)->setMethods($userMethods)->disableOriginalConstructor()->getMock();
@@ -116,7 +124,7 @@ trait RendererTestTrait
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
;
->setMetaField((new TimesheetMeta())->setName('foo-timesheet')->setValue('bar-timesheet')->setIsVisible(true));
$timesheet2 = new Timesheet();
$timesheet2
@@ -127,6 +135,8 @@ trait RendererTestTrait
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
->setMetaField((new TimesheetMeta())->setName('foo-timesheet')->setValue('bar-timesheet'))
->setMetaField((new TimesheetMeta())->setName('foo-timesheet2')->setValue('bar-timesheet2')->setIsVisible(true))
;
$timesheet3 = new Timesheet();
@@ -138,6 +148,7 @@ trait RendererTestTrait
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
->setMetaField((new TimesheetMeta())->setName('foo-timesheet')->setValue('bar-timesheet1')->setIsVisible(true))
;
$timesheet4 = new Timesheet();
@@ -149,6 +160,7 @@ trait RendererTestTrait
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
->setMetaField((new TimesheetMeta())->setName('foo-timesheet3')->setValue('bluuuub')->setIsVisible(true))
;
$timesheet5 = new Timesheet();
@@ -193,6 +205,8 @@ trait RendererTestTrait
{
$customer = new Customer();
$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);
@@ -200,10 +214,12 @@ trait RendererTestTrait
$project = new Project();
$project->setName('project name');
$project->setCustomer($customer);
$project->setMetaField((new ProjectMeta())->setName('foo-project')->setValue('bar-project')->setIsVisible(true));
$activity = new Activity();
$activity->setName('activity description');
$activity->setProject($project);
$activity->setMetaField((new ActivityMeta())->setName('foo-activity')->setValue('bar-activity')->setIsVisible(true));
$userMethods = ['getId', 'getPreferenceValue', 'getUsername'];
$user1 = $this->getMockBuilder(User::class)->setMethods($userMethods)->disableOriginalConstructor()->getMock();