From 9d15fc1efd62303bc78aa46ecbdcb9bd09ba89b5 Mon Sep 17 00:00:00 2001 From: keywan Date: Fri, 4 Jan 2019 00:17:50 +0100 Subject: [PATCH] add tests for consistency controller - fixed getting request parameter - removed unused template code - add automatic fix for modules - change 403 to 404 (obscurity adds some security) --- Controller/CheckConsistency.php | 16 +++----- Core/InternalModule.php | 11 ++++-- .../Controller/CheckConsistencyTest.php | 37 +++++++++++++++++++ views/flow/tpl/checkconsistency.tpl | 15 +------- 4 files changed, 50 insertions(+), 29 deletions(-) create mode 100644 Tests/Integration/Controller/CheckConsistencyTest.php diff --git a/Controller/CheckConsistency.php b/Controller/CheckConsistency.php index e1ee9f3..40d64b9 100644 --- a/Controller/CheckConsistency.php +++ b/Controller/CheckConsistency.php @@ -23,19 +23,19 @@ public function init() { $oConfig = Registry::get(Config::class); - $redirectUrl = $oConfig->getShopUrl(); - $sKey = Registry::get(Request::class)('key'); + $sKey = Registry::get(Request::class)->getRequestParameter('key'); //todo: add Exeception / Logging + $utils = Registry::getUtils(); if((bool)$oConfig->getConfigParam('blACActiveCompleteCheck') == false ) { - Registry::getUtils()->redirect($redirectUrl, false, 403); + $utils->handlePageNotFoundError(); } //todo: add Exeception / Logging if($sKey != $oConfig->getConfigParam('sACActiveCompleteKey')) { - Registry::getUtils()->redirect($redirectUrl, false, 403); + $utils->handlePageNotFoundError(); } } @@ -59,13 +59,7 @@ public function render() $aModuleChecks[$sModId] = $aModule; } $this->_aViewData['aModules'] = $aModuleChecks; - $this->_aViewData['sState'] = array( - -3 => 'sfatals', - -2 => 'sfatalm', - -1 => 'serror', - 0 => 'swarning', - 1 => 'sok' - ); + return $this->sTemplate; } diff --git a/Core/InternalModule.php b/Core/InternalModule.php index d983759..0a4139b 100644 --- a/Core/InternalModule.php +++ b/Core/InternalModule.php @@ -227,23 +227,23 @@ public function checkModuleVersions() public function getTitle() { if ($this->checked !== false) { - return $this->checked; + return $this->checked['title']; } $title = parent::getTitle(); $request = Registry::getRequest(); $controller = $request->getRequestParameter('cl'); - if ($controller == 'module_list') { + if ($controller == 'module_list' || $controller == 'checkconsistency') { $fixed = $this->getModuleFixHelper()->fix($this); if ($fixed) { $title .= ' State fixed'; } - $this->checkState(); + $this->checked = $this->checkState(); if (($this->state & self::NEED_MANUAL_FIXED) == self::NEED_MANUAL_FIXED) { $title .= ' Issue found!'; } - $this->checked = $title; + $this->checked['title'] = $title; } return $title; } @@ -536,6 +536,9 @@ public function getModuleNameSpace($sModulePath) */ public function checkState($sTitle = '') { + if ($this->checked !== false) { + return $this->checked; + } $oModule = $this; $aModule = array(); $aModule['oxid'] = $sId = $oModule->getId(); diff --git a/Tests/Integration/Controller/CheckConsistencyTest.php b/Tests/Integration/Controller/CheckConsistencyTest.php new file mode 100644 index 0000000..88a78a9 --- /dev/null +++ b/Tests/Integration/Controller/CheckConsistencyTest.php @@ -0,0 +1,37 @@ +render(); + $this->assertSame('checkconsistency.tpl', $result); + } + + public function testInit() + { + $controller = oxNew(CheckConsistency::class); + $mockBuilder = $this->getMockBuilder(Utils::class); + $mockBuilder->setMethods(['handlePageNotFoundError']); + $utils = $mockBuilder->getMock(); + $utils->expects($this->once())->method("handlePageNotFoundError"); + Registry::set(Utils::class, $utils); + $controller->init(); + } + +} \ No newline at end of file diff --git a/views/flow/tpl/checkconsistency.tpl b/views/flow/tpl/checkconsistency.tpl index bead435..adcd5c2 100644 --- a/views/flow/tpl/checkconsistency.tpl +++ b/views/flow/tpl/checkconsistency.tpl @@ -79,25 +79,12 @@ [{include file="items.tpl" title="AC_MI_EVENTS" items=$ModId.aEvents}] - [{if $ModId.aEvents|@count == 0 - && $ModId.aSettings|@count == 0 - && $ModId.aControllers|@count == 0 - && $ModId.aTemplates|@count == 0 - && $ModId.aBlocks|@count == 0 - && $ModId.aFiles|@count == 0 - && $ModId.aExtended|@count == 0 - && $ModId.aVersions|@count == 0 - }] - - - [{/if}] [{/foreach}]
[{oxmultilang ident="AC_LEGEND"}] : - [{oxmultilang ident="AC_STATE_OK"}] [{oxmultilang ident="AC_STATE_OK_LABEL"}] - [{oxmultilang ident="AC_STATE_WA"}] [{oxmultilang ident="AC_STATE_WA_LABEL"}] - [{oxmultilang ident="AC_STATE_ER"}] [{oxmultilang ident="AC_STATE_ER_LABEL"}] + [{oxmultilang ident="AC_STATE_OK"}] [{oxmultilang ident="AC_STATE_OK"}] [{oxmultilang ident="AC_STATE_FM"}] [{oxmultilang ident="AC_STATE_FM_LABEL"}] [{oxmultilang ident="AC_STATE_FS"}] [{oxmultilang ident="AC_STATE_FS_LABEL"}]