Skip to content

Commit

Permalink
Fixed null deprecation in `Mage_Catalog_Model_Product_Option_Type_Tex…
Browse files Browse the repository at this point in the history
…t::validateUserValue()` (#4357)

* Fixed null deprecation in Mage/Catalog/Model/Product/Option/Type/Text

* Added test

* Added method

* Changed at source.

* Fix bug on array to string conversion on date input type.

* Revert eveything.

---------

Co-authored-by: Sven Reichel <[email protected]>
  • Loading branch information
kiatng and sreichel authored Nov 22, 2024
1 parent 8033a6e commit 11db607
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
*/
class Mage_Catalog_Model_Product_Option_Type_Text extends Mage_Catalog_Model_Product_Option_Type_Default
{
public function getUserValue(): string
{
return (string) $this->getDataByKey('user_value');
}

/**
* Validate user input for option
*
* @throws Mage_Core_Exception
* @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
* @return Mage_Catalog_Model_Product_Option_Type_Default
* @return $this
*/
public function validateUserValue($values)
{
Expand Down
81 changes: 81 additions & 0 deletions tests/unit/Mage/Catalog/Model/Product/Option/Type/TextTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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\Catalog\Model\Product\Option\Type;

use Generator;
use Mage;
use Mage_Catalog_Model_Product_Option;
use Mage_Catalog_Model_Product_Option_Type_Text as Subject;
use PHPUnit\Framework\TestCase;

class TextTest extends TestCase
{
public Subject $subject;

public function setUp(): void
{
Mage::app();
$this->subject = Mage::getModel('catalog/product_option_type_text');
}

/**
* @group Mage_Catalog
* @group Mage_Catalog_Model
* @group runInSeparateProcess
* @runInSeparateProcess
*/
public function testValidateUserValue(): void
{
$this->subject->setOption(new Mage_Catalog_Model_Product_Option());
$this->assertInstanceOf(Subject::class, $this->subject->validateUserValue([]));
}


/**
* @dataProvider providePrepareForCart
* @group Mage_Catalog
* @group Mage_Catalog_Model
*/
public function testPrepareForCart($expectedResult, bool $setIsValid = true, $setUserValue = null): void
{
$this->subject->setIsValid($setIsValid)->setUserValue($setUserValue);
$this->assertSame($expectedResult, $this->subject->prepareForCart());
}

public function providePrepareForCart(): Generator
{
yield 'valid' => [
'test',
true,
'test',
];
yield 'invalid' => [
null,
];
}

/**
* @covers Mage_Catalog_Model_Product_Option_Type_Text::getFormattedOptionValue()
* @group Mage_Catalog
* @group Mage_Catalog_Model
*/
public function testGetDefaultAttributeSetId(): void
{
$this->assertIsString($this->subject->getFormattedOptionValue(''));
}
}

0 comments on commit 11db607

Please sign in to comment.