support custom fields for invoices (#3077)

This commit is contained in:
Kevin Papst
2022-01-20 16:59:26 +01:00
committed by GitHub
parent 9731023014
commit 40242b7dcc
15 changed files with 396 additions and 6 deletions

View File

@@ -199,6 +199,7 @@ class InvoiceControllerTest extends ControllerBaseTest
$this->assertIsRedirect($client);
$this->assertRedirectUrl($client, '/invoice/show?id=', false);
$client->followRedirect();
$this->assertTrue($client->getResponse()->isSuccessful());
$this->assertDataTableRowCount($client, 'datatable_invoices', 1);
$em = $this->getEntityManager();

View File

@@ -0,0 +1,41 @@
<?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\Entity;
use App\Entity\Customer;
use App\Entity\EntityWithMetaFields;
use App\Entity\Invoice;
use App\Entity\InvoiceMeta;
use App\Entity\MetaTableTypeInterface;
/**
* @covers \App\Entity\InvoiceMeta
*/
class InvoiceMetaTest extends AbstractMetaEntityTest
{
protected function getEntity(): EntityWithMetaFields
{
return new Invoice();
}
protected function getMetaEntity(): MetaTableTypeInterface
{
return new InvoiceMeta();
}
public function testSetEntityThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected instanceof Invoice, received "App\Entity\Customer"');
$sut = new InvoiceMeta();
$sut->setEntity(new Customer());
}
}

View File

@@ -14,6 +14,7 @@ use App\Entity\ActivityMeta;
use App\Entity\Customer;
use App\Entity\CustomerMeta;
use App\Entity\Invoice;
use App\Entity\InvoiceMeta;
use App\Entity\InvoiceTemplate;
use App\Entity\Project;
use App\Entity\ProjectMeta;
@@ -221,4 +222,54 @@ class InvoiceTest extends TestCase
return new DateNumberGenerator($repository);
}
public function testClone()
{
$sut = new Invoice();
$sut->setComment('foo kajsdhgf aksjdhfg');
$sut->setFilename('1234567890');
$meta = new InvoiceMeta();
$meta->setName('blabla');
$meta->setValue('1234567890');
$meta->setIsVisible(false);
$meta->setIsRequired(true);
$sut->setMetaField($meta);
$clone = clone $sut;
foreach ($sut->getMetaFields() as $metaField) {
$cloneMeta = $clone->getMetaField($metaField->getName());
self::assertEquals($cloneMeta->getValue(), $metaField->getValue());
}
self::assertEquals('1234567890', $clone->getInvoiceFilename());
self::assertEquals('foo kajsdhgf aksjdhfg', $clone->getComment());
}
public function testMetaFields()
{
$sut = new Invoice();
$meta = new InvoiceMeta();
$meta->setName('foo')->setValue('bar')->setType('test');
self::assertInstanceOf(Invoice::class, $sut->setMetaField($meta));
self::assertEquals(1, $sut->getMetaFields()->count());
$result = $sut->getMetaField('foo');
self::assertSame($result, $meta);
self::assertEquals('test', $result->getType());
$meta2 = new InvoiceMeta();
$meta2->setName('foo')->setValue('bar')->setType('test2');
self::assertInstanceOf(Invoice::class, $sut->setMetaField($meta2));
self::assertEquals(1, $sut->getMetaFields()->count());
self::assertCount(0, $sut->getVisibleMetaFields());
$result = $sut->getMetaField('foo');
self::assertSame($result, $meta);
self::assertEquals('test2', $result->getType());
$sut->setMetaField((new InvoiceMeta())->setName('blub')->setIsVisible(true));
$sut->setMetaField((new InvoiceMeta())->setName('blab')->setIsVisible(true));
self::assertEquals(3, $sut->getMetaFields()->count());
self::assertCount(2, $sut->getVisibleMetaFields());
}
}

View File

@@ -20,7 +20,7 @@ class InvoiceLoaderTest extends AbstractLoaderTest
{
public function testLoadResults()
{
$em = $this->getEntityManagerMock(2);
$em = $this->getEntityManagerMock(3);
$sut = new InvoiceLoader($em);