Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(''));
}
}