Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Mage_Adminhtml_Block_Template::isOutputEnabled() for invalid module #4320

Merged
merged 6 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions app/code/core/Mage/Adminhtml/Block/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,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 @@ -50,10 +50,7 @@ public function getFormKey()
*/
public function isOutputEnabled($moduleName = null)
{
if ($moduleName === null) {
$moduleName = $this->getModuleName();
}
sreichel marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -120,7 +120,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 @@ -135,10 +135,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
80 changes: 80 additions & 0 deletions tests/unit/Mage/Adminhtml/Block/TemplateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?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 'Mage_Core' => [
true,
'Mage_Core',
];
sreichel marked this conversation as resolved.
Show resolved Hide resolved
yield 'Not_Exits' => [
false,
'Not_Exits',
];
sreichel marked this conversation as resolved.
Show resolved Hide resolved
}

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