|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Catalog\Model\Product\Option\Type; |
| 8 | + |
| 9 | +use Magento\Catalog\Model\Product\Option; |
| 10 | + |
| 11 | +/** |
| 12 | + * Test for customizable product option with "Text" type |
| 13 | + */ |
| 14 | +class TextTest extends \PHPUnit\Framework\TestCase |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @var Text |
| 18 | + */ |
| 19 | + protected $model; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var \Magento\Framework\ObjectManagerInterface |
| 23 | + */ |
| 24 | + private $objectManager; |
| 25 | + |
| 26 | + /** |
| 27 | + * {@inheritDoc} |
| 28 | + */ |
| 29 | + protected function setUp() |
| 30 | + { |
| 31 | + $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); |
| 32 | + $this->model = $this->objectManager->create( |
| 33 | + Text::class |
| 34 | + ); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Check if newline symbols are normalized in option value |
| 39 | + * |
| 40 | + * @dataProvider optionValueDataProvider |
| 41 | + * @param array $productOptionData |
| 42 | + * @param string $optionValue |
| 43 | + * @param string $expectedOptionValue |
| 44 | + */ |
| 45 | + public function testNormalizeNewlineSymbols( |
| 46 | + array $productOptionData, |
| 47 | + string $optionValue, |
| 48 | + string $expectedOptionValue |
| 49 | + ) { |
| 50 | + $productOption = $this->objectManager->create( |
| 51 | + Option::class, |
| 52 | + ['data' => $productOptionData] |
| 53 | + ); |
| 54 | + |
| 55 | + $this->model->setOption($productOption); |
| 56 | + $this->model->setUserValue($optionValue); |
| 57 | + $this->model->validateUserValue([]); |
| 58 | + |
| 59 | + $this->assertSame($expectedOptionValue, $this->model->getUserValue()); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Data provider for testNormalizeNewlineSymbols |
| 64 | + * |
| 65 | + * @return array |
| 66 | + */ |
| 67 | + public function optionValueDataProvider() |
| 68 | + { |
| 69 | + return [ |
| 70 | + [ |
| 71 | + // $productOptionData |
| 72 | + ['id' => 11, 'type' => 'area'], |
| 73 | + // $optionValue |
| 74 | + 'string string', |
| 75 | + // $expectedOptionValue |
| 76 | + 'string string' |
| 77 | + ], |
| 78 | + [ |
| 79 | + // $productOptionData |
| 80 | + ['id' => 11, 'type' => 'area'], |
| 81 | + // $optionValue |
| 82 | + "string \r\n string", |
| 83 | + // $expectedOptionValue |
| 84 | + "string \n string" |
| 85 | + ], |
| 86 | + [ |
| 87 | + // $productOptionData |
| 88 | + ['id' => 11, 'type' => 'area'], |
| 89 | + // $optionValue |
| 90 | + "string \n\r string", |
| 91 | + // $expectedOptionValue |
| 92 | + "string \n string" |
| 93 | + ], |
| 94 | + [ |
| 95 | + // $productOptionData |
| 96 | + ['id' => 11, 'type' => 'area'], |
| 97 | + // $optionValue |
| 98 | + "string \r string", |
| 99 | + // $expectedOptionValue |
| 100 | + "string \n string" |
| 101 | + ] |
| 102 | + ]; |
| 103 | + } |
| 104 | +} |
0 commit comments