-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OXDEV-8462 Add admin controller example
- Loading branch information
1 parent
24dd725
commit 7297ff3
Showing
8 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © MB Arbatos Klubas. 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\ModuleTemplate\Extension\Model\User; | ||
use OxidEsales\Eshop\Application\Controller\Admin\AdminController; | ||
|
||
class GreetingAdminController extends AdminController | ||
{ | ||
protected $_sThisTemplate = '@oe_moduletemplate/admin/user_greetings'; | ||
|
||
public function render() | ||
{ | ||
$oUser = oxNew(User::class); | ||
if ($oUser->load($this->getEditObjectId())) { | ||
$this->addTplParam(ModuleCore::OEMT_ADMIN_GREETING_TEMPLATE_VARNAME, $oUser->getPersonalGreeting()); | ||
} | ||
|
||
return parent::render(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
tests/Integration/Greeting/Controller/Admin/GreetingAdminControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\ModuleTemplate\Tests\Integration\Controller\Admin; | ||
|
||
use OxidEsales\Eshop\Application\Model\User as EshopModelUser; | ||
use OxidEsales\ModuleTemplate\Greeting\Controller\Admin\GreetingAdminController; | ||
use OxidEsales\ModuleTemplate\Core\Module as ModuleCore; | ||
use OxidEsales\ModuleTemplate\Tests\Integration\IntegrationTestCase; | ||
|
||
/* | ||
* We want to test controller behavior going 'full way'. | ||
* No mocks, we go straight to the database (full integration)). | ||
*/ | ||
final class GreetingAdminControllerTest extends IntegrationTestCase | ||
{ | ||
public const TEST_USER_ID = '_testuser'; | ||
|
||
public const TEST_GREETING = 'Hello there!'; | ||
|
||
public function testRender(): void | ||
{ | ||
$this->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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% include "headitem.html.twig" with {title: "GENERAL_ADMIN_TITLE"|translate} %} | ||
|
||
<form action="{{ oViewConf.getSelfLink() }}" method="post"> | ||
{{ oViewConf.getHiddenSid()|raw }} | ||
<input type="hidden" name="oxid" value="{{ oxid }}"> | ||
<input type="hidden" name="cl" value="oemt_admin_greeting"> | ||
</form> | ||
|
||
<h1 class="page-header">{{ translate({ ident: "OEMODULETEMPLATE_GREETING_TITLE" }) }}</h1> | ||
|
||
{% if greeting_message %} | ||
<div>{{ translate({ ident: "OEMODULETEMPLATE_GREETING_MESSAGE_TEXT" }) }} {{ greeting_message }}</div> | ||
{% else %} | ||
<div>{{ translate({ ident: "OEMODULETEMPLATE_NO_GREETING_TEXT" }) }}</div> | ||
{% endif %} | ||
|
||
{% include "bottomnaviitem.html.twig" %} | ||
{% include "bottomitem.html.twig" %} |