Skip to content

Commit

Permalink
Adjusted code after MR
Browse files Browse the repository at this point in the history
  • Loading branch information
Leone committed Dec 16, 2019
1 parent 284e3ed commit 2ae6838
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 45 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/Model/Product/Option/Type/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public function getFormattedOptionValue($value)
* @param string $value
* @return string
*/
private function normalizeNewLineSymbols($value)
private function normalizeNewLineSymbols(string $value)
{
return str_replace(["\r\n", "\n\r", "\r"], ["\n", "\n", "\n"], $value);
return str_replace(["\r\n", "\n\r", "\r"], "\n", $value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@
namespace Magento\Catalog\Model\Product\Option\Type;

use Magento\Catalog\Model\Product\Option;
use Magento\Tests\NamingConvention\true\mixed;
use PHPUnit\Framework\TestCase;
use Magento\Framework\ObjectManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;

/**
* Test for customizable product option with "Text" type
*/
class TextTest extends \PHPUnit\Framework\TestCase
class TextTest extends TestCase
{
const STUB_OPTION_DATA = ['id' => 11, 'type' => 'area'];

/**
* @var Text
*/
protected $model;
protected $optionText;

/**
* @var \Magento\Framework\ObjectManagerInterface
* @var ObjectManagerInterface
*/
private $objectManager;

Expand All @@ -28,10 +34,8 @@ class TextTest extends \PHPUnit\Framework\TestCase
*/
protected function setUp()
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->model = $this->objectManager->create(
Text::class
);
$this->objectManager = Bootstrap::getObjectManager();
$this->optionText = $this->objectManager->create(Text::class);
}

/**
Expand All @@ -52,11 +56,11 @@ public function testNormalizeNewlineSymbols(
['data' => $productOptionData]
);

$this->model->setOption($productOption);
$this->model->setUserValue($optionValue);
$this->model->validateUserValue([]);
$this->optionText->setOption($productOption);
$this->optionText->setUserValue($optionValue);
$this->optionText->validateUserValue([]);

$this->assertSame($expectedOptionValue, $this->model->getUserValue());
$this->assertSame($expectedOptionValue, $this->optionText->getUserValue());
}

/**
Expand All @@ -67,38 +71,10 @@ public function testNormalizeNewlineSymbols(
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"
]
[self::STUB_OPTION_DATA, 'string string', 'string string'],
[self::STUB_OPTION_DATA, "string \r\n string", "string \n string"],
[self::STUB_OPTION_DATA, "string \n\r string", "string \n string"],
[self::STUB_OPTION_DATA, "string \r string", "string \n string"]
];
}
}

0 comments on commit 2ae6838

Please sign in to comment.