From 61e2584b13cd455a0b4be551333cc2b304edf4c1 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Wed, 2 Oct 2024 01:18:39 +0200 Subject: [PATCH 1/5] Added getter method to return string --- .../Adminhtml/Block/Widget/Grid/Column.php | 32 +++++++++++++++++-- tests/unit/Mage/Core/Model/UrlTest.php | 9 ++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php index 34e54f3406b..bf71385667d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php @@ -38,6 +38,10 @@ class Mage_Adminhtml_Block_Widget_Grid_Column extends Mage_Adminhtml_Block_Widge protected $_type; protected $_cssClass = null; + /** + * @param Mage_Adminhtml_Block_Widget_Grid $grid + * @return $this + */ public function setGrid($grid) { $this->_grid = $grid; @@ -46,6 +50,9 @@ public function setGrid($grid) return $this; } + /** + * @return Mage_Adminhtml_Block_Widget_Grid + */ public function getGrid() { return $this->_grid; @@ -160,6 +167,7 @@ public function getRowField(Varien_Object $row) */ $frameCallback = $this->getFrameCallback(); if (is_array($frameCallback)) { + // phpcs:ignore Ecg.Security.ForbiddenFunction.Found $renderedValue = call_user_func($frameCallback, $renderedValue, $row, $this, false); } @@ -188,6 +196,7 @@ public function getRowFieldExport(Varien_Object $row) */ $frameCallback = $this->getFrameCallback(); if (is_array($frameCallback)) { + // phpcs:ignore Ecg.Security.ForbiddenFunction.Found $renderedValue = call_user_func($frameCallback, $renderedValue, $row, $this, true); } @@ -222,15 +231,22 @@ protected function &_applyDecorators($value, $decorators) return $value; } + /** + * @param string $renderer + * @return $this + */ public function setRenderer($renderer) { $this->_renderer = $renderer; return $this; } + /** + * @return string + */ protected function _getRendererByType() { - $type = strtolower((string)$this->getType()); + $type = strtolower($this->getType()); $renderers = $this->getGrid()->getColumnRenderers(); if (is_array($renderers) && isset($renderers[$type])) { @@ -317,15 +333,22 @@ public function getRenderer() return $this->_renderer; } + /** + * @param string $filterClass + * @return void + */ public function setFilter($filterClass) { $this->_filter = $this->getLayout()->createBlock($filterClass) ->setColumn($this); } + /** + * @return string + */ protected function _getFilterByType() { - $type = strtolower((string)$this->getType()); + $type = strtolower($this->getType()); $filters = $this->getGrid()->getColumnFilters(); if (is_array($filters) && isset($filters[$type])) { return $filters[$type]; @@ -424,4 +447,9 @@ public function getExportHeader() } return $this->getHeader(); } + + public function getType(): string + { + return (string) $this->_getData('type'); + } } diff --git a/tests/unit/Mage/Core/Model/UrlTest.php b/tests/unit/Mage/Core/Model/UrlTest.php index c6c644783ec..86841586f7b 100644 --- a/tests/unit/Mage/Core/Model/UrlTest.php +++ b/tests/unit/Mage/Core/Model/UrlTest.php @@ -31,6 +31,15 @@ public function setUp(): void $this->subject = Mage::getModel('core/url'); } + /** + * @group Mage_Core + * @group Mage_Core_Model + */ + public function testEscape(): void + { + $this->assertSame('%22%27%3E%3C', $this->subject->escape('"\'><')); + } + /** * @group Mage_Core * @group Mage_Core_Model From b7aadc7804d272ef6f02c826372551083a9ff67e Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Wed, 2 Oct 2024 01:33:06 +0200 Subject: [PATCH 2/5] Added test --- .../Block/Widget/Grid/ColumnTest.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php diff --git a/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php b/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php new file mode 100644 index 00000000000..762de14d167 --- /dev/null +++ b/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php @@ -0,0 +1,28 @@ +subject = new Mage_Adminhtml_Block_Widget_Grid_Column(); + } + + /** + * @group Mage_Adminhtml + * @group Mage_Adminhtml_Block + */ + public function testGetType(): void + { + $this->assertIsString($this->subject->getType()); + } +} From bb4357cf63ebe1b8c0ef0fca570a02da07783d2a Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Wed, 2 Oct 2024 01:35:01 +0200 Subject: [PATCH 3/5] Added test --- .../Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php | 13 +++++++++++++ tests/unit/Mage/Core/Model/ConfigTest.php | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php b/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php index 762de14d167..e15ef2f6009 100644 --- a/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php +++ b/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php @@ -1,5 +1,18 @@ Date: Wed, 2 Oct 2024 01:50:04 +0200 Subject: [PATCH 4/5] Fixed test --- tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php b/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php index e15ef2f6009..6018495231c 100644 --- a/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php +++ b/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php @@ -36,6 +36,7 @@ public function setUp(): void */ public function testGetType(): void { - $this->assertIsString($this->subject->getType()); + $this->subject->setType('text'); + $this->assertSame('text', $this->subject->getType()); } } From cda8fbe700db7359b60e5dadef4779f46e4f2891 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Wed, 2 Oct 2024 01:50:04 +0200 Subject: [PATCH 5/5] Fixed test --- tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php b/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php index e15ef2f6009..f5589b383c2 100644 --- a/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php +++ b/tests/unit/Mage/Adminhtml/Block/Widget/Grid/ColumnTest.php @@ -36,6 +36,9 @@ public function setUp(): void */ public function testGetType(): void { - $this->assertIsString($this->subject->getType()); + $this->assertSame('', $this->subject->getType()); + + $this->subject->setType('text'); + $this->assertSame('text', $this->subject->getType()); } }