Skip to content

Commit

Permalink
Merge branch 'b-7.1.x' into b-7.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
TitaKoleva committed Aug 8, 2024
2 parents 134c934 + e6079e4 commit a7e4052
Show file tree
Hide file tree
Showing 26 changed files with 394 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.1.0] - Unreleased

### Removed
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` - 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
Expand All @@ -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\UserModelFactory`)

#### Whatever you do, ensure it is covered with tests
* unit/integration test
Expand Down
10 changes: 10 additions & 0 deletions menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="ISO-8859-15"?>
<OX>
<OXMENU id="NAVIGATION_ESHOPADMIN">
<MAINMENU id="mxuadmin">
<SUBMENU id="mxusers">
<TAB id="tbcluser_greetings" cl="oemt_admin_greeting" />
</SUBMENU>
</MAINMENU>
</OXMENU>
</OX>
3 changes: 2 additions & 1 deletion metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
32 changes: 32 additions & 0 deletions src/Greeting/Controller/Admin/GreetingAdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\ModuleTemplate\Greeting\Controller\Admin;

use OxidEsales\ModuleTemplate\Core\Module as ModuleCore;
use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
use OxidEsales\ModuleTemplate\Extension\Model\User as TemplateModelUser;
use OxidEsales\ModuleTemplate\Greeting\Service\UserServiceInterface;

class GreetingAdminController extends AdminController
{
protected $_sThisTemplate = '@oe_moduletemplate/admin/user_greetings';

public function render()
{
$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());
}

return parent::render();
}
}
23 changes: 23 additions & 0 deletions src/Greeting/Infrastructure/UserModelFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\ModuleTemplate\Greeting\Infrastructure;

use OxidEsales\Eshop\Application\Model\User;

class UserModelFactory implements UserModelFactoryInterface
{
/**
* @inheritDoc
*/
public function create(): User
{
return oxNew(User::class);
}
}
18 changes: 18 additions & 0 deletions src/Greeting/Infrastructure/UserModelFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

namespace OxidEsales\ModuleTemplate\Greeting\Infrastructure;

use OxidEsales\Eshop\Application\Model\User;

interface UserModelFactoryInterface
{
/**
* @return User
*/
public function create(): User;
}
38 changes: 38 additions & 0 deletions src/Greeting/Service/UserService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\ModuleTemplate\Greeting\Service;

use OxidEsales\Eshop\Application\Model\User as EshopModelUser;
use OxidEsales\ModuleTemplate\Greeting\Infrastructure\UserModelFactoryInterface;

/**
* @extendable-class
*/
class UserService implements UserServiceInterface
{
/**
* @var UserModelFactoryInterface
*/
private $userModelFactory;

public function __construct(
UserModelFactoryInterface $userModelFactory
) {
$this->userModelFactory = $userModelFactory;
}

public function getUserById(string $userId): EshopModelUser
{
$userModel = $this->userModelFactory->create();
$userModel->load($userId);

return $userModel;
}
}
17 changes: 17 additions & 0 deletions src/Greeting/Service/UserServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\ModuleTemplate\Greeting\Service;

use OxidEsales\Eshop\Application\Model\User as EshopModelUser;

interface UserServiceInterface
{
public function getUserById(string $userId): EshopModelUser;
}
9 changes: 8 additions & 1 deletion src/Greeting/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ services:

OxidEsales\ModuleTemplate\Greeting\Service\GreetingMessageServiceInterface:
class: OxidEsales\ModuleTemplate\Greeting\Service\GreetingMessageService
public: true
public: true

OxidEsales\ModuleTemplate\Greeting\Infrastructure\UserModelFactoryInterface:
class: OxidEsales\ModuleTemplate\Greeting\Infrastructure\UserModelFactory

OxidEsales\ModuleTemplate\Greeting\Service\UserServiceInterface:
class: OxidEsales\ModuleTemplate\Greeting\Service\UserService
public: true
5 changes: 5 additions & 0 deletions tests/Codeception/Acceptance.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
66 changes: 66 additions & 0 deletions tests/Codeception/Acceptance/Admin/GreetingAdminCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\ModuleTemplate\Tests\Codeception\Acceptance\Admin;

use OxidEsales\Codeception\Module\Translation\Translator;
use OxidEsales\ModuleTemplate\Tests\Codeception\Support\AcceptanceTester;

/**
* @group oe_moduletemplate
* @group oe_moduletemplate_admin
*/
final class GreetingAdminCest
{
public function _before(AcceptanceTester $I): void
{
//ensure each test start from same environment
$I->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(),
]
);
}
}
2 changes: 1 addition & 1 deletion tests/Codeception/Acceptance/GreetingCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/Codeception/Acceptance/ModuleCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/Codeception/Acceptance/UpdateGreetingCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions tests/Codeception/Support/AcceptanceTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions tests/Codeception/Support/Data/fixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@
'email' => '[email protected]',
'password' => 'useruser',
],
'adminUser' => [
'OXID' => 'oxadminuser',
'email' => '[email protected]',
'password' => 'useruser',
],
];
3 changes: 2 additions & 1 deletion tests/Codeception/Support/Data/fixtures.sql
Original file line number Diff line number Diff line change
@@ -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,'[email protected]','$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,'[email protected]','$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,'[email protected]','$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');
Loading

0 comments on commit a7e4052

Please sign in to comment.