From 36e7864fd04e83e334a83fb971ff8d6be77d5efd Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 17 Apr 2023 19:44:57 +0200 Subject: [PATCH] test fixes --- Controller/BackendController.php | 30 +++++ Theme/Backend/Lang/de.lang.php | 2 +- Theme/Backend/Lang/en.lang.php | 2 +- Theme/Backend/item-profile.tpl.php | 9 +- .../Api/ApiControllerAttributeTrait.php | 8 +- tests/Controller/ApiControllerTest.php | 2 + tests/Models/ItemAttributeTest.php | 61 ---------- tests/Models/ItemAttributeTypeTest.php | 84 -------------- tests/Models/ItemAttributeValueTest.php | 108 ------------------ tests/Models/NullItemAttributeTest.php | 42 ------- tests/Models/NullItemAttributeTypeTest.php | 42 ------- tests/Models/NullItemAttributeValueTest.php | 42 ------- 12 files changed, 43 insertions(+), 389 deletions(-) delete mode 100755 tests/Models/ItemAttributeTest.php delete mode 100755 tests/Models/ItemAttributeTypeTest.php delete mode 100755 tests/Models/ItemAttributeValueTest.php delete mode 100755 tests/Models/NullItemAttributeTest.php delete mode 100755 tests/Models/NullItemAttributeTypeTest.php delete mode 100755 tests/Models/NullItemAttributeValueTest.php diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 34a31c5..419fd16 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -21,8 +21,11 @@ use Modules\Billing\Models\SalesBillMapper; use Modules\ItemManagement\Models\ItemAttributeTypeMapper; use Modules\ItemManagement\Models\ItemAttributeValueMapper; use Modules\ItemManagement\Models\ItemMapper; +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; @@ -349,6 +352,33 @@ final class BackendController extends Controller $view->addData('item', $item); + // 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(ItemMapper::HAS_MANY['files']['external'], 'file') + ->from(ItemMapper::TABLE) + ->leftJoin(ItemMapper::HAS_MANY['files']['table']) + ->on(ItemMapper::HAS_MANY['files']['table'] . '.' . ItemMapper::HAS_MANY['files']['self'], '=', ItemMapper::TABLE . '.' . ItemMapper::PRIMARYFIELD) + ->leftJoin(MediaMapper::TABLE) + ->on(ItemMapper::HAS_MANY['files']['table'] . '.' . ItemMapper::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(ItemMapper::HAS_MANY['files']['self'], '=', $item->getId()) + ->where(MediaTypeMapper::TABLE . '.' . MediaTypeMapper::getColumnByMember('name'), '=', 'item_profile_image'); + + $itemImage = MediaMapper::get() + ->with('types') + ->where('id', $results) + ->limit(1) + ->execute(); + + $view->addData('itemImage', $itemImage); + /** @var \Model\Setting $settings */ $settings = $this->app->appSettings->get(null, [ SettingsEnum::DEFAULT_LOCALIZATION, diff --git a/Theme/Backend/Lang/de.lang.php b/Theme/Backend/Lang/de.lang.php index ee8462a..f889dfe 100755 --- a/Theme/Backend/Lang/de.lang.php +++ b/Theme/Backend/Lang/de.lang.php @@ -83,7 +83,7 @@ return ['ItemManagement' => [ 'Name3' => 'Name3.', 'Name4' => 'Name4.', 'Name5' => 'Name5.', - 'Net' => 'Reingewicht', + 'Net' => 'Netto', 'NetWeight' => 'Reingewicht', 'None' => 'Keiner', 'Notes' => 'Anmerkungen', diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index ae181f9..79ffcdc 100755 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -83,7 +83,7 @@ return ['ItemManagement' => [ 'Name3' => 'Name3', 'Name4' => 'Name4', 'Name5' => 'Name5', - 'Net' => 'Net Weight', + 'Net' => 'Net', 'NetWeight' => 'Net Weight', 'None' => 'None', 'Notes' => 'Notes', diff --git a/Theme/Backend/item-profile.tpl.php b/Theme/Backend/item-profile.tpl.php index cb587a3..82b61eb 100755 --- a/Theme/Backend/item-profile.tpl.php +++ b/Theme/Backend/item-profile.tpl.php @@ -26,6 +26,7 @@ $Attribute = $item->getAttributes(); $notes = $item->getNotes(); $files = $item->getFiles(); +$itemImage = $this->getData('itemImage') ?? new NullMedia(); $newestInvoices = $this->getData('newestInvoices') ?? []; $allInvoices = $this->getData('allInvoices') ?? []; @@ -86,13 +87,13 @@ echo $this->getData('nav')->render(); - getFileByTypeName('item_profile_image'); ?> +
<?= $this->printHtml($image->name); ?> + src="getPath()); ?>">
diff --git a/tests/Controller/Api/ApiControllerAttributeTrait.php b/tests/Controller/Api/ApiControllerAttributeTrait.php index 50a3e9c..ba3e1ff 100755 --- a/tests/Controller/Api/ApiControllerAttributeTrait.php +++ b/tests/Controller/Api/ApiControllerAttributeTrait.php @@ -74,7 +74,7 @@ trait ApiControllerAttributeTrait $request->setData('title', 'EN:1'); $request->setData('language', ISO639x1Enum::_EN); - $this->module->apiAttributeTypeCreate($request, $response); + $this->module->apiItemAttributeTypeCreate($request, $response); self::assertGreaterThan(0, $response->get('')['response']->getId()); } @@ -92,7 +92,7 @@ trait ApiControllerAttributeTrait $request->setData('type', '1'); $request->setData('language', ISO639x1Enum::_DE); - $this->module->apiAttributeTypeL11nCreate($request, $response); + $this->module->apiItemAttributeTypeL11nCreate($request, $response); self::assertGreaterThan(0, $response->get('')['response']->getId()); } @@ -219,7 +219,7 @@ trait ApiControllerAttributeTrait $request->header->account = 1; $request->setData('invalid', '1'); - $this->module->apiAttributeTypeCreate($request, $response); + $this->module->apiItemAttributeTypeCreate($request, $response); self::assertEquals(RequestStatusCode::R_400, $response->header->status); } @@ -235,7 +235,7 @@ trait ApiControllerAttributeTrait $request->header->account = 1; $request->setData('invalid', '1'); - $this->module->apiAttributeTypeL11nCreate($request, $response); + $this->module->apiItemAttributeTypeL11nCreate($request, $response); self::assertEquals(RequestStatusCode::R_400, $response->header->status); } diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index 8e2d753..7d6050f 100755 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -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); diff --git a/tests/Models/ItemAttributeTest.php b/tests/Models/ItemAttributeTest.php deleted file mode 100755 index 8a31279..0000000 --- a/tests/Models/ItemAttributeTest.php +++ /dev/null @@ -1,61 +0,0 @@ -attr = new Attribute(); - } - - /** - * @covers Modules\Attribute\Models\Attribute - * @group module - */ - public function testDefault() : void - { - self::assertEquals(0, $this->attr->getId()); - self::assertInstanceOf('Modules\Attribute\Models\AttributeType', $this->attr->type); - self::assertInstanceOf('Modules\Attribute\Models\AttributeValue', $this->attr->value); - } - - /** - * @covers Modules\Attribute\Models\Attribute - * @group module - */ - public function testSerialize() : void - { - self::assertEquals( - [ - 'id', - 'item', - 'type', - 'value', - ], - \array_keys($this->attr->jsonSerialize()) - ); - } -} diff --git a/tests/Models/ItemAttributeTypeTest.php b/tests/Models/ItemAttributeTypeTest.php deleted file mode 100755 index 64237a1..0000000 --- a/tests/Models/ItemAttributeTypeTest.php +++ /dev/null @@ -1,84 +0,0 @@ -attr = new AttributeType(); - } - - /** - * @covers Modules\Attribute\Models\AttributeType - * @group module - */ - public function testDefault() : void - { - self::assertEquals(0, $this->attr->getId()); - self::assertEquals('', $this->attr->name); - self::assertEquals('', $this->attr->validationPattern); - self::assertFalse($this->attr->custom); - self::assertFalse($this->attr->isRequired); - self::assertEquals('', $this->attr->getL11n()); - } - - /** - * @covers Modules\Attribute\Models\AttributeType - * @group module - */ - public function testL11nInputOutput() : void - { - $this->attr->setL11n('Test'); - self::assertEquals('Test', $this->attr->getL11n()); - - $this->attr->setL11n(new BaseStringL11n('NewTest')); - self::assertEquals('NewTest', $this->attr->getL11n()); - } - - /** - * @covers Modules\Attribute\Models\AttributeType - * @group module - */ - public function testSerialize() : void - { - $this->attr->name = 'Test'; - $this->attr->validationPattern = 'Pattern'; - $this->attr->custom = true; - $this->attr->isRequired = true; - - self::assertEquals( - [ - 'id' => 0, - 'name' => 'Test', - 'validationPattern' => 'Pattern', - 'custom' => true, - 'isRequired' => true, - ], - $this->attr->jsonSerialize() - ); - } -} diff --git a/tests/Models/ItemAttributeValueTest.php b/tests/Models/ItemAttributeValueTest.php deleted file mode 100755 index e0a3e3c..0000000 --- a/tests/Models/ItemAttributeValueTest.php +++ /dev/null @@ -1,108 +0,0 @@ -value = new AttributeValue(); - } - - /** - * @covers Modules\Attribute\Models\AttributeValue - * @group module - */ - public function testDefault() : void - { - self::assertEquals(0, $this->value->getId()); - self::assertNull($this->value->getValue()); - self::assertFalse($this->value->isDefault); - } - - /** - * @covers Modules\Attribute\Models\AttributeValue - * @group module - */ - public function testValueIntInputOutput() : void - { - $this->value->setValue(1, AttributeValueType::_INT); - self::assertEquals(1, $this->value->getValue()); - } - - /** - * @covers Modules\Attribute\Models\AttributeValue - * @group module - */ - public function testValueFloatInputOutput() : void - { - $this->value->setValue(1.1, AttributeValueType::_FLOAT); - self::assertEquals(1.1, $this->value->getValue()); - } - - /** - * @covers Modules\Attribute\Models\AttributeValue - * @group module - */ - public function testValueStringInputOutput() : void - { - $this->value->setValue('test', AttributeValueType::_STRING); - self::assertEquals('test', $this->value->getValue()); - } - - /** - * @covers Modules\Attribute\Models\AttributeValue - * @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\Attribute\Models\AttributeValue - * @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() - ); - } -} diff --git a/tests/Models/NullItemAttributeTest.php b/tests/Models/NullItemAttributeTest.php deleted file mode 100755 index ac60c00..0000000 --- a/tests/Models/NullItemAttributeTest.php +++ /dev/null @@ -1,42 +0,0 @@ -getId()); - } -} diff --git a/tests/Models/NullItemAttributeTypeTest.php b/tests/Models/NullItemAttributeTypeTest.php deleted file mode 100755 index 4080430..0000000 --- a/tests/Models/NullItemAttributeTypeTest.php +++ /dev/null @@ -1,42 +0,0 @@ -getId()); - } -} diff --git a/tests/Models/NullItemAttributeValueTest.php b/tests/Models/NullItemAttributeValueTest.php deleted file mode 100755 index bc04711..0000000 --- a/tests/Models/NullItemAttributeValueTest.php +++ /dev/null @@ -1,42 +0,0 @@ -getId()); - } -}