From 1b255256b11bfae00b32017405a549a3e175df5e Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Tue, 29 Oct 2024 16:46:44 +0100 Subject: [PATCH 1/4] fix isOutputEnabled --- .../core/Mage/Adminhtml/Block/Template.php | 7 +- app/code/core/Mage/Core/Helper/Abstract.php | 7 +- .../Mage/Adminhtml/Block/TemplateTest.php | 80 +++++++++++++++++++ 3 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 tests/unit/Mage/Adminhtml/Block/TemplateTest.php diff --git a/app/code/core/Mage/Adminhtml/Block/Template.php b/app/code/core/Mage/Adminhtml/Block/Template.php index 6816f2da30c..678cc90eac5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Template.php +++ b/app/code/core/Mage/Adminhtml/Block/Template.php @@ -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 @@ -50,10 +50,7 @@ public function getFormKey() */ 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); } /** diff --git a/app/code/core/Mage/Core/Helper/Abstract.php b/app/code/core/Mage/Core/Helper/Abstract.php index 3f5459db500..27c15ea338d 100644 --- a/app/code/core/Mage/Core/Helper/Abstract.php +++ b/app/code/core/Mage/Core/Helper/Abstract.php @@ -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 @@ -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); } /** diff --git a/tests/unit/Mage/Adminhtml/Block/TemplateTest.php b/tests/unit/Mage/Adminhtml/Block/TemplateTest.php new file mode 100644 index 00000000000..a08ee2befe7 --- /dev/null +++ b/tests/unit/Mage/Adminhtml/Block/TemplateTest.php @@ -0,0 +1,80 @@ +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', + ]; + yield 'Not_Exits' => [ + false, + 'Not_Exits', + ]; + } + + /** + * @see Mage_Core_Model_Input_Filter_MaliciousCode::filter() + * @group Mage_Adminhtml + * @group Mage_Adminhtml_Block + */ + public function testMaliciousCodeFilter(): void + { + $this->assertIsString($this->subject->maliciousCodeFilter('')); + } +} From 879af9bc303c3ff8aab3fb23b61004bb515f5a84 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Tue, 29 Oct 2024 18:06:48 +0100 Subject: [PATCH 2/4] Update tests/unit/Mage/Adminhtml/Block/TemplateTest.php Co-authored-by: Justin Beaty <51970393+justinbeaty@users.noreply.github.com> --- tests/unit/Mage/Adminhtml/Block/TemplateTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/Mage/Adminhtml/Block/TemplateTest.php b/tests/unit/Mage/Adminhtml/Block/TemplateTest.php index a08ee2befe7..71696c54250 100644 --- a/tests/unit/Mage/Adminhtml/Block/TemplateTest.php +++ b/tests/unit/Mage/Adminhtml/Block/TemplateTest.php @@ -62,9 +62,9 @@ public function provideIsOutputEnabled(): Generator true, 'Mage_Core', ]; - yield 'Not_Exits' => [ + yield 'Not_Exist' => [ false, - 'Not_Exits', + 'Not_Exist', ]; } From e822e5af53d8ec1124a86584e383966cfe3c5724 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Tue, 29 Oct 2024 18:07:55 +0100 Subject: [PATCH 3/4] fix https://github.com/OpenMage/magento-lts/pull/4320#discussion_r1821212246 --- app/code/core/Mage/Adminhtml/Block/Template.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/core/Mage/Adminhtml/Block/Template.php b/app/code/core/Mage/Adminhtml/Block/Template.php index 678cc90eac5..c82e6aa07e0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Template.php +++ b/app/code/core/Mage/Adminhtml/Block/Template.php @@ -50,6 +50,10 @@ public function getFormKey() */ public function isOutputEnabled($moduleName = null) { + if ($moduleName === null) { + $moduleName = $this->getModuleName(); + } + return Mage::helper('core')->isModuleOutputEnabled($moduleName); } From b7f981cbdc1e7bd7afed08e3a1c2140aec527778 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Tue, 29 Oct 2024 18:21:34 +0100 Subject: [PATCH 4/4] updated tests --- tests/unit/Mage/Adminhtml/Block/TemplateTest.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/unit/Mage/Adminhtml/Block/TemplateTest.php b/tests/unit/Mage/Adminhtml/Block/TemplateTest.php index 71696c54250..ea770f2e441 100644 --- a/tests/unit/Mage/Adminhtml/Block/TemplateTest.php +++ b/tests/unit/Mage/Adminhtml/Block/TemplateTest.php @@ -51,13 +51,17 @@ public function testGetFormKey(): void * @group Mage_Adminhtml * @group Mage_Adminhtml_Block */ - public function testIsOutputEnabled(bool $expectedResult, string $moduleName): void + 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', @@ -68,6 +72,15 @@ public function provideIsOutputEnabled(): Generator ]; } + /** + * @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