test fixes

This commit is contained in:
Dennis Eichhorn 2023-04-17 19:44:57 +02:00
parent b50b81bf6c
commit f0d2b883d4
11 changed files with 39 additions and 382 deletions

View File

@ -152,9 +152,9 @@ final class ApiController extends Controller
AuditMapper::create()->execute($audit);
if (($validate['status'] === 0
&& $validate['vat'] === true
&& $validate['name'] === true
&& $validate['city'] === true)
&& $validate['vat'] === 'A'
&& $validate['name'] === 'A'
&& $validate['city'] === 'A')
|| $validate['status'] !== 0 // Api out of order -> accept it -> @todo: test it during invoice creation
) {
/** @var \Modules\Attribute\Models\AttributeType $type */

View File

@ -18,8 +18,11 @@ use Modules\Billing\Models\SalesBillMapper;
use Modules\ClientManagement\Models\ClientAttributeTypeMapper;
use Modules\ClientManagement\Models\ClientAttributeValueMapper;
use Modules\ClientManagement\Models\ClientMapper;
use Modules\Media\Models\MediaMapper;
use Modules\Media\Models\MediaTypeMapper;
use phpOMS\Asset\AssetType;
use phpOMS\Contract\RenderableInterface;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\Database\Query\OrderType;
use phpOMS\Localization\ISO3166CharEnum;
use phpOMS\Localization\ISO3166NameEnum;
@ -219,6 +222,33 @@ final class BackendController extends Controller
$view->setData('client', $client);
// Get item profile image
// It might not be part of the 5 newest item files from above
// @todo: It would be nice to have something like this as a default method in the model e.g.
// ItemManagement::getRelations()->with('types')->where(...);
// This should return the relations and NOT the model itself
$query = new Builder($this->app->dbPool->get());
$results = $query->selectAs(ClientMapper::HAS_MANY['files']['external'], 'file')
->from(ClientMapper::TABLE)
->leftJoin(ClientMapper::HAS_MANY['files']['table'])
->on(ClientMapper::HAS_MANY['files']['table'] . '.' . ClientMapper::HAS_MANY['files']['self'], '=', ClientMapper::TABLE . '.' . ClientMapper::PRIMARYFIELD)
->leftJoin(MediaMapper::TABLE)
->on(ClientMapper::HAS_MANY['files']['table'] . '.' . ClientMapper::HAS_MANY['files']['external'], '=', MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD)
->leftJoin(MediaMapper::HAS_MANY['types']['table'])
->on(MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD, '=', MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['self'])
->leftJoin(MediaTypeMapper::TABLE)
->on(MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['external'], '=', MediaTypeMapper::TABLE . '.' . MediaTypeMapper::PRIMARYFIELD)
->where(ClientMapper::HAS_MANY['files']['self'], '=', $client->getId())
->where(MediaTypeMapper::TABLE . '.' . MediaTypeMapper::getColumnByMember('name'), '=', 'client_profile_image');
$clientImage = MediaMapper::get()
->with('types')
->where('id', $results)
->limit(1)
->execute();
$view->addData('clientImage', $clientImage);
// stats
if ($this->app->moduleManager->isActive('Billing')) {
$ytd = SalesBillMapper::getSalesByClientId($client->getId(), new SmartDateTime('Y-01-01'), new SmartDateTime('now'));

View File

@ -12,6 +12,7 @@
*/
declare(strict_types=1);
use Modules\Media\Models\NullMedia;
use Modules\Profile\Models\ContactType;
use phpOMS\Uri\UriFactory;
@ -25,6 +26,8 @@ $client = $this->getData('client');
$notes = $client->getNotes();
$files = $client->getFiles();
$clientImage = $this->getData('clientImage') ?? new NullMedia();
$newestInvoices = $this->getData('newestInvoices') ?? [];
$monthlySalesCosts = $this->getData('monthlySalesCosts') ?? [];

View File

@ -25,6 +25,7 @@ use phpOMS\Application\ApplicationAbstract;
use phpOMS\DataStorage\Session\HttpSession;
use phpOMS\Dispatcher\Dispatcher;
use phpOMS\Event\EventManager;
use phpOMS\Localization\L11nManager;
use phpOMS\Module\ModuleAbstract;
use phpOMS\Module\ModuleManager;
use phpOMS\Router\WebRouter;
@ -63,6 +64,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
$this->app->eventManager = new EventManager($this->app->dispatcher);
$this->app->eventManager->importFromFile(__DIR__ . '/../../../../Web/Api/Hooks.php');
$this->app->sessionManager = new HttpSession(36000);
$this->app->l11nManager = new L11nManager();
$account = new Account();
TestUtils::setMember($account, 'id', 1);

View File

@ -1,63 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\ClientManagement\tests\Models;
use Modules\ClientManagement\Models\ClientAttribute;
/**
* @internal
*/
final class ClientAttributeTest extends \PHPUnit\Framework\TestCase
{
private ClientAttribute $attribute;
/**
* {@inheritdoc}
*/
protected function setUp() : void
{
$this->attribute = new ClientAttribute();
}
/**
* @covers Modules\ClientManagement\Models\ClientAttribute
* @group module
*/
public function testDefault() : void
{
self::assertEquals(0, $this->attribute->getId());
self::assertInstanceOf('\Modules\ClientManagement\Models\ClientAttributeType', $this->attribute->type);
self::assertInstanceOf('\Modules\ClientManagement\Models\ClientAttributeValue', $this->attribute->value);
}
/**
* @covers Modules\ClientManagement\Models\ClientAttribute
* @group module
*/
public function testSerialize() : void
{
$serialized = $this->attribute->jsonSerialize();
self::assertEquals(
[
'id',
'client',
'type',
'value',
],
\array_keys($serialized)
);
}
}

View File

@ -1,82 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\ClientManagement\tests\Models;
use Modules\ClientManagement\Models\ClientAttributeType;
use phpOMS\Localization\BaseStringL11n;
/**
* @internal
*/
final class ClientAttributeTypeTest extends \PHPUnit\Framework\TestCase
{
private ClientAttributeType $type;
/**
* {@inheritdoc}
*/
protected function setUp() : void
{
$this->type = new ClientAttributeType();
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeType
* @group module
*/
public function testDefault() : void
{
self::assertEquals(0, $this->type->getId());
self::assertEquals('', $this->type->getL11n());
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeType
* @group module
*/
public function testL11nInputOutput() : void
{
$this->type->setL11n('Test');
self::assertEquals('Test', $this->type->getL11n());
$this->type->setL11n(new BaseStringL11n('NewTest'));
self::assertEquals('NewTest', $this->type->getL11n());
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeType
* @group module
*/
public function testSerialize() : void
{
$this->type->name = 'Title';
$this->type->fields = 2;
$this->type->custom = true;
$this->type->validationPattern = '\d*';
$this->type->isRequired = true;
self::assertEquals(
[
'id' => 0,
'name' => 'Title',
'fields' => 2,
'custom' => true,
'validationPattern' => '\d*',
'isRequired' => true,
],
$this->type->jsonSerialize()
);
}
}

View File

@ -1,107 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\ClientManagement\tests\Models;
use Modules\ClientManagement\Models\AttributeValueType;
use Modules\ClientManagement\Models\ClientAttributeValue;
/**
* @internal
*/
final class ClientAttributeValueTest extends \PHPUnit\Framework\TestCase
{
private ClientAttributeValue $value;
/**
* {@inheritdoc}
*/
protected function setUp() : void
{
$this->value = new ClientAttributeValue();
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeValue
* @group module
*/
public function testDefault() : void
{
self::assertEquals(0, $this->value->getId());
self::assertNull($this->value->getValue());
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeValue
* @group module
*/
public function testValueIntInputOutput() : void
{
$this->value->setValue(1, AttributeValueType::_INT);
self::assertEquals(1, $this->value->getValue());
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeValue
* @group module
*/
public function testValueFloatInputOutput() : void
{
$this->value->setValue(1.1, AttributeValueType::_FLOAT);
self::assertEquals(1.1, $this->value->getValue());
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeValue
* @group module
*/
public function testValueStringInputOutput() : void
{
$this->value->setValue('test', AttributeValueType::_STRING);
self::assertEquals('test', $this->value->getValue());
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeValue
* @group module
*/
public function testValueDateInputOutput() : void
{
$dat = new \DateTime('now');
$this->value->setValue('now', AttributeValueType::_DATETIME);
self::assertEquals($dat->format('Y-m-d'), $this->value->getValue()->format('Y-m-d'));
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeValue
* @group module
*/
public function testSerialize() : void
{
$this->value->setValue('test', AttributeValueType::_STRING);
$this->value->isDefault = true;
self::assertEquals(
[
'id' => 0,
'valueInt' => null,
'valueStr' => 'test',
'valueDec' => null,
'valueDat' => null,
'isDefault' => true,
],
$this->value->jsonSerialize()
);
}
}

View File

@ -52,7 +52,7 @@ final class ClientTest extends \PHPUnit\Framework\TestCase
self::assertEquals([], $this->client->getAddresses());
self::assertEquals([], $this->client->getContactElements());
self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $this->client->createdAt->format('Y-m-d'));
self::assertInstanceOf('\Modules\Profile\Models\Profile', $this->client->profile);
self::assertInstanceOf('\Modules\Admin\Models\Account', $this->client->account);
self::assertInstanceOf('\Modules\Admin\Models\Address', $this->client->mainAddress);
self::assertInstanceOf('\Modules\Profile\Models\NullContactElement', $this->client->getMainContactElement(0));
}

View File

@ -1,42 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\ClientManagement\tests\Models;
use Modules\ClientManagement\Models\NullClientAttribute;
/**
* @internal
*/
final class NullClientAttributeTest extends \PHPUnit\Framework\TestCase
{
/**
* @covers Modules\ClientManagement\Models\NullClientAttribute
* @group framework
*/
public function testNull() : void
{
self::assertInstanceOf('\Modules\ClientManagement\Models\ClientAttribute', new NullClientAttribute());
}
/**
* @covers Modules\ClientManagement\Models\NullClientAttribute
* @group framework
*/
public function testId() : void
{
$null = new NullClientAttribute(2);
self::assertEquals(2, $null->getId());
}
}

View File

@ -1,42 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\ClientManagement\tests\Models;
use Modules\ClientManagement\Models\NullClientAttributeType;
/**
* @internal
*/
final class NullClientAttributeTypeTest extends \PHPUnit\Framework\TestCase
{
/**
* @covers Modules\ClientManagement\Models\NullClientAttributeType
* @group framework
*/
public function testNull() : void
{
self::assertInstanceOf('\Modules\ClientManagement\Models\ClientAttributeType', new NullClientAttributeType());
}
/**
* @covers Modules\ClientManagement\Models\NullClientAttributeType
* @group framework
*/
public function testId() : void
{
$null = new NullClientAttributeType(2);
self::assertEquals(2, $null->getId());
}
}

View File

@ -1,42 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\ClientManagement\tests\Models;
use Modules\ClientManagement\Models\NullClientAttributeValue;
/**
* @internal
*/
final class NullClientAttributeValueTest extends \PHPUnit\Framework\TestCase
{
/**
* @covers Modules\ClientManagement\Models\NullClientAttributeValue
* @group framework
*/
public function testNull() : void
{
self::assertInstanceOf('\Modules\ClientManagement\Models\ClientAttributeValue', new NullClientAttributeValue());
}
/**
* @covers Modules\ClientManagement\Models\NullClientAttributeValue
* @group framework
*/
public function testId() : void
{
$null = new NullClientAttributeValue(2);
self::assertEquals(2, $null->getId());
}
}