From 11db60758fa964faeabcf02ad722806922a2af8d Mon Sep 17 00:00:00 2001 From: Ng Kiat Siong Date: Sat, 23 Nov 2024 06:14:06 +0800 Subject: [PATCH] Fixed null deprecation in `Mage_Catalog_Model_Product_Option_Type_Text::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 --- .../Model/Product/Option/Type/Text.php | 7 +- .../Model/Product/Option/Type/TextTest.php | 81 +++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 tests/unit/Mage/Catalog/Model/Product/Option/Type/TextTest.php diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Text.php b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Text.php index 442d112c0fa..42e3ca64fa7 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Text.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Text.php @@ -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) { diff --git a/tests/unit/Mage/Catalog/Model/Product/Option/Type/TextTest.php b/tests/unit/Mage/Catalog/Model/Product/Option/Type/TextTest.php new file mode 100644 index 00000000000..313cf47fafe --- /dev/null +++ b/tests/unit/Mage/Catalog/Model/Product/Option/Type/TextTest.php @@ -0,0 +1,81 @@ +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('')); + } +}