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('')); + } +}