-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[issue-25974] Fix for "Amount of characters on a 'Area' Customizable …
…Option counted differently on backend/frontend"
- Loading branch information
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/TextTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Model\Product\Option\Type; | ||
|
||
use Magento\Catalog\Model\Product\Option; | ||
|
||
/** | ||
* Test for customizable product option with "Text" type | ||
*/ | ||
class TextTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var Text | ||
*/ | ||
protected $model; | ||
|
||
/** | ||
* @var \Magento\Framework\ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); | ||
$this->model = $this->objectManager->create( | ||
Text::class | ||
); | ||
} | ||
|
||
/** | ||
* Check if newline symbols are normalized in option value | ||
* | ||
* @dataProvider optionValueDataProvider | ||
* @param array $productOptionData | ||
* @param string $optionValue | ||
* @param string $expectedOptionValue | ||
*/ | ||
public function testNormalizeNewlineSymbols( | ||
array $productOptionData, | ||
string $optionValue, | ||
string $expectedOptionValue | ||
) { | ||
$productOption = $this->objectManager->create( | ||
Option::class, | ||
['data' => $productOptionData] | ||
); | ||
|
||
$this->model->setOption($productOption); | ||
$this->model->setUserValue($optionValue); | ||
$this->model->validateUserValue([]); | ||
|
||
$this->assertSame($expectedOptionValue, $this->model->getUserValue()); | ||
} | ||
|
||
/** | ||
* Data provider for testNormalizeNewlineSymbols | ||
* | ||
* @return array | ||
*/ | ||
public function optionValueDataProvider() | ||
{ | ||
return [ | ||
[ | ||
// $productOptionData | ||
['id' => 11, 'type' => 'area'], | ||
// $optionValue | ||
'string string', | ||
// $expectedOptionValue | ||
'string string' | ||
], | ||
[ | ||
// $productOptionData | ||
['id' => 11, 'type' => 'area'], | ||
// $optionValue | ||
"string \r\n string", | ||
// $expectedOptionValue | ||
"string \n string" | ||
], | ||
[ | ||
// $productOptionData | ||
['id' => 11, 'type' => 'area'], | ||
// $optionValue | ||
"string \n\r string", | ||
// $expectedOptionValue | ||
"string \n string" | ||
], | ||
[ | ||
// $productOptionData | ||
['id' => 11, 'type' => 'area'], | ||
// $optionValue | ||
"string \r string", | ||
// $expectedOptionValue | ||
"string \n string" | ||
] | ||
]; | ||
} | ||
} |
Shouldn't this method be placed inside of \Magento\Framework\Stdlib\StringUtils ? I'm sure this isn't the only place this method will come in handy..