Skip to content

Commit 11db607

Browse files
kiatngsreichel
andauthored
Fixed null deprecation in Mage_Catalog_Model_Product_Option_Type_Text::validateUserValue() (OpenMage#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]>
1 parent 8033a6e commit 11db607

File tree

2 files changed

+87
-1
lines changed
  • app/code/core/Mage/Catalog/Model/Product/Option/Type
  • tests/unit/Mage/Catalog/Model/Product/Option/Type

2 files changed

+87
-1
lines changed

app/code/core/Mage/Catalog/Model/Product/Option/Type/Text.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@
2121
*/
2222
class Mage_Catalog_Model_Product_Option_Type_Text extends Mage_Catalog_Model_Product_Option_Type_Default
2323
{
24+
public function getUserValue(): string
25+
{
26+
return (string) $this->getDataByKey('user_value');
27+
}
28+
2429
/**
2530
* Validate user input for option
2631
*
2732
* @throws Mage_Core_Exception
2833
* @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
29-
* @return Mage_Catalog_Model_Product_Option_Type_Default
34+
* @return $this
3035
*/
3136
public function validateUserValue($values)
3237
{
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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\Catalog\Model\Product\Option\Type;
19+
20+
use Generator;
21+
use Mage;
22+
use Mage_Catalog_Model_Product_Option;
23+
use Mage_Catalog_Model_Product_Option_Type_Text as Subject;
24+
use PHPUnit\Framework\TestCase;
25+
26+
class TextTest extends TestCase
27+
{
28+
public Subject $subject;
29+
30+
public function setUp(): void
31+
{
32+
Mage::app();
33+
$this->subject = Mage::getModel('catalog/product_option_type_text');
34+
}
35+
36+
/**
37+
* @group Mage_Catalog
38+
* @group Mage_Catalog_Model
39+
* @group runInSeparateProcess
40+
* @runInSeparateProcess
41+
*/
42+
public function testValidateUserValue(): void
43+
{
44+
$this->subject->setOption(new Mage_Catalog_Model_Product_Option());
45+
$this->assertInstanceOf(Subject::class, $this->subject->validateUserValue([]));
46+
}
47+
48+
49+
/**
50+
* @dataProvider providePrepareForCart
51+
* @group Mage_Catalog
52+
* @group Mage_Catalog_Model
53+
*/
54+
public function testPrepareForCart($expectedResult, bool $setIsValid = true, $setUserValue = null): void
55+
{
56+
$this->subject->setIsValid($setIsValid)->setUserValue($setUserValue);
57+
$this->assertSame($expectedResult, $this->subject->prepareForCart());
58+
}
59+
60+
public function providePrepareForCart(): Generator
61+
{
62+
yield 'valid' => [
63+
'test',
64+
true,
65+
'test',
66+
];
67+
yield 'invalid' => [
68+
null,
69+
];
70+
}
71+
72+
/**
73+
* @covers Mage_Catalog_Model_Product_Option_Type_Text::getFormattedOptionValue()
74+
* @group Mage_Catalog
75+
* @group Mage_Catalog_Model
76+
*/
77+
public function testGetDefaultAttributeSetId(): void
78+
{
79+
$this->assertIsString($this->subject->getFormattedOptionValue(''));
80+
}
81+
}

0 commit comments

Comments
 (0)