Skip to content

Commit

Permalink
Merge pull request #52 from OXIDprojects/c-test
Browse files Browse the repository at this point in the history
add tests for consistency controller
  • Loading branch information
keywan-ghadami-oxid authored Jan 4, 2019
2 parents 0acb8a5 + 9d15fc1 commit d55e38e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 29 deletions.
16 changes: 5 additions & 11 deletions Controller/CheckConsistency.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand All @@ -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;
}

Expand Down
11 changes: 7 additions & 4 deletions Core/InternalModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= ' <strong style="color: #00e200">State fixed</strong>';
}
$this->checkState();
$this->checked = $this->checkState();
if (($this->state & self::NEED_MANUAL_FIXED) == self::NEED_MANUAL_FIXED) {
$title .= ' <strong style="color: #009ddb">Issue found!</strong>';
}

$this->checked = $title;
$this->checked['title'] = $title;
}
return $title;
}
Expand Down Expand Up @@ -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();
Expand Down
37 changes: 37 additions & 0 deletions Tests/Integration/Controller/CheckConsistencyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Created by PhpStorm.
* User: keywan
* Date: 04.01.19
* Time: 00:01
*/

namespace OxidCommunity\ModuleInternals\Tests\Integration\Controller;

use OxidEsales\TestingLibrary\UnitTestCase;
use OxidCommunity\ModuleInternals\Controller\CheckConsistency;
use OxidEsales\Eshop\Core\Utils;
use OxidEsales\Eshop\Core\Registry;

class CheckConsistencyTest extends UnitTestCase
{

public function testRender()
{
$controller = oxNew(CheckConsistency::class);
$result = $controller->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();
}

}
15 changes: 1 addition & 14 deletions views/flow/tpl/checkconsistency.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
</div>
[{/foreach}]
<div class="actions">
<b>[{oxmultilang ident="AC_LEGEND"}] : </b>
<span class="state sok">[{oxmultilang ident="AC_STATE_OK"}]</span> <i>[{oxmultilang ident="AC_STATE_OK_LABEL"}]</i>
<span class="state swarning">[{oxmultilang ident="AC_STATE_WA"}]</span> <i>[{oxmultilang ident="AC_STATE_WA_LABEL"}]</i>
<span class="state serror">[{oxmultilang ident="AC_STATE_ER"}]</span> <i>[{oxmultilang ident="AC_STATE_ER_LABEL"}]</i>
<span class="state sok">[{oxmultilang ident="AC_STATE_OK"}]</span> <i>[{oxmultilang ident="AC_STATE_OK"}]</i>
<span class="state sfatalm">[{oxmultilang ident="AC_STATE_FM"}]</span> <i>[{oxmultilang ident="AC_STATE_FM_LABEL"}]</i>
<span class="state sfatals">[{oxmultilang ident="AC_STATE_FS"}]</span> <i>[{oxmultilang ident="AC_STATE_FS_LABEL"}]</i>
</div>
Expand Down

0 comments on commit d55e38e

Please sign in to comment.