Skip to content

Commit

Permalink
Fix Mage_Adminhtml_Block_Template::isOutputEnabled() for invalid mo…
Browse files Browse the repository at this point in the history
…dule (#4320)

* fix isOutputEnabled

* Update tests/unit/Mage/Adminhtml/Block/TemplateTest.php

Co-authored-by: Justin Beaty <51970393+justinbeaty@users.noreply.github.com>

* fix

OpenMage/magento-lts#4320 (comment)

* updated tests

---------

Co-authored-by: Justin Beaty <51970393+justinbeaty@users.noreply.github.com>
  • Loading branch information
2 people authored and github-actions[bot] committed Oct 31, 2024
1 parent f2029b9 commit 8418701
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 7 deletions.
5 changes: 3 additions & 2 deletions app/code/core/Mage/Adminhtml/Block/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getFormKey()
}

/**
* Check whether or not the module output is enabled
* Check whether the module output is enabled
*
* Because many module blocks belong to Adminhtml module,
* the feature "Disable module output" doesn't cover Admin area
Expand All @@ -52,7 +52,8 @@ public function isOutputEnabled($moduleName = null)
if ($moduleName === null) {
$moduleName = $this->getModuleName();
}
return !Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $moduleName);

return Mage::helper('core')->isModuleOutputEnabled($moduleName);
}

/**
Expand Down
7 changes: 2 additions & 5 deletions app/code/core/Mage/Core/Helper/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected function _getModuleName()
}

/**
* Check whether or not the module output is enabled in Configuration
* Check whether the module output is enabled in Configuration
*
* @param string $moduleName Full module name
* @return bool
Expand All @@ -131,10 +131,7 @@ public function isModuleOutputEnabled($moduleName = null)
return false;
}

if (Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $moduleName)) {
return false;
}
return true;
return !Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $moduleName);
}

/**
Expand Down
93 changes: 93 additions & 0 deletions tests/unit/Mage/Adminhtml/Block/TemplateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

/**
* OpenMage
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available at https://opensource.org/license/osl-3-0-php
*
* @category OpenMage
* @package OpenMage_Tests
* @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace OpenMage\Tests\Unit\Mage\Adminhtml\Block;

use Generator;
use Mage;
use Mage_Adminhtml_Block_Template;
use PHPUnit\Framework\TestCase;

class TemplateTest extends TestCase
{
public Mage_Adminhtml_Block_Template $subject;

public function setUp(): void
{
Mage::app();
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
$this->subject = new Mage_Adminhtml_Block_Template();
}

/**
* @see Mage_Core_Model_Session::getFormKey()
* @group Mage_Adminhtml
* @group Mage_Adminhtml_Block
* @group runInSeparateProcess
* @runInSeparateProcess
*/
public function testGetFormKey(): void
{
$this->assertIsString($this->subject->getFormKey());
}

/**
* @covers Mage_Adminhtml_Block_Template::isOutputEnabled()
* @dataProvider provideIsOutputEnabled
* @group Mage_Adminhtml
* @group Mage_Adminhtml_Block
*/
public function testIsOutputEnabled(bool $expectedResult, ?string $moduleName): void
{
$this->assertSame($expectedResult, $this->subject->isOutputEnabled($moduleName));
}

public function provideIsOutputEnabled(): Generator
{
yield 'null' => [
true,
null, #Mage_Adminhtml
];
yield 'Mage_Core' => [
true,
'Mage_Core',
];
yield 'Not_Exist' => [
false,
'Not_Exist',
];
}

/**
* @group Mage_Adminhtml
* @group Mage_Adminhtml_Block
*/
public function testGetModuleName(): void
{
$this->assertSame('Mage_Adminhtml', $this->subject->getModuleName());
}

/**
* @see Mage_Core_Model_Input_Filter_MaliciousCode::filter()
* @group Mage_Adminhtml
* @group Mage_Adminhtml_Block
*/
public function testMaliciousCodeFilter(): void
{
$this->assertIsString($this->subject->maliciousCodeFilter(''));
}
}

0 comments on commit 8418701

Please sign in to comment.