Skip to content

Commit d3bfa19

Browse files
authored
PHP8.1: Added getter method for Mage_Adminhtml_Block_Widget_Grid_Column::getType() to return string (#4238)
* Added getter method to return string * Added test * Added test * Fixed test * Fixed test
1 parent 468eaf3 commit d3bfa19

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class Mage_Adminhtml_Block_Widget_Grid_Column extends Mage_Adminhtml_Block_Widge
3838
protected $_type;
3939
protected $_cssClass = null;
4040

41+
/**
42+
* @param Mage_Adminhtml_Block_Widget_Grid $grid
43+
* @return $this
44+
*/
4145
public function setGrid($grid)
4246
{
4347
$this->_grid = $grid;
@@ -46,6 +50,9 @@ public function setGrid($grid)
4650
return $this;
4751
}
4852

53+
/**
54+
* @return Mage_Adminhtml_Block_Widget_Grid
55+
*/
4956
public function getGrid()
5057
{
5158
return $this->_grid;
@@ -160,6 +167,7 @@ public function getRowField(Varien_Object $row)
160167
*/
161168
$frameCallback = $this->getFrameCallback();
162169
if (is_array($frameCallback)) {
170+
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
163171
$renderedValue = call_user_func($frameCallback, $renderedValue, $row, $this, false);
164172
}
165173

@@ -188,6 +196,7 @@ public function getRowFieldExport(Varien_Object $row)
188196
*/
189197
$frameCallback = $this->getFrameCallback();
190198
if (is_array($frameCallback)) {
199+
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
191200
$renderedValue = call_user_func($frameCallback, $renderedValue, $row, $this, true);
192201
}
193202

@@ -222,15 +231,22 @@ protected function &_applyDecorators($value, $decorators)
222231
return $value;
223232
}
224233

234+
/**
235+
* @param string $renderer
236+
* @return $this
237+
*/
225238
public function setRenderer($renderer)
226239
{
227240
$this->_renderer = $renderer;
228241
return $this;
229242
}
230243

244+
/**
245+
* @return string
246+
*/
231247
protected function _getRendererByType()
232248
{
233-
$type = strtolower((string)$this->getType());
249+
$type = strtolower($this->getType());
234250
$renderers = $this->getGrid()->getColumnRenderers();
235251

236252
if (is_array($renderers) && isset($renderers[$type])) {
@@ -317,15 +333,22 @@ public function getRenderer()
317333
return $this->_renderer;
318334
}
319335

336+
/**
337+
* @param string $filterClass
338+
* @return void
339+
*/
320340
public function setFilter($filterClass)
321341
{
322342
$this->_filter = $this->getLayout()->createBlock($filterClass)
323343
->setColumn($this);
324344
}
325345

346+
/**
347+
* @return string
348+
*/
326349
protected function _getFilterByType()
327350
{
328-
$type = strtolower((string)$this->getType());
351+
$type = strtolower($this->getType());
329352
$filters = $this->getGrid()->getColumnFilters();
330353
if (is_array($filters) && isset($filters[$type])) {
331354
return $filters[$type];
@@ -424,4 +447,9 @@ public function getExportHeader()
424447
}
425448
return $this->getHeader();
426449
}
450+
451+
public function getType(): string
452+
{
453+
return (string) $this->_getData('type');
454+
}
427455
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/**
4+
* OpenMage
5+
*
6+
* This source file is subject to the Open Software License (OSL 3.0)
7+
* that is bundled with this package in the file LICENSE.txt.
8+
* It is also available at https://opensource.org/license/osl-3-0-php
9+
*
10+
* @category OpenMage
11+
* @package OpenMage_Tests
12+
* @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org)
13+
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
14+
*/
15+
16+
declare(strict_types=1);
17+
18+
namespace OpenMage\Tests\Unit\Mage\Adminhtml\Block\Widget\Grid;
19+
20+
use Mage_Adminhtml_Block_Widget_Grid_Column;
21+
use PHPUnit\Framework\TestCase;
22+
23+
class ColumnTest extends TestCase
24+
{
25+
public Mage_Adminhtml_Block_Widget_Grid_Column $subject;
26+
27+
public function setUp(): void
28+
{
29+
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
30+
$this->subject = new Mage_Adminhtml_Block_Widget_Grid_Column();
31+
}
32+
33+
/**
34+
* @group Mage_Adminhtml
35+
* @group Mage_Adminhtml_Block
36+
*/
37+
public function testGetType(): void
38+
{
39+
$this->assertSame('', $this->subject->getType());
40+
41+
$this->subject->setType('text');
42+
$this->assertSame('text', $this->subject->getType());
43+
}
44+
}

tests/unit/Mage/Core/Model/ConfigTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<?php
22

3+
/**
4+
* OpenMage
5+
*
6+
* This source file is subject to the Open Software License (OSL 3.0)
7+
* that is bundled with this package in the file LICENSE.txt.
8+
* It is also available at https://opensource.org/license/osl-3-0-php
9+
*
10+
* @category OpenMage
11+
* @package OpenMage_Tests
12+
* @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org)
13+
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
14+
*/
15+
316
declare(strict_types=1);
417

518
namespace OpenMage\Tests\Unit\Mage\Core\Model;

tests/unit/Mage/Core/Model/UrlTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ public function setUp(): void
3131
$this->subject = Mage::getModel('core/url');
3232
}
3333

34+
/**
35+
* @group Mage_Core
36+
* @group Mage_Core_Model
37+
*/
38+
public function testEscape(): void
39+
{
40+
$this->assertSame('%22%27%3E%3C', $this->subject->escape('"\'><'));
41+
}
42+
3443
/**
3544
* @group Mage_Core
3645
* @group Mage_Core_Model

0 commit comments

Comments
 (0)