From bd4bceb3451efc4cb488cb6d985ff69fcb18994c Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Thu, 11 Jul 2024 21:27:55 +0300 Subject: [PATCH 01/22] OXDEV-8462 Add admin controller example --- menu.xml | 10 +++ metadata.php | 3 +- .../Admin/GreetingAdminController.php | 29 +++++++++ src/Core/Module.php | 2 + .../Admin/GreetingAdminControllerTest.php | 61 +++++++++++++++++++ views/admin_twig/de/module_options.php | 7 +++ views/admin_twig/en/module_options.php | 7 +++ views/twig/admin/user_greetings.html.twig | 19 ++++++ 8 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 menu.xml create mode 100644 src/Controller/Admin/GreetingAdminController.php create mode 100644 tests/Integration/Controller/Admin/GreetingAdminControllerTest.php create mode 100644 views/twig/admin/user_greetings.html.twig diff --git a/menu.xml b/menu.xml new file mode 100644 index 0000000..09d989c --- /dev/null +++ b/menu.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/metadata.php b/metadata.php index 6420cdb..29c4b4f 100644 --- a/metadata.php +++ b/metadata.php @@ -28,7 +28,8 @@ \OxidEsales\Eshop\Application\Model\Basket::class => \OxidEsales\ModuleTemplate\Model\Basket::class ], 'controllers' => [ - 'oemtgreeting' => \OxidEsales\ModuleTemplate\Controller\GreetingController::class + 'oemtgreeting' => \OxidEsales\ModuleTemplate\Controller\GreetingController::class, + 'oemt_admin_greeting' => \OxidEsales\ModuleTemplate\Controller\Admin\GreetingAdminController::class, ], 'templates' => [ '@oe_moduletemplate/templates/greetingtemplate.tpl' => 'views/smarty/templates/greetingtemplate.tpl', diff --git a/src/Controller/Admin/GreetingAdminController.php b/src/Controller/Admin/GreetingAdminController.php new file mode 100644 index 0000000..5fca419 --- /dev/null +++ b/src/Controller/Admin/GreetingAdminController.php @@ -0,0 +1,29 @@ +load($this->getEditObjectId())) { + $this->addTplParam(ModuleCore::OEMT_ADMIN_GREETING_TEMPLATE_VARNAME, $oUser->getPersonalGreeting()); + } + + return parent::render(); + } +} \ No newline at end of file diff --git a/src/Core/Module.php b/src/Core/Module.php index fd95178..64cf660 100644 --- a/src/Core/Module.php +++ b/src/Core/Module.php @@ -18,4 +18,6 @@ final class Module public const OEMT_COUNTER_TEMPLATE_VARNAME = 'oemt_greeting_counter'; public const DEFAULT_PERSONAL_GREETING_LANGUAGE_CONST = 'OEMODULETEMPLATE_GREETING_GENERIC'; + + public const OEMT_ADMIN_GREETING_TEMPLATE_VARNAME = 'greeting_message'; } diff --git a/tests/Integration/Controller/Admin/GreetingAdminControllerTest.php b/tests/Integration/Controller/Admin/GreetingAdminControllerTest.php new file mode 100644 index 0000000..a7e1854 --- /dev/null +++ b/tests/Integration/Controller/Admin/GreetingAdminControllerTest.php @@ -0,0 +1,61 @@ +createTestUser(); + + $controller = oxNew(GreetingAdminController::class); + $controller->setEditObjectId(self::TEST_USER_ID); + + $this->assertSame('@oe_moduletemplate/admin/user_greetings', $controller->render()); + + $viewData = $controller->getViewData(); + + $this->assertSame(self::TEST_GREETING, $viewData[ModuleCore::OEMT_ADMIN_GREETING_TEMPLATE_VARNAME]); + } + + private function createTestUser(): void + { + $user = oxNew(EshopModelUser::class); + $user->assign( + [ + 'oxid' => self::TEST_USER_ID, + 'oemtgreeting' => self::TEST_GREETING, + ] + ); + $user->save(); + } +} diff --git a/views/admin_twig/de/module_options.php b/views/admin_twig/de/module_options.php index e9e60fe..68524f3 100644 --- a/views/admin_twig/de/module_options.php +++ b/views/admin_twig/de/module_options.php @@ -9,6 +9,13 @@ $aLang = [ 'charset' => 'UTF-8', + 'tbcluser_greetings' => 'Greetings', + + 'OEMODULETEMPLATE_GREETING_TITLE' => 'Admin controller example', + 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', + 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', + + # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Einstellungen', 'SHOP_MODULE_oemoduletemplate_GreetingMode' => 'Begrüßungsmodus', 'SHOP_MODULE_oemoduletemplate_GreetingMode_generic' => 'höflich', diff --git a/views/admin_twig/en/module_options.php b/views/admin_twig/en/module_options.php index 80de61c..79c881e 100644 --- a/views/admin_twig/en/module_options.php +++ b/views/admin_twig/en/module_options.php @@ -9,6 +9,13 @@ $aLang = [ 'charset' => 'UTF-8', + 'tbcluser_greetings' => 'Greetings', + + 'OEMODULETEMPLATE_GREETING_TITLE' => 'Admin controller example', + 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', + 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', + + # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Settings', 'SHOP_MODULE_oemoduletemplate_GreetingMode' => 'Greeting mode', 'SHOP_MODULE_oemoduletemplate_GreetingMode_generic' => 'generic', diff --git a/views/twig/admin/user_greetings.html.twig b/views/twig/admin/user_greetings.html.twig new file mode 100644 index 0000000..14e2d9d --- /dev/null +++ b/views/twig/admin/user_greetings.html.twig @@ -0,0 +1,19 @@ +{% include "headitem.html.twig" with {title: "GENERAL_ADMIN_TITLE"|translate} %} + +
+ {{ oViewConf.getHiddenSid()|raw }} + + +
+ +

{{ translate({ ident: "OEMODULETEMPLATE_GREETING_TITLE" }) }}

+ +{% if greeting_message %} +
{{ translate({ ident: "OEMODULETEMPLATE_GREETING_MESSAGE_TEXT" }) }} {{ greeting_message }}
+{% else %} +
{{ translate({ ident: "OEMODULETEMPLATE_NO_GREETING_TEXT" }) }}
+{% endif %} + + +{% include "bottomnaviitem.html.twig" %} +{% include "bottomitem.html.twig" %} From fec7b49d68cd00e0e94babdcb598a70e10e59880 Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Fri, 12 Jul 2024 12:39:45 +0300 Subject: [PATCH 02/22] OXDEV-8462 Add example of extending admin template --- .../Acceptance/Admin/GreetingAdminCest.php | 66 +++++++++++++++++++ tests/Codeception/Acceptance/GreetingCest.php | 2 +- tests/Codeception/Acceptance/ModuleCest.php | 2 +- .../Acceptance/UpdateGreetingCest.php | 2 +- tests/Codeception/_data/fixtures.php | 5 ++ tests/Codeception/_data/fixtures.sql | 3 +- .../Codeception/_support/AcceptanceTester.php | 17 +++++ tests/Codeception/acceptance.suite.yml | 4 ++ views/admin_twig/de/module_options.php | 2 + views/admin_twig/en/module_options.php | 2 + .../themes/admin_twig/user_main.html.twig | 16 +++++ .../themes/apex/page/shop/start.html.twig | 6 +- .../twig/templates/greetingtemplate.html.twig | 2 +- 13 files changed, 120 insertions(+), 9 deletions(-) create mode 100644 tests/Codeception/Acceptance/Admin/GreetingAdminCest.php create mode 100644 views/twig/extensions/themes/admin_twig/user_main.html.twig diff --git a/tests/Codeception/Acceptance/Admin/GreetingAdminCest.php b/tests/Codeception/Acceptance/Admin/GreetingAdminCest.php new file mode 100644 index 0000000..c0c6b57 --- /dev/null +++ b/tests/Codeception/Acceptance/Admin/GreetingAdminCest.php @@ -0,0 +1,66 @@ +setGreetingModeGeneric(); + $this->setUserPersonalGreeting($I, 'Hello there!'); + } + + public function _after(AcceptanceTester $I): void + { + //clean up after each test + $I->setGreetingModeGeneric(); + } + + /** @param AcceptanceTester $I */ + public function seeGreetingOptionsForUser(AcceptanceTester $I): void + { + $I->openAdmin(); + $adminPage = $I->loginAdmin(); + + $userList = $adminPage->openUsers(); + $userList->find("where[oxuser][oxusername]", $I->getDemoUserName()); + + $I->selectEditFrame(); + $I->see(Translator::translate('OEMODULETEMPLATE_ALLOW_GREETING')); + + $I->selectListFrame(); + $I->click(Translator::translate('tbcluser_greetings')); + + $I->selectEditFrame(); + $I->see(Translator::translate('OEMODULETEMPLATE_GREETING_TITLE')); + $I->see('Hello there!'); + } + + private function setUserPersonalGreeting(AcceptanceTester $I, string $value = ''): void + { + $I->updateInDatabase( + 'oxuser', + [ + 'oemtgreeting' => $value, + ], + [ + 'oxusername' => $I->getDemoUserName(), + ] + ); + } +} diff --git a/tests/Codeception/Acceptance/GreetingCest.php b/tests/Codeception/Acceptance/GreetingCest.php index 51587ef..d46740d 100644 --- a/tests/Codeception/Acceptance/GreetingCest.php +++ b/tests/Codeception/Acceptance/GreetingCest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace OxidEsales\ModuleTemplate\Tests\Codeception\Helper; +namespace OxidEsales\ModuleTemplate\Tests\Codeception\Acceptance; use OxidEsales\Codeception\Module\Translation\Translator; use OxidEsales\ModuleTemplate\Tests\Codeception\AcceptanceTester; diff --git a/tests/Codeception/Acceptance/ModuleCest.php b/tests/Codeception/Acceptance/ModuleCest.php index 5bb1944..4c4d433 100644 --- a/tests/Codeception/Acceptance/ModuleCest.php +++ b/tests/Codeception/Acceptance/ModuleCest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace OxidEsales\ModuleTemplate\Tests\Codeception\Helper; +namespace OxidEsales\ModuleTemplate\Tests\Codeception\Acceptance; use OxidEsales\Codeception\Module\Translation\Translator; use OxidEsales\ModuleTemplate\Core\Module; diff --git a/tests/Codeception/Acceptance/UpdateGreetingCest.php b/tests/Codeception/Acceptance/UpdateGreetingCest.php index aadc490..7c4da42 100644 --- a/tests/Codeception/Acceptance/UpdateGreetingCest.php +++ b/tests/Codeception/Acceptance/UpdateGreetingCest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace OxidEsales\ModuleTemplate\Tests\Codeception\Helper; +namespace OxidEsales\ModuleTemplate\Tests\Codeception\Acceptance; use OxidEsales\Codeception\Module\Translation\Translator; use OxidEsales\ModuleTemplate\Core\Module as ModuleCore; diff --git a/tests/Codeception/_data/fixtures.php b/tests/Codeception/_data/fixtures.php index f0a0ec2..8203c99 100644 --- a/tests/Codeception/_data/fixtures.php +++ b/tests/Codeception/_data/fixtures.php @@ -13,4 +13,9 @@ 'email' => 'user@oxid-esales.com', 'password' => 'useruser', ], + 'adminUser' => [ + 'OXID' => 'oxadminuser', + 'email' => 'admin@oxid-esales.com', + 'password' => 'useruser', + ], ]; diff --git a/tests/Codeception/_data/fixtures.sql b/tests/Codeception/_data/fixtures.sql index b46ea9b..f0c7152 100644 --- a/tests/Codeception/_data/fixtures.sql +++ b/tests/Codeception/_data/fixtures.sql @@ -1,3 +1,4 @@ #Add default user REPLACE INTO `oxuser` (`OXID`, `OXACTIVE`, `OXRIGHTS`, `OXSHOPID`, `OXUSERNAME`, `OXPASSWORD`, `OXPASSSALT`, `OXCREATE`, `OXREGISTER`, `OXTIMESTAMP`, `OXBIRTHDATE`) VALUES -('oxdefaultuser',1,'user',1,'user@oxid-esales.com','$2y$10$ljaDXMPHOyC7ELlnC5ErK.3ET4B0oAN3WVr/Tk.RKlUfiuBcQEVVC','', '2003-01-01 00:00:00', '2003-01-01 00:00:00', '2003-01-01 00:00:00', '1985-01-01'); +('oxdefaultuser',1,'user',1,'user@oxid-esales.com','$2y$10$ljaDXMPHOyC7ELlnC5ErK.3ET4B0oAN3WVr/Tk.RKlUfiuBcQEVVC','', '2003-01-01 00:00:00', '2003-01-01 00:00:00', '2003-01-01 00:00:00', '1985-01-01'), +('oxadminuser',1,'malladmin',1,'admin@oxid-esales.com','$2y$10$ljaDXMPHOyC7ELlnC5ErK.3ET4B0oAN3WVr/Tk.RKlUfiuBcQEVVC','', '2003-01-01 00:00:00', '2003-01-01 00:00:00', '2003-01-01 00:00:00', '1985-01-01'); diff --git a/tests/Codeception/_support/AcceptanceTester.php b/tests/Codeception/_support/AcceptanceTester.php index bbd9db3..0b3f26a 100644 --- a/tests/Codeception/_support/AcceptanceTester.php +++ b/tests/Codeception/_support/AcceptanceTester.php @@ -10,6 +10,8 @@ namespace OxidEsales\ModuleTemplate\Tests\Codeception; use Codeception\Util\Fixtures; +use OxidEsales\Codeception\Admin\AdminLoginPage; +use OxidEsales\Codeception\Admin\AdminPanel; use OxidEsales\Codeception\Page\Home; use OxidEsales\Facts\Facts; use OxidEsales\ModuleTemplate\Service\ModuleSettings; @@ -91,6 +93,21 @@ public function getShopUrl(): string return $facts->getShopUrl(); } + public function openAdmin(): AdminLoginPage + { + $I = $this; + $adminLogin = new AdminLoginPage($I); + $I->amOnPage($adminLogin->URL); + return $adminLogin; + } + + public function loginAdmin(): AdminPanel + { + $adminPage = $this->openAdmin(); + $admin = Fixtures::get('adminUser'); + return $adminPage->login($admin['email'], $admin['password']); + } + protected function getServiceFromContainer(string $serviceName) { return ContainerFactory::getInstance() diff --git a/tests/Codeception/acceptance.suite.yml b/tests/Codeception/acceptance.suite.yml index 4f81b98..8c034c6 100644 --- a/tests/Codeception/acceptance.suite.yml +++ b/tests/Codeception/acceptance.suite.yml @@ -35,6 +35,10 @@ modules: depends: - WebDriver - Db + - \OxidEsales\Codeception\Module\OxideshopAdmin: + depends: + - WebDriver + - \OxidEsales\Codeception\Module\Oxideshop - \OxidEsales\Codeception\Module\Database: depends: Db - \OxidEsales\Codeception\Module\SelectTheme: diff --git a/views/admin_twig/de/module_options.php b/views/admin_twig/de/module_options.php index 68524f3..0f6c739 100644 --- a/views/admin_twig/de/module_options.php +++ b/views/admin_twig/de/module_options.php @@ -14,6 +14,8 @@ 'OEMODULETEMPLATE_GREETING_TITLE' => 'Admin controller example', 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', + 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Allow user to set greeting', + 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Example of extending admin template', # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Einstellungen', diff --git a/views/admin_twig/en/module_options.php b/views/admin_twig/en/module_options.php index 79c881e..3d3091a 100644 --- a/views/admin_twig/en/module_options.php +++ b/views/admin_twig/en/module_options.php @@ -14,6 +14,8 @@ 'OEMODULETEMPLATE_GREETING_TITLE' => 'Admin controller example', 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', + 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Allow user to set greeting', + 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Example of extending admin template', # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Settings', diff --git a/views/twig/extensions/themes/admin_twig/user_main.html.twig b/views/twig/extensions/themes/admin_twig/user_main.html.twig new file mode 100644 index 0000000..5c25b7d --- /dev/null +++ b/views/twig/extensions/themes/admin_twig/user_main.html.twig @@ -0,0 +1,16 @@ +{% extends 'user_main.html.twig' %} + +{% block admin_user_main_form %} + + + + {{ translate({ ident: "OEMODULETEMPLATE_ALLOW_GREETING" }) }} + + + + {% include "inputhelp.html.twig" with {'sHelpId': help_id("OEMODULETEMPLATE_HELP_ALLOW_GREETING"), 'sHelpText': help_text("OEMODULETEMPLATE_HELP_ALLOW_GREETING")} %} + + + + {{ parent() }} +{% endblock %} \ No newline at end of file diff --git a/views/twig/extensions/themes/apex/page/shop/start.html.twig b/views/twig/extensions/themes/apex/page/shop/start.html.twig index 885cc70..652e75e 100644 --- a/views/twig/extensions/themes/apex/page/shop/start.html.twig +++ b/views/twig/extensions/themes/apex/page/shop/start.html.twig @@ -7,10 +7,8 @@ {{ oView.getOemtGreeting() }} {% if oView.canUpdateOemtGreeting() %} - + + {{ translate({ ident: "OEMODULETEMPLATE_GREETING_UPDATE" }) }} {% endif %}

diff --git a/views/twig/templates/greetingtemplate.html.twig b/views/twig/templates/greetingtemplate.html.twig index 07b6612..b485c63 100644 --- a/views/twig/templates/greetingtemplate.html.twig +++ b/views/twig/templates/greetingtemplate.html.twig @@ -4,7 +4,7 @@
From cdd8779bc3a52a7dd101038e8d8d968c8914a796 Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Fri, 12 Jul 2024 14:39:48 +0300 Subject: [PATCH 03/22] OXDEV-8462 Add smarty admin template and extension --- metadata.php | 6 ++++++ .../blocks/admin/admin_user_main_form.tpl | 11 +++++++++++ .../smarty/templates/admin/user_greetings.tpl | 18 ++++++++++++++++++ views/twig/admin/user_greetings.html.twig | 3 +-- 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 views/smarty/blocks/admin/admin_user_main_form.tpl create mode 100644 views/smarty/templates/admin/user_greetings.tpl diff --git a/metadata.php b/metadata.php index 29c4b4f..8dbe812 100644 --- a/metadata.php +++ b/metadata.php @@ -33,6 +33,7 @@ ], 'templates' => [ '@oe_moduletemplate/templates/greetingtemplate.tpl' => 'views/smarty/templates/greetingtemplate.tpl', + '@oe_moduletemplate/templates/admin/user_greetings.tpl' => 'views/smarty/templates/admin/user_greetings.tpl', ], 'events' => [ 'onActivate' => '\OxidEsales\ModuleTemplate\Core\ModuleEvents::onActivate', @@ -44,6 +45,11 @@ 'template' => 'page/shop/start.tpl', 'block' => 'start_welcome_text', 'file' => 'views/smarty/blocks/oemt_start_welcome_text.tpl' + ], + [ + 'template' => 'user_main.tpl', + 'block' => 'admin_user_main_form', + 'file' => 'views/smarty/blocks/admin/admin_user_main_form.tpl' ] ], 'settings' => [ diff --git a/views/smarty/blocks/admin/admin_user_main_form.tpl b/views/smarty/blocks/admin/admin_user_main_form.tpl new file mode 100644 index 0000000..a33c590 --- /dev/null +++ b/views/smarty/blocks/admin/admin_user_main_form.tpl @@ -0,0 +1,11 @@ + + + [{oxmultilang ident="OEMODULETEMPLATE_ALLOW_GREETING"}] + + + + [{oxinputhelp ident="OEMODULETEMPLATE_HELP_ALLOW_GREETING"}] + + + +[{$smarty.block.parent}] \ No newline at end of file diff --git a/views/smarty/templates/admin/user_greetings.tpl b/views/smarty/templates/admin/user_greetings.tpl new file mode 100644 index 0000000..c61e5dc --- /dev/null +++ b/views/smarty/templates/admin/user_greetings.tpl @@ -0,0 +1,18 @@ +[{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign box="list"}] + + + [{$oViewConf->getHiddenSid()}] + + + + +

[{oxmultilang ident="OEMODULETEMPLATE_GREETING_TITLE"}]

+ +[{if $greeting_message}] +
[{oxmultilang ident="OEMODULETEMPLATE_GREETING_MESSAGE_TEXT"}] [{$greeting_message}]
+[{else}] +
[{oxmultilang ident="OEMODULETEMPLATE_NO_GREETING_TEXT"}]
+[{/if}] + +[{include file="bottomnaviitem.tpl"}] +[{include file="bottomitem.tpl"}] diff --git a/views/twig/admin/user_greetings.html.twig b/views/twig/admin/user_greetings.html.twig index 14e2d9d..15ce786 100644 --- a/views/twig/admin/user_greetings.html.twig +++ b/views/twig/admin/user_greetings.html.twig @@ -1,6 +1,6 @@ {% include "headitem.html.twig" with {title: "GENERAL_ADMIN_TITLE"|translate} %} -
+ {{ oViewConf.getHiddenSid()|raw }} @@ -14,6 +14,5 @@
{{ translate({ ident: "OEMODULETEMPLATE_NO_GREETING_TEXT" }) }}
{% endif %} - {% include "bottomnaviitem.html.twig" %} {% include "bottomitem.html.twig" %} From fc9523ca646ac41a04d0356d0f80d00633a329e1 Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Fri, 12 Jul 2024 14:52:46 +0300 Subject: [PATCH 04/22] OXDEV-8462 Add oxnew factory example --- services.yaml | 5 +++- .../Admin/GreetingAdminController.php | 2 +- src/Infrastructure/CoreRequestFactory.php | 23 +++++++++++++++ .../CoreRequestFactoryInterface.php | 18 ++++++++++++ src/Service/GreetingMessage.php | 13 +++++---- .../Service/GreetingMessageTest.php | 10 +++---- .../Infrastructure/CoreRequestFactoryTest.php | 29 +++++++++++++++++++ tests/Unit/Service/GreetingMessageTest.php | 3 +- 8 files changed, 89 insertions(+), 14 deletions(-) create mode 100644 src/Infrastructure/CoreRequestFactory.php create mode 100644 src/Infrastructure/CoreRequestFactoryInterface.php create mode 100644 tests/Unit/Infrastructure/CoreRequestFactoryTest.php diff --git a/services.yaml b/services.yaml index b50ad33..6b9e62f 100644 --- a/services.yaml +++ b/services.yaml @@ -44,4 +44,7 @@ services: OxidEsales\ModuleTemplate\Subscriber\BeforeModelUpdate: class: OxidEsales\ModuleTemplate\Subscriber\BeforeModelUpdate - tags: [ 'kernel.event_subscriber' ] \ No newline at end of file + tags: [ 'kernel.event_subscriber' ] + + OxidEsales\ModuleTemplate\Infrastructure\CoreRequestFactoryInterface: + class: OxidEsales\ModuleTemplate\Infrastructure\CoreRequestFactory \ No newline at end of file diff --git a/src/Controller/Admin/GreetingAdminController.php b/src/Controller/Admin/GreetingAdminController.php index 5fca419..88ad2c1 100644 --- a/src/Controller/Admin/GreetingAdminController.php +++ b/src/Controller/Admin/GreetingAdminController.php @@ -26,4 +26,4 @@ public function render() return parent::render(); } -} \ No newline at end of file +} diff --git a/src/Infrastructure/CoreRequestFactory.php b/src/Infrastructure/CoreRequestFactory.php new file mode 100644 index 0000000..30a2211 --- /dev/null +++ b/src/Infrastructure/CoreRequestFactory.php @@ -0,0 +1,23 @@ +settings = $settings; - $this->request = $request; + $this->coreRequestFactory = $coreRequestFactory; } public function getGreeting(?EshopModelUser $user = null): string @@ -59,7 +59,8 @@ public function saveGreeting(EshopModelUser $user): bool private function getRequestOemtGreeting(): string { - $input = (string)$this->request->getRequestParameter(ModuleCore::OEMT_GREETING_TEMPLATE_VARNAME); + $coreRequestService = $this->coreRequestFactory->create(); + $input = (string)$coreRequestService->getRequestParameter(ModuleCore::OEMT_GREETING_TEMPLATE_VARNAME); //in real life add some input validation return (string)substr($input, 0, 253); diff --git a/tests/Integration/Service/GreetingMessageTest.php b/tests/Integration/Service/GreetingMessageTest.php index c6fa721..a31bedf 100644 --- a/tests/Integration/Service/GreetingMessageTest.php +++ b/tests/Integration/Service/GreetingMessageTest.php @@ -10,8 +10,8 @@ namespace OxidEsales\ModuleTemplate\Tests\Integration\Service; use OxidEsales\Eshop\Application\Model\User as EshopModelUser; -use OxidEsales\Eshop\Core\Request as CoreRequest; use OxidEsales\ModuleTemplate\Core\Module as ModuleCore; +use OxidEsales\ModuleTemplate\Infrastructure\CoreRequestFactoryInterface; use OxidEsales\ModuleTemplate\Service\GreetingMessage; use OxidEsales\ModuleTemplate\Service\ModuleSettings; use OxidEsales\ModuleTemplate\Tests\Integration\IntegrationTestCase; @@ -22,7 +22,7 @@ public function testModuleGenericGreetingModeEmptyUser(): void { $service = new GreetingMessage( $this->getSettingsMock(ModuleSettings::GREETING_MODE_GENERIC), - oxNew(CoreRequest::class) + $this->createMock(CoreRequestFactoryInterface::class) ); $user = oxNew(EshopModelUser::class); @@ -33,7 +33,7 @@ public function testModulePersonalGreetingModeEmptyUser(): void { $service = new GreetingMessage( $this->getSettingsMock(), - oxNew(CoreRequest::class) + $this->createMock(CoreRequestFactoryInterface::class) ); $user = oxNew(EshopModelUser::class); @@ -44,7 +44,7 @@ public function testModuleGenericGreeting(): void { $service = new GreetingMessage( $this->getSettingsMock(ModuleSettings::GREETING_MODE_GENERIC), - oxNew(CoreRequest::class) + $this->createMock(CoreRequestFactoryInterface::class) ); $user = oxNew(EshopModelUser::class); $user->setPersonalGreeting('Hi sweetie!'); @@ -56,7 +56,7 @@ public function testModulePersonalGreeting(): void { $service = new GreetingMessage( $this->getSettingsMock(), - oxNew(CoreRequest::class) + $this->createMock(CoreRequestFactoryInterface::class) ); $user = oxNew(EshopModelUser::class); $user->setPersonalGreeting('Hi sweetie!'); diff --git a/tests/Unit/Infrastructure/CoreRequestFactoryTest.php b/tests/Unit/Infrastructure/CoreRequestFactoryTest.php new file mode 100644 index 0000000..859264d --- /dev/null +++ b/tests/Unit/Infrastructure/CoreRequestFactoryTest.php @@ -0,0 +1,29 @@ +getMockBuilder(CoreRequestFactory::class) + ->onlyMethods(['create']) + ->getMock(); + + $this->assertInstanceOf(Request::class, $coreThemeFactoryMock->create()); + } +} diff --git a/tests/Unit/Service/GreetingMessageTest.php b/tests/Unit/Service/GreetingMessageTest.php index 48058fd..d3b860a 100644 --- a/tests/Unit/Service/GreetingMessageTest.php +++ b/tests/Unit/Service/GreetingMessageTest.php @@ -11,6 +11,7 @@ use OxidEsales\Eshop\Core\Request as CoreRequest; use OxidEsales\ModuleTemplate\Core\Module as ModuleCore; +use OxidEsales\ModuleTemplate\Infrastructure\CoreRequestFactoryInterface; use OxidEsales\ModuleTemplate\Service\GreetingMessage; use OxidEsales\ModuleTemplate\Service\ModuleSettings; use PHPUnit\Framework\TestCase; @@ -24,7 +25,7 @@ public function testGenericGreetingNoUser(string $mode, string $expected): void { $service = new GreetingMessage( $this->createConfiguredMock(ModuleSettings::class, ['getGreetingMode' => $mode]), - $this->createStub(CoreRequest::class) + $this->createMock(CoreRequestFactoryInterface::class) ); $this->assertSame($expected, $service->getGreeting()); From 7297ff32806fa37dc81eccbe681307dd74e6cc17 Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Mon, 15 Jul 2024 13:37:11 +0300 Subject: [PATCH 05/22] OXDEV-8462 Add admin controller example --- menu.xml | 10 ++++ metadata.php | 3 +- src/Core/Module.php | 2 + .../Admin/GreetingAdminController.php | 29 +++++++++++ .../Admin/GreetingAdminControllerTest.php | 52 +++++++++++++++++++ views/admin_twig/de/module_options.php | 7 +++ views/admin_twig/en/module_options.php | 7 +++ views/twig/admin/user_greetings.html.twig | 18 +++++++ 8 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 menu.xml create mode 100644 src/Greeting/Controller/Admin/GreetingAdminController.php create mode 100644 tests/Integration/Greeting/Controller/Admin/GreetingAdminControllerTest.php create mode 100644 views/twig/admin/user_greetings.html.twig diff --git a/menu.xml b/menu.xml new file mode 100644 index 0000000..be2a624 --- /dev/null +++ b/menu.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/metadata.php b/metadata.php index 3fda7f7..0ede64c 100644 --- a/metadata.php +++ b/metadata.php @@ -28,7 +28,8 @@ \OxidEsales\Eshop\Application\Model\User::class => \OxidEsales\ModuleTemplate\Extension\Model\User::class, ], 'controllers' => [ - 'oemtgreeting' => \OxidEsales\ModuleTemplate\Greeting\Controller\GreetingController::class + 'oemtgreeting' => \OxidEsales\ModuleTemplate\Greeting\Controller\GreetingController::class, + 'oemt_admin_greeting' => \OxidEsales\ModuleTemplate\Greeting\Controller\Admin\GreetingAdminController::class, ], 'events' => [ 'onActivate' => '\OxidEsales\ModuleTemplate\Core\ModuleEvents::onActivate', diff --git a/src/Core/Module.php b/src/Core/Module.php index fd95178..64cf660 100644 --- a/src/Core/Module.php +++ b/src/Core/Module.php @@ -18,4 +18,6 @@ final class Module public const OEMT_COUNTER_TEMPLATE_VARNAME = 'oemt_greeting_counter'; public const DEFAULT_PERSONAL_GREETING_LANGUAGE_CONST = 'OEMODULETEMPLATE_GREETING_GENERIC'; + + public const OEMT_ADMIN_GREETING_TEMPLATE_VARNAME = 'greeting_message'; } diff --git a/src/Greeting/Controller/Admin/GreetingAdminController.php b/src/Greeting/Controller/Admin/GreetingAdminController.php new file mode 100644 index 0000000..adce9bc --- /dev/null +++ b/src/Greeting/Controller/Admin/GreetingAdminController.php @@ -0,0 +1,29 @@ +load($this->getEditObjectId())) { + $this->addTplParam(ModuleCore::OEMT_ADMIN_GREETING_TEMPLATE_VARNAME, $oUser->getPersonalGreeting()); + } + + return parent::render(); + } +} diff --git a/tests/Integration/Greeting/Controller/Admin/GreetingAdminControllerTest.php b/tests/Integration/Greeting/Controller/Admin/GreetingAdminControllerTest.php new file mode 100644 index 0000000..fb7e1bf --- /dev/null +++ b/tests/Integration/Greeting/Controller/Admin/GreetingAdminControllerTest.php @@ -0,0 +1,52 @@ +createTestUser(); + + $controller = oxNew(GreetingAdminController::class); + $controller->setEditObjectId(self::TEST_USER_ID); + + $this->assertSame('@oe_moduletemplate/admin/user_greetings', $controller->render()); + + $viewData = $controller->getViewData(); + + $this->assertSame(self::TEST_GREETING, $viewData[ModuleCore::OEMT_ADMIN_GREETING_TEMPLATE_VARNAME]); + } + + private function createTestUser(): void + { + $user = oxNew(EshopModelUser::class); + $user->assign( + [ + 'oxid' => self::TEST_USER_ID, + 'oemtgreeting' => self::TEST_GREETING, + ] + ); + $user->save(); + } +} diff --git a/views/admin_twig/de/module_options.php b/views/admin_twig/de/module_options.php index e9e60fe..68524f3 100644 --- a/views/admin_twig/de/module_options.php +++ b/views/admin_twig/de/module_options.php @@ -9,6 +9,13 @@ $aLang = [ 'charset' => 'UTF-8', + 'tbcluser_greetings' => 'Greetings', + + 'OEMODULETEMPLATE_GREETING_TITLE' => 'Admin controller example', + 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', + 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', + + # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Einstellungen', 'SHOP_MODULE_oemoduletemplate_GreetingMode' => 'Begrüßungsmodus', 'SHOP_MODULE_oemoduletemplate_GreetingMode_generic' => 'höflich', diff --git a/views/admin_twig/en/module_options.php b/views/admin_twig/en/module_options.php index 80de61c..79c881e 100644 --- a/views/admin_twig/en/module_options.php +++ b/views/admin_twig/en/module_options.php @@ -9,6 +9,13 @@ $aLang = [ 'charset' => 'UTF-8', + 'tbcluser_greetings' => 'Greetings', + + 'OEMODULETEMPLATE_GREETING_TITLE' => 'Admin controller example', + 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', + 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', + + # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Settings', 'SHOP_MODULE_oemoduletemplate_GreetingMode' => 'Greeting mode', 'SHOP_MODULE_oemoduletemplate_GreetingMode_generic' => 'generic', diff --git a/views/twig/admin/user_greetings.html.twig b/views/twig/admin/user_greetings.html.twig new file mode 100644 index 0000000..15ce786 --- /dev/null +++ b/views/twig/admin/user_greetings.html.twig @@ -0,0 +1,18 @@ +{% include "headitem.html.twig" with {title: "GENERAL_ADMIN_TITLE"|translate} %} + + + {{ oViewConf.getHiddenSid()|raw }} + + + + +

{{ translate({ ident: "OEMODULETEMPLATE_GREETING_TITLE" }) }}

+ +{% if greeting_message %} +
{{ translate({ ident: "OEMODULETEMPLATE_GREETING_MESSAGE_TEXT" }) }} {{ greeting_message }}
+{% else %} +
{{ translate({ ident: "OEMODULETEMPLATE_NO_GREETING_TEXT" }) }}
+{% endif %} + +{% include "bottomnaviitem.html.twig" %} +{% include "bottomitem.html.twig" %} From 2e29e3a43066b0d8811e8b1c1e13276806ddac8d Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Mon, 15 Jul 2024 14:29:28 +0300 Subject: [PATCH 06/22] OXDEV-8462 Add example of extending admin template --- tests/Codeception/Acceptance.suite.yml | 5 ++ .../Acceptance/Admin/GreetingAdminCest.php | 66 +++++++++++++++++++ tests/Codeception/Acceptance/GreetingCest.php | 2 +- tests/Codeception/Acceptance/ModuleCest.php | 2 +- .../Acceptance/UpdateGreetingCest.php | 2 +- .../Codeception/Support/AcceptanceTester.php | 17 +++++ tests/Codeception/Support/Data/fixtures.php | 5 ++ tests/Codeception/Support/Data/fixtures.sql | 3 +- views/admin_twig/de/module_options.php | 2 + views/admin_twig/en/module_options.php | 2 + .../themes/admin_twig/user_main.html.twig | 16 +++++ 11 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 tests/Codeception/Acceptance/Admin/GreetingAdminCest.php create mode 100644 views/twig/extensions/themes/admin_twig/user_main.html.twig diff --git a/tests/Codeception/Acceptance.suite.yml b/tests/Codeception/Acceptance.suite.yml index 4f81b98..8e58792 100644 --- a/tests/Codeception/Acceptance.suite.yml +++ b/tests/Codeception/Acceptance.suite.yml @@ -35,6 +35,11 @@ modules: depends: - WebDriver - Db + - \OxidEsales\Codeception\Module\OxideshopAdmin: + screen_shot_url: '%SCREEN_SHOT_URL%' + depends: + - WebDriver + - \OxidEsales\Codeception\Module\Oxideshop - \OxidEsales\Codeception\Module\Database: depends: Db - \OxidEsales\Codeception\Module\SelectTheme: diff --git a/tests/Codeception/Acceptance/Admin/GreetingAdminCest.php b/tests/Codeception/Acceptance/Admin/GreetingAdminCest.php new file mode 100644 index 0000000..6ae657a --- /dev/null +++ b/tests/Codeception/Acceptance/Admin/GreetingAdminCest.php @@ -0,0 +1,66 @@ +setGreetingModeGeneric(); + $this->setUserPersonalGreeting($I, 'Hello there!'); + } + + public function _after(AcceptanceTester $I): void + { + //clean up after each test + $I->setGreetingModeGeneric(); + } + + /** @param AcceptanceTester $I */ + public function seeGreetingOptionsForUser(AcceptanceTester $I): void + { + $I->openAdmin(); + $adminPage = $I->loginAdmin(); + + $userList = $adminPage->openUsers(); + $userList->find("where[oxuser][oxusername]", $I->getDemoUserName()); + + $I->selectEditFrame(); + $I->see(Translator::translate('OEMODULETEMPLATE_ALLOW_GREETING')); + + $I->selectListFrame(); + $I->click(Translator::translate('tbcluser_greetings')); + + $I->selectEditFrame(); + $I->see(Translator::translate('OEMODULETEMPLATE_GREETING_TITLE')); + $I->see('Hello there!'); + } + + private function setUserPersonalGreeting(AcceptanceTester $I, string $value = ''): void + { + $I->updateInDatabase( + 'oxuser', + [ + 'oemtgreeting' => $value, + ], + [ + 'oxusername' => $I->getDemoUserName(), + ] + ); + } +} diff --git a/tests/Codeception/Acceptance/GreetingCest.php b/tests/Codeception/Acceptance/GreetingCest.php index 8089231..0696853 100644 --- a/tests/Codeception/Acceptance/GreetingCest.php +++ b/tests/Codeception/Acceptance/GreetingCest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace OxidEsales\ModuleTemplate\Tests\Codeception\Helper; +namespace OxidEsales\ModuleTemplate\Tests\Codeception\Acceptance; use OxidEsales\Codeception\Module\Translation\Translator; use OxidEsales\ModuleTemplate\Tests\Codeception\Support\AcceptanceTester; diff --git a/tests/Codeception/Acceptance/ModuleCest.php b/tests/Codeception/Acceptance/ModuleCest.php index 9242193..88df3b5 100644 --- a/tests/Codeception/Acceptance/ModuleCest.php +++ b/tests/Codeception/Acceptance/ModuleCest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace OxidEsales\ModuleTemplate\Tests\Codeception\Helper; +namespace OxidEsales\ModuleTemplate\Tests\Codeception\Acceptance; use OxidEsales\Codeception\Module\Translation\Translator; use OxidEsales\ModuleTemplate\Core\Module; diff --git a/tests/Codeception/Acceptance/UpdateGreetingCest.php b/tests/Codeception/Acceptance/UpdateGreetingCest.php index 748c1eb..2af51e1 100644 --- a/tests/Codeception/Acceptance/UpdateGreetingCest.php +++ b/tests/Codeception/Acceptance/UpdateGreetingCest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace OxidEsales\ModuleTemplate\Tests\Codeception\Helper; +namespace OxidEsales\ModuleTemplate\Tests\Codeception\Acceptance; use OxidEsales\Codeception\Module\Translation\Translator; use OxidEsales\ModuleTemplate\Core\Module as ModuleCore; diff --git a/tests/Codeception/Support/AcceptanceTester.php b/tests/Codeception/Support/AcceptanceTester.php index eb1acbd..6a18554 100644 --- a/tests/Codeception/Support/AcceptanceTester.php +++ b/tests/Codeception/Support/AcceptanceTester.php @@ -10,6 +10,8 @@ namespace OxidEsales\ModuleTemplate\Tests\Codeception\Support; use Codeception\Util\Fixtures; +use OxidEsales\Codeception\Admin\AdminLoginPage; +use OxidEsales\Codeception\Admin\AdminPanel; use OxidEsales\Codeception\Page\Home; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; use OxidEsales\Facts\Facts; @@ -91,6 +93,21 @@ public function getShopUrl(): string return $facts->getShopUrl(); } + public function openAdmin(): AdminLoginPage + { + $I = $this; + $adminLogin = new AdminLoginPage($I); + $I->amOnPage($adminLogin->URL); + return $adminLogin; + } + + public function loginAdmin(): AdminPanel + { + $adminPage = $this->openAdmin(); + $admin = Fixtures::get('adminUser'); + return $adminPage->login($admin['email'], $admin['password']); + } + protected function getServiceFromContainer(string $serviceName) { return ContainerFactory::getInstance() diff --git a/tests/Codeception/Support/Data/fixtures.php b/tests/Codeception/Support/Data/fixtures.php index f0a0ec2..8203c99 100644 --- a/tests/Codeception/Support/Data/fixtures.php +++ b/tests/Codeception/Support/Data/fixtures.php @@ -13,4 +13,9 @@ 'email' => 'user@oxid-esales.com', 'password' => 'useruser', ], + 'adminUser' => [ + 'OXID' => 'oxadminuser', + 'email' => 'admin@oxid-esales.com', + 'password' => 'useruser', + ], ]; diff --git a/tests/Codeception/Support/Data/fixtures.sql b/tests/Codeception/Support/Data/fixtures.sql index b46ea9b..f0c7152 100644 --- a/tests/Codeception/Support/Data/fixtures.sql +++ b/tests/Codeception/Support/Data/fixtures.sql @@ -1,3 +1,4 @@ #Add default user REPLACE INTO `oxuser` (`OXID`, `OXACTIVE`, `OXRIGHTS`, `OXSHOPID`, `OXUSERNAME`, `OXPASSWORD`, `OXPASSSALT`, `OXCREATE`, `OXREGISTER`, `OXTIMESTAMP`, `OXBIRTHDATE`) VALUES -('oxdefaultuser',1,'user',1,'user@oxid-esales.com','$2y$10$ljaDXMPHOyC7ELlnC5ErK.3ET4B0oAN3WVr/Tk.RKlUfiuBcQEVVC','', '2003-01-01 00:00:00', '2003-01-01 00:00:00', '2003-01-01 00:00:00', '1985-01-01'); +('oxdefaultuser',1,'user',1,'user@oxid-esales.com','$2y$10$ljaDXMPHOyC7ELlnC5ErK.3ET4B0oAN3WVr/Tk.RKlUfiuBcQEVVC','', '2003-01-01 00:00:00', '2003-01-01 00:00:00', '2003-01-01 00:00:00', '1985-01-01'), +('oxadminuser',1,'malladmin',1,'admin@oxid-esales.com','$2y$10$ljaDXMPHOyC7ELlnC5ErK.3ET4B0oAN3WVr/Tk.RKlUfiuBcQEVVC','', '2003-01-01 00:00:00', '2003-01-01 00:00:00', '2003-01-01 00:00:00', '1985-01-01'); diff --git a/views/admin_twig/de/module_options.php b/views/admin_twig/de/module_options.php index 68524f3..0f6c739 100644 --- a/views/admin_twig/de/module_options.php +++ b/views/admin_twig/de/module_options.php @@ -14,6 +14,8 @@ 'OEMODULETEMPLATE_GREETING_TITLE' => 'Admin controller example', 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', + 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Allow user to set greeting', + 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Example of extending admin template', # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Einstellungen', diff --git a/views/admin_twig/en/module_options.php b/views/admin_twig/en/module_options.php index 79c881e..3d3091a 100644 --- a/views/admin_twig/en/module_options.php +++ b/views/admin_twig/en/module_options.php @@ -14,6 +14,8 @@ 'OEMODULETEMPLATE_GREETING_TITLE' => 'Admin controller example', 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', + 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Allow user to set greeting', + 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Example of extending admin template', # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Settings', diff --git a/views/twig/extensions/themes/admin_twig/user_main.html.twig b/views/twig/extensions/themes/admin_twig/user_main.html.twig new file mode 100644 index 0000000..eb57f25 --- /dev/null +++ b/views/twig/extensions/themes/admin_twig/user_main.html.twig @@ -0,0 +1,16 @@ +{% extends 'user_main.html.twig' %} + +{% block admin_user_main_form %} + + + + {{ translate({ ident: "OEMODULETEMPLATE_ALLOW_GREETING" }) }} + + + + {% include "inputhelp.html.twig" with {'sHelpId': help_id("OEMODULETEMPLATE_HELP_ALLOW_GREETING"), 'sHelpText': help_text("OEMODULETEMPLATE_HELP_ALLOW_GREETING")} %} + + + + {{ parent() }} +{% endblock %} From f3c344ef1b2a459c5b8f9b4047b31eb1cfddf771 Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Mon, 15 Jul 2024 16:44:54 +0300 Subject: [PATCH 07/22] Add oxnew factory example --- .../Infrastructure/CoreRequestFactory.php | 23 +++++++++++++++ .../CoreRequestFactoryInterface.php | 18 ++++++++++++ .../Service/GreetingMessageService.php | 7 +++-- src/Greeting/services.yaml | 6 ++-- .../Service/GreetingMessageServiceTest.php | 8 ++--- .../Infrastructure/CoreRequestFactoryTest.php | 29 +++++++++++++++++++ .../Service/GreetingMessageServiceTest.php | 8 ++--- 7 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 src/Greeting/Infrastructure/CoreRequestFactory.php create mode 100644 src/Greeting/Infrastructure/CoreRequestFactoryInterface.php create mode 100644 tests/Unit/Greeting/Infrastructure/CoreRequestFactoryTest.php diff --git a/src/Greeting/Infrastructure/CoreRequestFactory.php b/src/Greeting/Infrastructure/CoreRequestFactory.php new file mode 100644 index 0000000..eaa8a6f --- /dev/null +++ b/src/Greeting/Infrastructure/CoreRequestFactory.php @@ -0,0 +1,23 @@ +shopRequest->getRequestParameter(ModuleCore::OEMT_GREETING_TEMPLATE_VARNAME); + $coreRequestService = $this->coreRequestFactory->create(); + $input = (string)$coreRequestService->getRequestParameter(ModuleCore::OEMT_GREETING_TEMPLATE_VARNAME); //in real life add some input validation return (string)substr($input, 0, 253); diff --git a/src/Greeting/services.yaml b/src/Greeting/services.yaml index ebd21e6..25ed4a2 100644 --- a/src/Greeting/services.yaml +++ b/src/Greeting/services.yaml @@ -3,7 +3,6 @@ services: public: false autowire: true bind: - OxidEsales\Eshop\Core\Request: '@=service("OxidEsales\\ModuleTemplate\\Core\\Registry").getRequest()' OxidEsales\Eshop\Core\Language: '@=service("OxidEsales\\ModuleTemplate\\Core\\Registry").getLang()' OxidEsales\ModuleTemplate\Greeting\Repository\GreetingRepositoryInterface: @@ -12,4 +11,7 @@ services: OxidEsales\ModuleTemplate\Greeting\Service\GreetingMessageServiceInterface: class: OxidEsales\ModuleTemplate\Greeting\Service\GreetingMessageService - public: true \ No newline at end of file + public: true + + OxidEsales\ModuleTemplate\Greeting\Infrastructure\CoreRequestFactoryInterface: + class: OxidEsales\ModuleTemplate\Greeting\Infrastructure\CoreRequestFactory \ No newline at end of file diff --git a/tests/Integration/Greeting/Service/GreetingMessageServiceTest.php b/tests/Integration/Greeting/Service/GreetingMessageServiceTest.php index 8202911..d27837a 100644 --- a/tests/Integration/Greeting/Service/GreetingMessageServiceTest.php +++ b/tests/Integration/Greeting/Service/GreetingMessageServiceTest.php @@ -10,9 +10,9 @@ namespace OxidEsales\ModuleTemplate\Tests\Integration\Greeting\Service; use OxidEsales\Eshop\Core\Language as CoreLanguage; -use OxidEsales\Eshop\Core\Request as CoreRequest; use OxidEsales\ModuleTemplate\Extension\Model\User; use OxidEsales\ModuleTemplate\Greeting\Service\GreetingMessageService; +use OxidEsales\ModuleTemplate\Greeting\Infrastructure\CoreRequestFactoryInterface; use OxidEsales\ModuleTemplate\Settings\Service\ModuleSettingsServiceInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; @@ -28,7 +28,7 @@ public function testGenericGreetingWithUserForPersonalMode(): void { $sut = new GreetingMessageService( moduleSettings: $moduleSettingsStub = $this->createMock(ModuleSettingsServiceInterface::class), - shopRequest: $this->createStub(CoreRequest::class), + coreRequestFactory: $this->createStub(CoreRequestFactoryInterface::class), shopLanguage: $langStub = $this->createStub(CoreLanguage::class), ); @@ -50,11 +50,11 @@ public function testGenericGreetingWithUserForPersonalMode(): void private function getSut( ModuleSettingsServiceInterface $moduleSettings = null, - CoreRequest $shopRequest = null, + CoreRequestFactoryInterface $coreRequestFactory = null, ): GreetingMessageService { return new GreetingMessageService( moduleSettings: $moduleSettings ?? $this->createStub(ModuleSettingsServiceInterface::class), - shopRequest: $shopRequest ?? $this->createStub(CoreRequest::class), + coreRequestFactory: $coreRequestFactory ?? $this->createStub(CoreRequestFactoryInterface::class), shopLanguage: $shopLanguage ?? $this->createStub(CoreLanguage::class), ); } diff --git a/tests/Unit/Greeting/Infrastructure/CoreRequestFactoryTest.php b/tests/Unit/Greeting/Infrastructure/CoreRequestFactoryTest.php new file mode 100644 index 0000000..1adf431 --- /dev/null +++ b/tests/Unit/Greeting/Infrastructure/CoreRequestFactoryTest.php @@ -0,0 +1,29 @@ +getMockBuilder(CoreRequestFactory::class) + ->onlyMethods(['create']) + ->getMock(); + + $this->assertInstanceOf(Request::class, $coreRequestFactoryMock->create()); + } +} diff --git a/tests/Unit/Greeting/Service/GreetingMessageServiceTest.php b/tests/Unit/Greeting/Service/GreetingMessageServiceTest.php index 2192280..53b9ab2 100644 --- a/tests/Unit/Greeting/Service/GreetingMessageServiceTest.php +++ b/tests/Unit/Greeting/Service/GreetingMessageServiceTest.php @@ -10,8 +10,8 @@ namespace OxidEsales\ModuleTemplate\Tests\Unit\Greeting\Service; use OxidEsales\Eshop\Core\Language as CoreLanguage; -use OxidEsales\Eshop\Core\Request as CoreRequest; use OxidEsales\ModuleTemplate\Core\Module as ModuleCore; +use OxidEsales\ModuleTemplate\Greeting\Infrastructure\CoreRequestFactoryInterface; use OxidEsales\ModuleTemplate\Greeting\Service\GreetingMessageService; use OxidEsales\ModuleTemplate\Settings\Service\ModuleSettingsServiceInterface; use PHPUnit\Framework\Attributes\CoversClass; @@ -24,7 +24,7 @@ public function testGenericGreetingNoUserForGenericMode(): void { $service = new GreetingMessageService( moduleSettings: $moduleSettingsStub = $this->createMock(ModuleSettingsServiceInterface::class), - shopRequest: $this->createStub(CoreRequest::class), + coreRequestFactory: $this->createStub(CoreRequestFactoryInterface::class), shopLanguage: $langStub = $this->createStub(CoreLanguage::class), ); @@ -43,7 +43,7 @@ public function testGenericGreetingWithUserForGenericMode(): void { $service = new GreetingMessageService( moduleSettings: $moduleSettingsStub = $this->createMock(ModuleSettingsServiceInterface::class), - shopRequest: $this->createStub(CoreRequest::class), + coreRequestFactory: $this->createStub(CoreRequestFactoryInterface::class), shopLanguage: $langStub = $this->createStub(CoreLanguage::class), ); @@ -62,7 +62,7 @@ public function testGenericGreetingNoUserForPersonalMode(): void { $service = new GreetingMessageService( moduleSettings: $moduleSettingsStub = $this->createMock(ModuleSettingsServiceInterface::class), - shopRequest: $this->createStub(CoreRequest::class), + coreRequestFactory: $this->createStub(CoreRequestFactoryInterface::class), shopLanguage: $this->createStub(CoreLanguage::class), ); From 0b97903f2e4aa9750e2d24650d54cf50828fd57f Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Mon, 15 Jul 2024 17:02:04 +0300 Subject: [PATCH 08/22] OXDEV-8462 Add changes in readme and changelog --- CHANGELOG.md | 8 ++++++++ README.md | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ee93e4..5d0e1b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [undecided] - unreleased + +### Added +- Admin controller +- Template for admin controller +- Example of extending of current admin template +- ``oxNew`` object factory example + ## [v3.0.0] - 2024-06-27 This is the stable release for v3.0.0. No changes have been made since v3.0.0-rc.1. diff --git a/README.md b/README.md index a906325..451aed9 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,8 @@ Story: * extending a shop model (`OxidEsales\ModuleTemplate\Extension\Model\User`) / (`OxidEsales\ModuleTemplate\Extension\Model\Basket`) * extending a shop controller (`OxidEsales\ModuleTemplate\Extension\Controller\StartController`) * extending a shop database table (`oxuser`) -* extending a shop template block (`start_welcome_text`) +* extending a shop template block (`start_newest_articles`) +* extending a shop admin template block (`admin_user_main_form`) **HINT**: only extend the shop core if there is no other way like listen and handle shop events, decorate/replace some DI service. Your module might be one of many in the class chain and you should @@ -227,10 +228,12 @@ If you need to extend the shop class chain by overwriting, try to stick to the p #### Sometimes we need to bring our own * own module controller (`oemtgreeting` with own template and own translations) +* own module admin controller (`oemt_admin_greeting` with own template and own translations) * module setting (`oemoduletemplate_GreetingMode`) * event subscriber (`OxidEsales\ModuleTemplate\Tracker\Subscriber\BeforeModelUpdate`) * model with a database (`OxidEsales\ModuleTemplate\Tracker\Model\GreetingTracker`) * DI service examples +* ``oxNew`` object factory example (`OxidEsales\ModuleTemplate\Greeting\Infrastructure\CoreRequestFactory`) #### Whatever you do, ensure it is covered with tests * unit/integration test From 81522ca405567bce53ec047885efaaaec0f0d674 Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Mon, 15 Jul 2024 17:18:03 +0300 Subject: [PATCH 09/22] OXDEV-8462 Clean up --- services.yaml | 2 -- .../Controller/Admin/GreetingAdminControllerTest.php | 6 ------ tests/Unit/Infrastructure/CoreRequestFactoryTest.php | 4 ++-- tests/Unit/Service/GreetingMessageTest.php | 1 - 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/services.yaml b/services.yaml index 6b9e62f..2512a6c 100644 --- a/services.yaml +++ b/services.yaml @@ -9,8 +9,6 @@ services: _defaults: public: false autowire: true - bind: - OxidEsales\Eshop\Core\Request: '@=service("OxidEsales\\ModuleTemplate\\Core\\Registry").getRequest()' OxidEsales\ModuleTemplate\Core\Registry: class: OxidEsales\Eshop\Core\Registry diff --git a/tests/Integration/Controller/Admin/GreetingAdminControllerTest.php b/tests/Integration/Controller/Admin/GreetingAdminControllerTest.php index a7e1854..578f3e6 100644 --- a/tests/Integration/Controller/Admin/GreetingAdminControllerTest.php +++ b/tests/Integration/Controller/Admin/GreetingAdminControllerTest.php @@ -12,10 +12,6 @@ use OxidEsales\Eshop\Application\Model\User as EshopModelUser; use OxidEsales\ModuleTemplate\Controller\Admin\GreetingAdminController; use OxidEsales\ModuleTemplate\Core\Module as ModuleCore; -use OxidEsales\ModuleTemplate\Model\GreetingTracker; -use OxidEsales\ModuleTemplate\Model\User as ModuleUser; -use OxidEsales\ModuleTemplate\Service\ModuleSettings; -use OxidEsales\ModuleTemplate\Service\Repository; use OxidEsales\ModuleTemplate\Tests\Integration\IntegrationTestCase; use OxidEsales\ModuleTemplate\Traits\ServiceContainer; @@ -31,8 +27,6 @@ final class GreetingAdminControllerTest extends IntegrationTestCase public const TEST_GREETING = 'Hello there!'; - public const TEST_GREETING_UPDATED = 'shopping addict'; - public function testRender(): void { $this->createTestUser(); diff --git a/tests/Unit/Infrastructure/CoreRequestFactoryTest.php b/tests/Unit/Infrastructure/CoreRequestFactoryTest.php index 859264d..125e2e7 100644 --- a/tests/Unit/Infrastructure/CoreRequestFactoryTest.php +++ b/tests/Unit/Infrastructure/CoreRequestFactoryTest.php @@ -20,10 +20,10 @@ class CoreRequestFactoryTest extends TestCase { public function testCreateProducesCorrectTypeOfObjects(): void { - $coreThemeFactoryMock = $this->getMockBuilder(CoreRequestFactory::class) + $coreRequestFactoryMock = $this->getMockBuilder(CoreRequestFactory::class) ->onlyMethods(['create']) ->getMock(); - $this->assertInstanceOf(Request::class, $coreThemeFactoryMock->create()); + $this->assertInstanceOf(Request::class, $coreRequestFactoryMock->create()); } } diff --git a/tests/Unit/Service/GreetingMessageTest.php b/tests/Unit/Service/GreetingMessageTest.php index d3b860a..43082c3 100644 --- a/tests/Unit/Service/GreetingMessageTest.php +++ b/tests/Unit/Service/GreetingMessageTest.php @@ -9,7 +9,6 @@ namespace OxidEsales\ModuleTemplate\Tests\Unit\Service; -use OxidEsales\Eshop\Core\Request as CoreRequest; use OxidEsales\ModuleTemplate\Core\Module as ModuleCore; use OxidEsales\ModuleTemplate\Infrastructure\CoreRequestFactoryInterface; use OxidEsales\ModuleTemplate\Service\GreetingMessage; From 85e8ffc80cc356687b2fb8ef02617a330addbeaf Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Mon, 15 Jul 2024 17:22:41 +0300 Subject: [PATCH 10/22] OXDEV-8462 Add changes in readme and changelog --- CHANGELOG.md | 8 ++++++++ README.md | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfe4247..c2c3ea3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [undecided] - unreleased + +### Added +- Admin controller +- Template for admin controller +- Example of extending of current admin template +- ``oxNew`` object factory example + ## [v2.1.0] - 2024-05-30 ### Added diff --git a/README.md b/README.md index 3394336..c024174 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,8 @@ Story: * extending a shop model (`OxidEsales\ModuleTemplate\Model\User`) / (`OxidEsales\ModuleTemplate\Model\Basket`) * extending a shop controller (`OxidEsales\ModuleTemplate\Controller\StartController`) * extending a shop database table (`oxuser`) -* extending a shop template block (`start_welcome_text`) +* extending a shop template block (`start_newest_articles`) +* extending a shop admin template block (`admin_user_main_form`) **HINT**: only extend the shop core if there is no other way like listen and handle shop events, extend/replace some DI service. Your module might be one of many in the class chain and you should @@ -223,10 +224,12 @@ If you need to extend the shop class chain by overwriting, try to stick to the p #### Sometimes we need to bring our own * own module controller (`oemtgreeting` with own template and own translations) +* own module admin controller (`oemt_admin_greeting` with own template and own translations) * module setting (`oemoduletemplate_GreetingMode`) * event subscriber (`OxidEsales\ModuleTemplate\Subscriber\BeforeModelUpdate`) * model with a database (`OxidEsales\ModuleTemplate\Model\GreetingTracker`) * DI service examples +* ``oxNew`` object factory example (`OxidEsales\ModuleTemplate\Greeting\Infrastructure\CoreRequestFactory`) #### Whatever you do, ensure it is covered with tests * unit/integration test From 4ed4bfd65778aa7fcc36c1764ac73aab88722005 Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Mon, 15 Jul 2024 17:57:49 +0300 Subject: [PATCH 11/22] OXDEV-8462 Fix smarty --- composer.json | 2 +- metadata.php | 2 +- tests/Codeception/acceptance.suite.yml | 6 +++--- views/admin_smarty/de/module_options.php | 9 +++++++++ views/admin_smarty/en/module_options.php | 9 +++++++++ views/smarty/{templates => }/admin/user_greetings.tpl | 0 6 files changed, 23 insertions(+), 5 deletions(-) rename views/smarty/{templates => }/admin/user_greetings.tpl (100%) diff --git a/composer.json b/composer.json index 7417b45..b859e23 100644 --- a/composer.json +++ b/composer.json @@ -69,7 +69,7 @@ "tests-codeception": [ "Composer\\Config::disableProcessTimeout", - "THEME_ID=apex MODULE_IDS=oe_moduletemplate SHOP_ROOT_PATH=/var/www vendor/bin/codecept run acceptance -c tests/codeception.yml --no-redirect" + "THEME_ID=flow MODULE_IDS=oe_moduletemplate SHOP_ROOT_PATH=/var/www vendor/bin/codecept run acceptance -c tests/codeception.yml --no-redirect" ], "tests-all": [ diff --git a/metadata.php b/metadata.php index 8dbe812..46aadb3 100644 --- a/metadata.php +++ b/metadata.php @@ -33,7 +33,7 @@ ], 'templates' => [ '@oe_moduletemplate/templates/greetingtemplate.tpl' => 'views/smarty/templates/greetingtemplate.tpl', - '@oe_moduletemplate/templates/admin/user_greetings.tpl' => 'views/smarty/templates/admin/user_greetings.tpl', + '@oe_moduletemplate/admin/user_greetings.tpl' => 'views/smarty/admin/user_greetings.tpl', ], 'events' => [ 'onActivate' => '\OxidEsales\ModuleTemplate\Core\ModuleEvents::onActivate', diff --git a/tests/Codeception/acceptance.suite.yml b/tests/Codeception/acceptance.suite.yml index 8c034c6..614d9c6 100644 --- a/tests/Codeception/acceptance.suite.yml +++ b/tests/Codeception/acceptance.suite.yml @@ -49,9 +49,9 @@ modules: - \OxidEsales\Codeception\Module\Translation\TranslationsModule: shop_path: '%SHOP_SOURCE_PATH%' paths: - - Application/views/apex - - Application/views/admin_twig - - ../vendor/oxid-esales/module-template/views/admin_twig + - Application/views/flow/translations + - Application/views/admin_smarty + - ../vendor/oxid-esales/module-template/views/admin_smarty - ../vendor/oxid-esales/module-template/translations - \OxidEsales\Codeception\Module\OxideshopModules step_decorators: diff --git a/views/admin_smarty/de/module_options.php b/views/admin_smarty/de/module_options.php index 9c0edf4..c7fa1c7 100644 --- a/views/admin_smarty/de/module_options.php +++ b/views/admin_smarty/de/module_options.php @@ -9,6 +9,15 @@ $aLang = [ 'charset' => 'UTF-8', + 'tbcluser_greetings' => 'Greetings', + + 'OEMODULETEMPLATE_GREETING_TITLE' => 'Admin controller example', + 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', + 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', + 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Allow user to set greeting', + 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Example of extending admin template', + + # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Einstellungen', 'SHOP_MODULE_oemoduletemplate_GreetingMode' => 'Begrüßungsmodus', 'SHOP_MODULE_oemoduletemplate_GreetingMode_generic' => 'höflich', diff --git a/views/admin_smarty/en/module_options.php b/views/admin_smarty/en/module_options.php index 4ff6e99..c5ef721 100644 --- a/views/admin_smarty/en/module_options.php +++ b/views/admin_smarty/en/module_options.php @@ -9,6 +9,15 @@ $aLang = [ 'charset' => 'UTF-8', + 'tbcluser_greetings' => 'Greetings', + + 'OEMODULETEMPLATE_GREETING_TITLE' => 'Admin controller example', + 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', + 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', + 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Allow user to set greeting', + 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Example of extending admin template', + + # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Settings', 'SHOP_MODULE_oemoduletemplate_GreetingMode' => 'Greeting mode', 'SHOP_MODULE_oemoduletemplate_GreetingMode_generic' => 'generic', diff --git a/views/smarty/templates/admin/user_greetings.tpl b/views/smarty/admin/user_greetings.tpl similarity index 100% rename from views/smarty/templates/admin/user_greetings.tpl rename to views/smarty/admin/user_greetings.tpl From 07000748eaff5bc01673d6a4a0db51556eb4752a Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Mon, 15 Jul 2024 18:00:18 +0300 Subject: [PATCH 12/22] OXDEV-8462 Revert tests to use apex --- composer.json | 2 +- tests/Codeception/acceptance.suite.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index b859e23..7417b45 100644 --- a/composer.json +++ b/composer.json @@ -69,7 +69,7 @@ "tests-codeception": [ "Composer\\Config::disableProcessTimeout", - "THEME_ID=flow MODULE_IDS=oe_moduletemplate SHOP_ROOT_PATH=/var/www vendor/bin/codecept run acceptance -c tests/codeception.yml --no-redirect" + "THEME_ID=apex MODULE_IDS=oe_moduletemplate SHOP_ROOT_PATH=/var/www vendor/bin/codecept run acceptance -c tests/codeception.yml --no-redirect" ], "tests-all": [ diff --git a/tests/Codeception/acceptance.suite.yml b/tests/Codeception/acceptance.suite.yml index 614d9c6..8c034c6 100644 --- a/tests/Codeception/acceptance.suite.yml +++ b/tests/Codeception/acceptance.suite.yml @@ -49,9 +49,9 @@ modules: - \OxidEsales\Codeception\Module\Translation\TranslationsModule: shop_path: '%SHOP_SOURCE_PATH%' paths: - - Application/views/flow/translations - - Application/views/admin_smarty - - ../vendor/oxid-esales/module-template/views/admin_smarty + - Application/views/apex + - Application/views/admin_twig + - ../vendor/oxid-esales/module-template/views/admin_twig - ../vendor/oxid-esales/module-template/translations - \OxidEsales\Codeception\Module\OxideshopModules step_decorators: From 97fb89b76fbda71ddd7bc5195e5e85bfea4aefdb Mon Sep 17 00:00:00 2001 From: Nikola Ivanovski Date: Tue, 16 Jul 2024 15:43:59 +0300 Subject: [PATCH 13/22] OXDEV-8462 Translate admin settings --- views/admin_twig/de/module_options.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/views/admin_twig/de/module_options.php b/views/admin_twig/de/module_options.php index 0f6c739..f1d490f 100644 --- a/views/admin_twig/de/module_options.php +++ b/views/admin_twig/de/module_options.php @@ -11,11 +11,11 @@ 'charset' => 'UTF-8', 'tbcluser_greetings' => 'Greetings', - 'OEMODULETEMPLATE_GREETING_TITLE' => 'Admin controller example', - 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', - 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', - 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Allow user to set greeting', - 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Example of extending admin template', + 'OEMODULETEMPLATE_GREETING_TITLE' => 'Beispiel Admin Controller', + 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Begrüßungsnachricht: ', + 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'Es wurde keine Begrüßungsnachricht hinzugefügt!', + 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Benutzer erlauben die Begrüßungsnachricht zu setzen', + 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Beispiel für die Erweiterung des Admin-Templates', # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Einstellungen', From 13b48da8570faa4759e2c8662569f51521be9a5b Mon Sep 17 00:00:00 2001 From: Nikola Ivanovski Date: Tue, 16 Jul 2024 15:45:16 +0300 Subject: [PATCH 14/22] OXDEV-8462 Translate admin settings --- views/admin_twig/de/module_options.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/views/admin_twig/de/module_options.php b/views/admin_twig/de/module_options.php index 0f6c739..f1d490f 100644 --- a/views/admin_twig/de/module_options.php +++ b/views/admin_twig/de/module_options.php @@ -11,11 +11,11 @@ 'charset' => 'UTF-8', 'tbcluser_greetings' => 'Greetings', - 'OEMODULETEMPLATE_GREETING_TITLE' => 'Admin controller example', - 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', - 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', - 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Allow user to set greeting', - 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Example of extending admin template', + 'OEMODULETEMPLATE_GREETING_TITLE' => 'Beispiel Admin Controller', + 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Begrüßungsnachricht: ', + 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'Es wurde keine Begrüßungsnachricht hinzugefügt!', + 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Benutzer erlauben die Begrüßungsnachricht zu setzen', + 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Beispiel für die Erweiterung des Admin-Templates', # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Einstellungen', From 8b984e5af1f99f711a38647ac5a5706158303472 Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Thu, 25 Jul 2024 12:10:54 +0300 Subject: [PATCH 15/22] OXDEV-8462 Fix admin templates and description --- README.md | 2 +- views/admin_smarty/de/module_options.php | 10 +++++----- views/admin_smarty/en/module_options.php | 2 +- views/admin_twig/de/module_options.php | 2 +- views/admin_twig/en/module_options.php | 2 +- views/smarty/admin/user_greetings.tpl | 2 +- views/smarty/blocks/admin/admin_user_main_form.tpl | 2 +- views/twig/admin/user_greetings.html.twig | 2 +- .../extensions/themes/admin_twig/user_main.html.twig | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c024174..2db5c55 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,7 @@ Story: * extending a shop controller (`OxidEsales\ModuleTemplate\Controller\StartController`) * extending a shop database table (`oxuser`) * extending a shop template block (`start_newest_articles`) -* extending a shop admin template block (`admin_user_main_form`) +* extending a shop admin template block (`admin_user_main_form` - only an extension of a block, without functionality) **HINT**: only extend the shop core if there is no other way like listen and handle shop events, extend/replace some DI service. Your module might be one of many in the class chain and you should diff --git a/views/admin_smarty/de/module_options.php b/views/admin_smarty/de/module_options.php index c7fa1c7..b041038 100644 --- a/views/admin_smarty/de/module_options.php +++ b/views/admin_smarty/de/module_options.php @@ -11,11 +11,11 @@ 'charset' => 'UTF-8', 'tbcluser_greetings' => 'Greetings', - 'OEMODULETEMPLATE_GREETING_TITLE' => 'Admin controller example', - 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', - 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', - 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Allow user to set greeting', - 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Example of extending admin template', + 'OEMODULETEMPLATE_GREETING_TITLE' => 'Beispiel Admin Controller', + 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Begrüßungsnachricht: ', + 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'Es wurde keine Begrüßungsnachricht hinzugefügt!', + 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Benutzer erlauben die Begrüßungsnachricht zu setzen', + 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Dies ist ein Beispiel, wie ein Admintemplate erweitert werden kann. Momentan ist keine Funktionalität hinter dieser Checkbox hinterlegt, es wird keine Einstellung in der Datenbank gespeichert.', # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Einstellungen', diff --git a/views/admin_smarty/en/module_options.php b/views/admin_smarty/en/module_options.php index c5ef721..4fc3fc2 100644 --- a/views/admin_smarty/en/module_options.php +++ b/views/admin_smarty/en/module_options.php @@ -15,7 +15,7 @@ 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Allow user to set greeting', - 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Example of extending admin template', + 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'This is an example of extending admin template. There is no functionality implemented behind this checkbox and does not save anything to the database', # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Settings', diff --git a/views/admin_twig/de/module_options.php b/views/admin_twig/de/module_options.php index f1d490f..2befaa8 100644 --- a/views/admin_twig/de/module_options.php +++ b/views/admin_twig/de/module_options.php @@ -15,7 +15,7 @@ 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Begrüßungsnachricht: ', 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'Es wurde keine Begrüßungsnachricht hinzugefügt!', 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Benutzer erlauben die Begrüßungsnachricht zu setzen', - 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Beispiel für die Erweiterung des Admin-Templates', + 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Dies ist ein Beispiel, wie ein Admintemplate erweitert werden kann. Momentan ist keine Funktionalität hinter dieser Checkbox hinterlegt, es wird keine Einstellung in der Datenbank gespeichert.', # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Einstellungen', diff --git a/views/admin_twig/en/module_options.php b/views/admin_twig/en/module_options.php index 3d3091a..839a250 100644 --- a/views/admin_twig/en/module_options.php +++ b/views/admin_twig/en/module_options.php @@ -15,7 +15,7 @@ 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Allow user to set greeting', - 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Example of extending admin template', + 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'This is an example of extending admin template. There is no functionality implemented behind this checkbox and does not save anything to the database', # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Settings', diff --git a/views/smarty/admin/user_greetings.tpl b/views/smarty/admin/user_greetings.tpl index c61e5dc..4c60079 100644 --- a/views/smarty/admin/user_greetings.tpl +++ b/views/smarty/admin/user_greetings.tpl @@ -1,6 +1,6 @@ [{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign box="list"}] -
+ [{$oViewConf->getHiddenSid()}] diff --git a/views/smarty/blocks/admin/admin_user_main_form.tpl b/views/smarty/blocks/admin/admin_user_main_form.tpl index a33c590..2b59818 100644 --- a/views/smarty/blocks/admin/admin_user_main_form.tpl +++ b/views/smarty/blocks/admin/admin_user_main_form.tpl @@ -3,7 +3,7 @@ [{oxmultilang ident="OEMODULETEMPLATE_ALLOW_GREETING"}] - + [{oxinputhelp ident="OEMODULETEMPLATE_HELP_ALLOW_GREETING"}] diff --git a/views/twig/admin/user_greetings.html.twig b/views/twig/admin/user_greetings.html.twig index 15ce786..26b8789 100644 --- a/views/twig/admin/user_greetings.html.twig +++ b/views/twig/admin/user_greetings.html.twig @@ -1,6 +1,6 @@ {% include "headitem.html.twig" with {title: "GENERAL_ADMIN_TITLE"|translate} %} - + {{ oViewConf.getHiddenSid()|raw }} diff --git a/views/twig/extensions/themes/admin_twig/user_main.html.twig b/views/twig/extensions/themes/admin_twig/user_main.html.twig index 5c25b7d..5769dd1 100644 --- a/views/twig/extensions/themes/admin_twig/user_main.html.twig +++ b/views/twig/extensions/themes/admin_twig/user_main.html.twig @@ -7,7 +7,7 @@ {{ translate({ ident: "OEMODULETEMPLATE_ALLOW_GREETING" }) }} - + {% include "inputhelp.html.twig" with {'sHelpId': help_id("OEMODULETEMPLATE_HELP_ALLOW_GREETING"), 'sHelpText': help_text("OEMODULETEMPLATE_HELP_ALLOW_GREETING")} %} From a049efccf41121eee14ff88633a38e83ec1679a6 Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Thu, 25 Jul 2024 16:22:35 +0300 Subject: [PATCH 16/22] OXDEV-8462 Fix admin templates and description --- README.md | 2 +- views/admin_twig/de/module_options.php | 2 +- views/admin_twig/en/module_options.php | 2 +- views/twig/admin/user_greetings.html.twig | 2 +- views/twig/extensions/themes/admin_twig/user_main.html.twig | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 451aed9..69265b4 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,7 @@ Story: * extending a shop controller (`OxidEsales\ModuleTemplate\Extension\Controller\StartController`) * extending a shop database table (`oxuser`) * extending a shop template block (`start_newest_articles`) -* extending a shop admin template block (`admin_user_main_form`) +* extending a shop admin template block (`admin_user_main_form` - only an extension of a block, without functionality) **HINT**: only extend the shop core if there is no other way like listen and handle shop events, decorate/replace some DI service. Your module might be one of many in the class chain and you should diff --git a/views/admin_twig/de/module_options.php b/views/admin_twig/de/module_options.php index f1d490f..2befaa8 100644 --- a/views/admin_twig/de/module_options.php +++ b/views/admin_twig/de/module_options.php @@ -15,7 +15,7 @@ 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Begrüßungsnachricht: ', 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'Es wurde keine Begrüßungsnachricht hinzugefügt!', 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Benutzer erlauben die Begrüßungsnachricht zu setzen', - 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Beispiel für die Erweiterung des Admin-Templates', + 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Dies ist ein Beispiel, wie ein Admintemplate erweitert werden kann. Momentan ist keine Funktionalität hinter dieser Checkbox hinterlegt, es wird keine Einstellung in der Datenbank gespeichert.', # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Einstellungen', diff --git a/views/admin_twig/en/module_options.php b/views/admin_twig/en/module_options.php index 3d3091a..839a250 100644 --- a/views/admin_twig/en/module_options.php +++ b/views/admin_twig/en/module_options.php @@ -15,7 +15,7 @@ 'OEMODULETEMPLATE_GREETING_MESSAGE_TEXT' => 'Greeting message: ', 'OEMODULETEMPLATE_NO_GREETING_TEXT' => 'No greeting message added!', 'OEMODULETEMPLATE_ALLOW_GREETING' => 'Allow user to set greeting', - 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'Example of extending admin template', + 'OEMODULETEMPLATE_HELP_ALLOW_GREETING' => 'This is an example of extending admin template. There is no functionality implemented behind this checkbox and does not save anything to the database', # Module settings 'SHOP_MODULE_GROUP_oemoduletemplate_main' => 'Settings', diff --git a/views/twig/admin/user_greetings.html.twig b/views/twig/admin/user_greetings.html.twig index 15ce786..26b8789 100644 --- a/views/twig/admin/user_greetings.html.twig +++ b/views/twig/admin/user_greetings.html.twig @@ -1,6 +1,6 @@ {% include "headitem.html.twig" with {title: "GENERAL_ADMIN_TITLE"|translate} %} - + {{ oViewConf.getHiddenSid()|raw }} diff --git a/views/twig/extensions/themes/admin_twig/user_main.html.twig b/views/twig/extensions/themes/admin_twig/user_main.html.twig index eb57f25..77b240d 100644 --- a/views/twig/extensions/themes/admin_twig/user_main.html.twig +++ b/views/twig/extensions/themes/admin_twig/user_main.html.twig @@ -7,7 +7,7 @@ {{ translate({ ident: "OEMODULETEMPLATE_ALLOW_GREETING" }) }} - + {% include "inputhelp.html.twig" with {'sHelpId': help_id("OEMODULETEMPLATE_HELP_ALLOW_GREETING"), 'sHelpText': help_text("OEMODULETEMPLATE_HELP_ALLOW_GREETING")} %} From 134c934b0122d5f75189dde0a0961cdd4308f8a2 Mon Sep 17 00:00:00 2001 From: Nikola Ivanovski Date: Tue, 30 Jul 2024 12:05:50 +0300 Subject: [PATCH 17/22] OXDEV-8503 Add GhA v0 dispatch and remove php 8.1 support --- .github/workflows/dispatch_module.yaml | 37 +++++++++++++++++++++----- .github/workflows/scheduled.yaml | 2 +- CHANGELOG.md | 5 ++++ composer.json | 2 +- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/.github/workflows/dispatch_module.yaml b/.github/workflows/dispatch_module.yaml index 835e251..b45ddb1 100644 --- a/.github/workflows/dispatch_module.yaml +++ b/.github/workflows/dispatch_module.yaml @@ -8,12 +8,17 @@ on: type: choice options: - 'no' - - 'PHP8.1/MySQL5.7' - - 'PHP8.1/MySQL8.0' - 'PHP8.2/MySQL5.7' - 'PHP8.2/MySQL8.0' - default: 'PHP8.1/MySQL5.7' + - 'PHP8.3/MySQL5.7' + - 'PHP8.3/MySQL8.0' + default: 'PHP8.2/MySQL8.0' description: 'Limit to one PHP/MySQL combination' + use_dev_version: + type: choice + options: ['no', 'v0'] + description: 'Use the dev version of github actions' + default: 'no' jobs: build_testplan: @@ -28,19 +33,20 @@ jobs: # shellcheck disable=SC2088 case "${{ inputs.limit }}" in "no") LIMIT='';; - "PHP8.1/MySQL5.7") LIMIT='~/defaults/php8.1_mysql5.7_only.yaml,' ;; - "PHP8.1/MySQL8.0") LIMIT='~/defaults/php8.1_mysql8.0_only.yaml,' ;; "PHP8.2/MySQL5.7") LIMIT='~/defaults/php8.2_mysql5.7_only.yaml,' ;; "PHP8.2/MySQL8.0") LIMIT='~/defaults/php8.2_mysql8.0_only.yaml,' ;; + "PHP8.3/MySQL5.7") LIMIT='~/defaults/php8.3_mysql5.7_only.yaml,' ;; + "PHP8.3/MySQL8.0") LIMIT='~/defaults/php8.3_mysql8.0_only.yaml,' ;; *) echo "Illegal choice, fix the workflow" exit 1 ;; esac # shellcheck disable=SC2088 - TESTPLAN="~/defaults/7.1.x.yaml,${LIMIT}~/module-template.yaml" + TESTPLAN="~/defaults/7.2.x.yaml,${LIMIT}~/module-template.yaml" echo "testplan=${TESTPLAN}" | tee -a "${GITHUB_OUTPUT}" dispatch_stable: + if: ${{ inputs.use_dev_version == 'no' }} needs: build_testplan uses: oxid-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v4 with: @@ -57,3 +63,22 @@ jobs: enterprise_github_token: ${{ secrets.enterprise_github_token }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + + dispatch_v0: + if: ${{ inputs.use_dev_version == 'v0' }} + needs: build_testplan + uses: oxid-eSales/github-actions/.github/workflows/call-universal_test_workflow.yml@v0 + with: + testplan: ${{ needs.build_testplan.outputs.testplan }} + runs_on: '"ubuntu-latest"' + defaults: 'v0' + plan_folder: '.github/oxid-esales' + secrets: + DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }} + DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }} + CACHE_ENDPOINT: ${{ secrets.CACHE_ENDPOINT }} + CACHE_ACCESS_KEY: ${{ secrets.CACHE_ACCESS_KEY }} + CACHE_SECRET_KEY: ${{ secrets.CACHE_SECRET_KEY }} + enterprise_github_token: ${{ secrets.enterprise_github_token }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/scheduled.yaml b/.github/workflows/scheduled.yaml index e5b21ae..de2a2df 100644 --- a/.github/workflows/scheduled.yaml +++ b/.github/workflows/scheduled.yaml @@ -11,7 +11,7 @@ jobs: if: always() uses: oxid-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v4 with: - testplan: '~/defaults/7.1.x.yaml,~/defaults/scheduled.yaml,~/module-template.yaml' + testplan: '~/defaults/7.2.x.yaml,~/defaults/scheduled.yaml,~/module-template.yaml' runs_on: '"ubuntu-latest"' defaults: 'v4' plan_folder: '.github/oxid-esales' diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ee93e4..3da4c67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [v3.1.0] - Unreleased + +### Removed +- PHP 8.1 support removed + ## [v3.0.0] - 2024-06-27 This is the stable release for v3.0.0. No changes have been made since v3.0.0-rc.1. diff --git a/composer.json b/composer.json index 5302c70..bfb6c3e 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "phpstan/phpstan": "^1.9.14", "squizlabs/php_codesniffer": "3.*", "phpmd/phpmd": "^2.11", - "oxid-esales/oxideshop-ce": "dev-b-7.1.x", + "oxid-esales/oxideshop-ce": "dev-b-7.2.x", "phpunit/phpunit": "~10.5.17", "mikey179/vfsstream": "~1.6.8", "codeception/codeception": "*", From 412c292fa8f234ca04d7fe534a3af426379e992f Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Thu, 1 Aug 2024 17:45:55 +0300 Subject: [PATCH 18/22] OXDEV-8462 Change oxNew factory example --- README.md | 2 +- services.yaml | 10 ++++- .../Admin/GreetingAdminController.php | 14 +++++-- ...equestFactory.php => UserModelFactory.php} | 8 ++-- ...face.php => UserModelFactoryInterface.php} | 8 ++-- src/Service/GreetingMessage.php | 13 +++---- src/Service/UserService.php | 38 +++++++++++++++++++ src/Service/UserServiceInterface.php | 17 +++++++++ .../Service/GreetingMessageTest.php | 10 ++--- ...ctoryTest.php => UserModelFactoryTest.php} | 12 +++--- tests/Unit/Service/GreetingMessageTest.php | 4 +- 11 files changed, 101 insertions(+), 35 deletions(-) rename src/Infrastructure/{CoreRequestFactory.php => UserModelFactory.php} (57%) rename src/Infrastructure/{CoreRequestFactoryInterface.php => UserModelFactoryInterface.php} (57%) create mode 100644 src/Service/UserService.php create mode 100644 src/Service/UserServiceInterface.php rename tests/Unit/Infrastructure/{CoreRequestFactoryTest.php => UserModelFactoryTest.php} (50%) diff --git a/README.md b/README.md index 2db5c55..a46e384 100644 --- a/README.md +++ b/README.md @@ -229,7 +229,7 @@ If you need to extend the shop class chain by overwriting, try to stick to the p * event subscriber (`OxidEsales\ModuleTemplate\Subscriber\BeforeModelUpdate`) * model with a database (`OxidEsales\ModuleTemplate\Model\GreetingTracker`) * DI service examples -* ``oxNew`` object factory example (`OxidEsales\ModuleTemplate\Greeting\Infrastructure\CoreRequestFactory`) +* ``oxNew`` object factory example (`OxidEsales\ModuleTemplate\Infrastructure\UserModelFactory`) #### Whatever you do, ensure it is covered with tests * unit/integration test diff --git a/services.yaml b/services.yaml index 2512a6c..fa8a7e6 100644 --- a/services.yaml +++ b/services.yaml @@ -9,6 +9,8 @@ services: _defaults: public: false autowire: true + bind: + OxidEsales\Eshop\Core\Request: '@=service("OxidEsales\\ModuleTemplate\\Core\\Registry").getRequest()' OxidEsales\ModuleTemplate\Core\Registry: class: OxidEsales\Eshop\Core\Registry @@ -44,5 +46,9 @@ services: class: OxidEsales\ModuleTemplate\Subscriber\BeforeModelUpdate tags: [ 'kernel.event_subscriber' ] - OxidEsales\ModuleTemplate\Infrastructure\CoreRequestFactoryInterface: - class: OxidEsales\ModuleTemplate\Infrastructure\CoreRequestFactory \ No newline at end of file + OxidEsales\ModuleTemplate\Infrastructure\UserModelFactoryInterface: + class: OxidEsales\ModuleTemplate\Infrastructure\UserModelFactory + + OxidEsales\ModuleTemplate\Service\UserServiceInterface: + class: OxidEsales\ModuleTemplate\Service\UserService + public: true diff --git a/src/Controller/Admin/GreetingAdminController.php b/src/Controller/Admin/GreetingAdminController.php index 88ad2c1..6651174 100644 --- a/src/Controller/Admin/GreetingAdminController.php +++ b/src/Controller/Admin/GreetingAdminController.php @@ -1,7 +1,7 @@ load($this->getEditObjectId())) { + $userService = $this->getServiceFromContainer(UserServiceInterface::class); + if ($this->getEditObjectId()) { + /** @var TemplateModelUser $oUser */ + $oUser = $userService->getUserById($this->getEditObjectId()); $this->addTplParam(ModuleCore::OEMT_ADMIN_GREETING_TEMPLATE_VARNAME, $oUser->getPersonalGreeting()); } diff --git a/src/Infrastructure/CoreRequestFactory.php b/src/Infrastructure/UserModelFactory.php similarity index 57% rename from src/Infrastructure/CoreRequestFactory.php rename to src/Infrastructure/UserModelFactory.php index 30a2211..35bdf16 100644 --- a/src/Infrastructure/CoreRequestFactory.php +++ b/src/Infrastructure/UserModelFactory.php @@ -9,15 +9,15 @@ namespace OxidEsales\ModuleTemplate\Infrastructure; -use OxidEsales\Eshop\Core\Request; +use OxidEsales\Eshop\Application\Model\User; -class CoreRequestFactory implements CoreRequestFactoryInterface +class UserModelFactory implements UserModelFactoryInterface { /** * @inheritDoc */ - public function create(): Request + public function create(): User { - return oxNew(Request::class); + return oxNew(User::class); } } diff --git a/src/Infrastructure/CoreRequestFactoryInterface.php b/src/Infrastructure/UserModelFactoryInterface.php similarity index 57% rename from src/Infrastructure/CoreRequestFactoryInterface.php rename to src/Infrastructure/UserModelFactoryInterface.php index d2f2d42..36c30fe 100644 --- a/src/Infrastructure/CoreRequestFactoryInterface.php +++ b/src/Infrastructure/UserModelFactoryInterface.php @@ -7,12 +7,12 @@ namespace OxidEsales\ModuleTemplate\Infrastructure; -use OxidEsales\Eshop\Core\Request; +use OxidEsales\Eshop\Application\Model\User; -interface CoreRequestFactoryInterface +interface UserModelFactoryInterface { /** - * @return Request + * @return User */ - public function create(): Request; + public function create(): User; } diff --git a/src/Service/GreetingMessage.php b/src/Service/GreetingMessage.php index 2527263..c184fa0 100644 --- a/src/Service/GreetingMessage.php +++ b/src/Service/GreetingMessage.php @@ -10,8 +10,8 @@ namespace OxidEsales\ModuleTemplate\Service; use OxidEsales\Eshop\Application\Model\User as EshopModelUser; +use OxidEsales\Eshop\Core\Request as EshopRequest; use OxidEsales\ModuleTemplate\Core\Module as ModuleCore; -use OxidEsales\ModuleTemplate\Infrastructure\CoreRequestFactoryInterface; use OxidEsales\ModuleTemplate\Model\User as TemplateModelUser; use OxidEsales\ModuleTemplate\Service\ModuleSettings as ModuleSettingsService; @@ -26,16 +26,16 @@ class GreetingMessage private $settings; /** - * @var CoreRequestFactoryInterface + * @var EshopRequest */ - private $coreRequestFactory; + private $request; public function __construct( ModuleSettingsService $settings, - CoreRequestFactoryInterface $coreRequestFactory + EshopRequest $request ) { $this->settings = $settings; - $this->coreRequestFactory = $coreRequestFactory; + $this->request = $request; } public function getGreeting(?EshopModelUser $user = null): string @@ -59,8 +59,7 @@ public function saveGreeting(EshopModelUser $user): bool private function getRequestOemtGreeting(): string { - $coreRequestService = $this->coreRequestFactory->create(); - $input = (string)$coreRequestService->getRequestParameter(ModuleCore::OEMT_GREETING_TEMPLATE_VARNAME); + $input = (string)$this->request->getRequestParameter(ModuleCore::OEMT_GREETING_TEMPLATE_VARNAME); //in real life add some input validation return (string)substr($input, 0, 253); diff --git a/src/Service/UserService.php b/src/Service/UserService.php new file mode 100644 index 0000000..1cfb923 --- /dev/null +++ b/src/Service/UserService.php @@ -0,0 +1,38 @@ +userModelFactory = $userModelFactory; + } + + public function getUserById(string $userId): EshopModelUser + { + $userModel = $this->userModelFactory->create(); + $userModel->load($userId); + + return $userModel; + } +} diff --git a/src/Service/UserServiceInterface.php b/src/Service/UserServiceInterface.php new file mode 100644 index 0000000..bc875ad --- /dev/null +++ b/src/Service/UserServiceInterface.php @@ -0,0 +1,17 @@ +getSettingsMock(ModuleSettings::GREETING_MODE_GENERIC), - $this->createMock(CoreRequestFactoryInterface::class) + $this->createStub(CoreRequest::class) ); $user = oxNew(EshopModelUser::class); @@ -33,7 +33,7 @@ public function testModulePersonalGreetingModeEmptyUser(): void { $service = new GreetingMessage( $this->getSettingsMock(), - $this->createMock(CoreRequestFactoryInterface::class) + $this->createStub(CoreRequest::class) ); $user = oxNew(EshopModelUser::class); @@ -44,7 +44,7 @@ public function testModuleGenericGreeting(): void { $service = new GreetingMessage( $this->getSettingsMock(ModuleSettings::GREETING_MODE_GENERIC), - $this->createMock(CoreRequestFactoryInterface::class) + $this->createStub(CoreRequest::class) ); $user = oxNew(EshopModelUser::class); $user->setPersonalGreeting('Hi sweetie!'); @@ -56,7 +56,7 @@ public function testModulePersonalGreeting(): void { $service = new GreetingMessage( $this->getSettingsMock(), - $this->createMock(CoreRequestFactoryInterface::class) + $this->createStub(CoreRequest::class) ); $user = oxNew(EshopModelUser::class); $user->setPersonalGreeting('Hi sweetie!'); diff --git a/tests/Unit/Infrastructure/CoreRequestFactoryTest.php b/tests/Unit/Infrastructure/UserModelFactoryTest.php similarity index 50% rename from tests/Unit/Infrastructure/CoreRequestFactoryTest.php rename to tests/Unit/Infrastructure/UserModelFactoryTest.php index 125e2e7..bf603a2 100644 --- a/tests/Unit/Infrastructure/CoreRequestFactoryTest.php +++ b/tests/Unit/Infrastructure/UserModelFactoryTest.php @@ -9,21 +9,21 @@ namespace OxidEsales\ModuleTemplate\Tests\Unit\Infrastructure; -use OxidEsales\ModuleTemplate\Infrastructure\CoreRequestFactory; +use OxidEsales\Eshop\Application\Model\User; +use OxidEsales\ModuleTemplate\Infrastructure\UserModelFactory; use PHPUnit\Framework\TestCase; -use OxidEsales\Eshop\Core\Request; /** - * @covers \OxidEsales\ModuleTemplate\Infrastructure\CoreRequestFactory + * @covers \OxidEsales\ModuleTemplate\Infrastructure\UserModelFactory */ -class CoreRequestFactoryTest extends TestCase +class UserModelFactoryTest extends TestCase { public function testCreateProducesCorrectTypeOfObjects(): void { - $coreRequestFactoryMock = $this->getMockBuilder(CoreRequestFactory::class) + $coreRequestFactoryMock = $this->getMockBuilder(UserModelFactory::class) ->onlyMethods(['create']) ->getMock(); - $this->assertInstanceOf(Request::class, $coreRequestFactoryMock->create()); + $this->assertInstanceOf(User::class, $coreRequestFactoryMock->create()); } } diff --git a/tests/Unit/Service/GreetingMessageTest.php b/tests/Unit/Service/GreetingMessageTest.php index 43082c3..48058fd 100644 --- a/tests/Unit/Service/GreetingMessageTest.php +++ b/tests/Unit/Service/GreetingMessageTest.php @@ -9,8 +9,8 @@ namespace OxidEsales\ModuleTemplate\Tests\Unit\Service; +use OxidEsales\Eshop\Core\Request as CoreRequest; use OxidEsales\ModuleTemplate\Core\Module as ModuleCore; -use OxidEsales\ModuleTemplate\Infrastructure\CoreRequestFactoryInterface; use OxidEsales\ModuleTemplate\Service\GreetingMessage; use OxidEsales\ModuleTemplate\Service\ModuleSettings; use PHPUnit\Framework\TestCase; @@ -24,7 +24,7 @@ public function testGenericGreetingNoUser(string $mode, string $expected): void { $service = new GreetingMessage( $this->createConfiguredMock(ModuleSettings::class, ['getGreetingMode' => $mode]), - $this->createMock(CoreRequestFactoryInterface::class) + $this->createStub(CoreRequest::class) ); $this->assertSame($expected, $service->getGreeting()); From e6079e43ed35b8c640a159927e934978051710ad Mon Sep 17 00:00:00 2001 From: Tatyana Koleva Date: Thu, 1 Aug 2024 18:25:05 +0300 Subject: [PATCH 19/22] OXDEV-8462 Change oxNew factory example --- README.md | 2 +- .../Admin/GreetingAdminController.php | 11 ++++-- ...equestFactory.php => UserModelFactory.php} | 8 ++-- ...face.php => UserModelFactoryInterface.php} | 8 ++-- .../Service/GreetingMessageService.php | 7 ++-- src/Greeting/Service/UserService.php | 38 +++++++++++++++++++ src/Greeting/Service/UserServiceInterface.php | 17 +++++++++ src/Greeting/services.yaml | 9 ++++- .../Service/GreetingMessageServiceTest.php | 8 ++-- .../Infrastructure/CoreRequestFactoryTest.php | 29 -------------- .../Infrastructure/UserModelFactoryTest.php | 29 ++++++++++++++ .../Service/GreetingMessageServiceTest.php | 8 ++-- 12 files changed, 118 insertions(+), 56 deletions(-) rename src/Greeting/Infrastructure/{CoreRequestFactory.php => UserModelFactory.php} (58%) rename src/Greeting/Infrastructure/{CoreRequestFactoryInterface.php => UserModelFactoryInterface.php} (58%) create mode 100644 src/Greeting/Service/UserService.php create mode 100644 src/Greeting/Service/UserServiceInterface.php delete mode 100644 tests/Unit/Greeting/Infrastructure/CoreRequestFactoryTest.php create mode 100644 tests/Unit/Greeting/Infrastructure/UserModelFactoryTest.php diff --git a/README.md b/README.md index 69265b4..02cc03e 100644 --- a/README.md +++ b/README.md @@ -233,7 +233,7 @@ If you need to extend the shop class chain by overwriting, try to stick to the p * event subscriber (`OxidEsales\ModuleTemplate\Tracker\Subscriber\BeforeModelUpdate`) * model with a database (`OxidEsales\ModuleTemplate\Tracker\Model\GreetingTracker`) * DI service examples -* ``oxNew`` object factory example (`OxidEsales\ModuleTemplate\Greeting\Infrastructure\CoreRequestFactory`) +* ``oxNew`` object factory example (`OxidEsales\ModuleTemplate\Greeting\Infrastructure\UserModelFactory`) #### Whatever you do, ensure it is covered with tests * unit/integration test diff --git a/src/Greeting/Controller/Admin/GreetingAdminController.php b/src/Greeting/Controller/Admin/GreetingAdminController.php index adce9bc..ba03e10 100644 --- a/src/Greeting/Controller/Admin/GreetingAdminController.php +++ b/src/Greeting/Controller/Admin/GreetingAdminController.php @@ -1,7 +1,7 @@ load($this->getEditObjectId())) { + $userService = $this->getService(UserServiceInterface::class); + if ($this->getEditObjectId()) { + /** @var TemplateModelUser $oUser */ + $oUser = $userService->getUserById($this->getEditObjectId()); $this->addTplParam(ModuleCore::OEMT_ADMIN_GREETING_TEMPLATE_VARNAME, $oUser->getPersonalGreeting()); } diff --git a/src/Greeting/Infrastructure/CoreRequestFactory.php b/src/Greeting/Infrastructure/UserModelFactory.php similarity index 58% rename from src/Greeting/Infrastructure/CoreRequestFactory.php rename to src/Greeting/Infrastructure/UserModelFactory.php index eaa8a6f..ee02c1c 100644 --- a/src/Greeting/Infrastructure/CoreRequestFactory.php +++ b/src/Greeting/Infrastructure/UserModelFactory.php @@ -9,15 +9,15 @@ namespace OxidEsales\ModuleTemplate\Greeting\Infrastructure; -use OxidEsales\Eshop\Core\Request; +use OxidEsales\Eshop\Application\Model\User; -class CoreRequestFactory implements CoreRequestFactoryInterface +class UserModelFactory implements UserModelFactoryInterface { /** * @inheritDoc */ - public function create(): Request + public function create(): User { - return oxNew(Request::class); + return oxNew(User::class); } } diff --git a/src/Greeting/Infrastructure/CoreRequestFactoryInterface.php b/src/Greeting/Infrastructure/UserModelFactoryInterface.php similarity index 58% rename from src/Greeting/Infrastructure/CoreRequestFactoryInterface.php rename to src/Greeting/Infrastructure/UserModelFactoryInterface.php index 3a3587b..6bd0ed2 100644 --- a/src/Greeting/Infrastructure/CoreRequestFactoryInterface.php +++ b/src/Greeting/Infrastructure/UserModelFactoryInterface.php @@ -7,12 +7,12 @@ namespace OxidEsales\ModuleTemplate\Greeting\Infrastructure; -use OxidEsales\Eshop\Core\Request; +use OxidEsales\Eshop\Application\Model\User; -interface CoreRequestFactoryInterface +interface UserModelFactoryInterface { /** - * @return Request + * @return User */ - public function create(): Request; + public function create(): User; } diff --git a/src/Greeting/Service/GreetingMessageService.php b/src/Greeting/Service/GreetingMessageService.php index 1e2cbd0..e3e604c 100644 --- a/src/Greeting/Service/GreetingMessageService.php +++ b/src/Greeting/Service/GreetingMessageService.php @@ -11,16 +11,16 @@ use OxidEsales\Eshop\Application\Model\User as EshopModelUser; use OxidEsales\Eshop\Core\Language as EshopLanguage; +use OxidEsales\Eshop\Core\Request as EshopRequest; use OxidEsales\ModuleTemplate\Core\Module as ModuleCore; use OxidEsales\ModuleTemplate\Extension\Model\User as TemplateModelUser; -use OxidEsales\ModuleTemplate\Greeting\Infrastructure\CoreRequestFactoryInterface; use OxidEsales\ModuleTemplate\Settings\Service\ModuleSettingsServiceInterface; class GreetingMessageService implements GreetingMessageServiceInterface { public function __construct( private ModuleSettingsServiceInterface $moduleSettings, - private CoreRequestFactoryInterface $coreRequestFactory, + private EshopRequest $shopRequest, private EshopLanguage $shopLanguage, ) { } @@ -62,8 +62,7 @@ public function saveGreeting(EshopModelUser $user): bool */ private function getRequestOemtGreeting(): string { - $coreRequestService = $this->coreRequestFactory->create(); - $input = (string)$coreRequestService->getRequestParameter(ModuleCore::OEMT_GREETING_TEMPLATE_VARNAME); + $input = (string)$this->shopRequest->getRequestParameter(ModuleCore::OEMT_GREETING_TEMPLATE_VARNAME); //in real life add some input validation return (string)substr($input, 0, 253); diff --git a/src/Greeting/Service/UserService.php b/src/Greeting/Service/UserService.php new file mode 100644 index 0000000..38fdd1e --- /dev/null +++ b/src/Greeting/Service/UserService.php @@ -0,0 +1,38 @@ +userModelFactory = $userModelFactory; + } + + public function getUserById(string $userId): EshopModelUser + { + $userModel = $this->userModelFactory->create(); + $userModel->load($userId); + + return $userModel; + } +} diff --git a/src/Greeting/Service/UserServiceInterface.php b/src/Greeting/Service/UserServiceInterface.php new file mode 100644 index 0000000..df3d645 --- /dev/null +++ b/src/Greeting/Service/UserServiceInterface.php @@ -0,0 +1,17 @@ +createMock(ModuleSettingsServiceInterface::class), - coreRequestFactory: $this->createStub(CoreRequestFactoryInterface::class), + shopRequest: $this->createStub(CoreRequest::class), shopLanguage: $langStub = $this->createStub(CoreLanguage::class), ); @@ -50,11 +50,11 @@ public function testGenericGreetingWithUserForPersonalMode(): void private function getSut( ModuleSettingsServiceInterface $moduleSettings = null, - CoreRequestFactoryInterface $coreRequestFactory = null, + CoreRequest $shopRequest = null, ): GreetingMessageService { return new GreetingMessageService( moduleSettings: $moduleSettings ?? $this->createStub(ModuleSettingsServiceInterface::class), - coreRequestFactory: $coreRequestFactory ?? $this->createStub(CoreRequestFactoryInterface::class), + shopRequest: $this->createStub(CoreRequest::class), shopLanguage: $shopLanguage ?? $this->createStub(CoreLanguage::class), ); } diff --git a/tests/Unit/Greeting/Infrastructure/CoreRequestFactoryTest.php b/tests/Unit/Greeting/Infrastructure/CoreRequestFactoryTest.php deleted file mode 100644 index 1adf431..0000000 --- a/tests/Unit/Greeting/Infrastructure/CoreRequestFactoryTest.php +++ /dev/null @@ -1,29 +0,0 @@ -getMockBuilder(CoreRequestFactory::class) - ->onlyMethods(['create']) - ->getMock(); - - $this->assertInstanceOf(Request::class, $coreRequestFactoryMock->create()); - } -} diff --git a/tests/Unit/Greeting/Infrastructure/UserModelFactoryTest.php b/tests/Unit/Greeting/Infrastructure/UserModelFactoryTest.php new file mode 100644 index 0000000..2e4bd71 --- /dev/null +++ b/tests/Unit/Greeting/Infrastructure/UserModelFactoryTest.php @@ -0,0 +1,29 @@ +getMockBuilder(UserModelFactory::class) + ->onlyMethods(['create']) + ->getMock(); + + $this->assertInstanceOf(User::class, $coreRequestFactoryMock->create()); + } +} diff --git a/tests/Unit/Greeting/Service/GreetingMessageServiceTest.php b/tests/Unit/Greeting/Service/GreetingMessageServiceTest.php index 53b9ab2..2192280 100644 --- a/tests/Unit/Greeting/Service/GreetingMessageServiceTest.php +++ b/tests/Unit/Greeting/Service/GreetingMessageServiceTest.php @@ -10,8 +10,8 @@ namespace OxidEsales\ModuleTemplate\Tests\Unit\Greeting\Service; use OxidEsales\Eshop\Core\Language as CoreLanguage; +use OxidEsales\Eshop\Core\Request as CoreRequest; use OxidEsales\ModuleTemplate\Core\Module as ModuleCore; -use OxidEsales\ModuleTemplate\Greeting\Infrastructure\CoreRequestFactoryInterface; use OxidEsales\ModuleTemplate\Greeting\Service\GreetingMessageService; use OxidEsales\ModuleTemplate\Settings\Service\ModuleSettingsServiceInterface; use PHPUnit\Framework\Attributes\CoversClass; @@ -24,7 +24,7 @@ public function testGenericGreetingNoUserForGenericMode(): void { $service = new GreetingMessageService( moduleSettings: $moduleSettingsStub = $this->createMock(ModuleSettingsServiceInterface::class), - coreRequestFactory: $this->createStub(CoreRequestFactoryInterface::class), + shopRequest: $this->createStub(CoreRequest::class), shopLanguage: $langStub = $this->createStub(CoreLanguage::class), ); @@ -43,7 +43,7 @@ public function testGenericGreetingWithUserForGenericMode(): void { $service = new GreetingMessageService( moduleSettings: $moduleSettingsStub = $this->createMock(ModuleSettingsServiceInterface::class), - coreRequestFactory: $this->createStub(CoreRequestFactoryInterface::class), + shopRequest: $this->createStub(CoreRequest::class), shopLanguage: $langStub = $this->createStub(CoreLanguage::class), ); @@ -62,7 +62,7 @@ public function testGenericGreetingNoUserForPersonalMode(): void { $service = new GreetingMessageService( moduleSettings: $moduleSettingsStub = $this->createMock(ModuleSettingsServiceInterface::class), - coreRequestFactory: $this->createStub(CoreRequestFactoryInterface::class), + shopRequest: $this->createStub(CoreRequest::class), shopLanguage: $this->createStub(CoreLanguage::class), ); From deb3f8088a09129fa1952f5e179d1a0f15af31d0 Mon Sep 17 00:00:00 2001 From: Nikola Ivanovski Date: Thu, 22 Aug 2024 14:35:23 +0300 Subject: [PATCH 20/22] Change GhA v0 to use light workflow --- .github/workflows/dispatch_module.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dispatch_module.yaml b/.github/workflows/dispatch_module.yaml index b45ddb1..0ca494f 100644 --- a/.github/workflows/dispatch_module.yaml +++ b/.github/workflows/dispatch_module.yaml @@ -67,7 +67,7 @@ jobs: dispatch_v0: if: ${{ inputs.use_dev_version == 'v0' }} needs: build_testplan - uses: oxid-eSales/github-actions/.github/workflows/call-universal_test_workflow.yml@v0 + uses: oxid-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v0 with: testplan: ${{ needs.build_testplan.outputs.testplan }} runs_on: '"ubuntu-latest"' From 0da25de64dbeafdf29df89bb612b0fe8f95f0e7e Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Fri, 23 Aug 2024 14:47:06 +0300 Subject: [PATCH 21/22] OXDEV-8462 Decide on the next version number by last changes Signed-off-by: Anton Fedurtsya --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2c3ea3..6468ae7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [undecided] - unreleased +## [v2.2.0] - unreleased ### Added - Admin controller From 84161d817286a6c1427378ad6131850d958d03fa Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Fri, 23 Aug 2024 14:55:12 +0300 Subject: [PATCH 22/22] Show issues if any found during commit hook execution Signed-off-by: Anton Fedurtsya --- .github/commit-hooks/pre-commit | 2 +- CHANGELOG.md | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/commit-hooks/pre-commit b/.github/commit-hooks/pre-commit index 715a914..f76d55a 100755 --- a/.github/commit-hooks/pre-commit +++ b/.github/commit-hooks/pre-commit @@ -1 +1 @@ -docker compose exec --workdir /var/www/vendor/oxid-esales/module-template php composer static \ No newline at end of file +docker compose exec -T --workdir /var/www/vendor/oxid-esales/module-template php composer static \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f7528d..0a418db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Example with extending of current admin template - ``oxNew`` model object factory example in Greeting namespace infrastructure +### Fixed +- "the input device is not a TTY" error message during github hook if problems found + ## [v3.0.0] - 2024-06-27 This is the stable release for v3.0.0. No changes have been made since v3.0.0-rc.1.