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} %}
+
+
+
+
+
+{% 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 @@