|
| 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 | +use Magento\Framework\ObjectManagerInterface; |
| 11 | +use Magento\TestFramework\Helper\Bootstrap; |
| 12 | +use PHPUnit\Framework\TestCase; |
| 13 | + |
| 14 | +/** |
| 15 | + * Test for customizable product option with "Text" type |
| 16 | + */ |
| 17 | +class TextTest extends TestCase |
| 18 | +{ |
| 19 | + const STUB_OPTION_DATA = ['id' => 11, 'type' => 'area']; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var Text |
| 23 | + */ |
| 24 | + protected $optionText; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var ObjectManagerInterface |
| 28 | + */ |
| 29 | + private $objectManager; |
| 30 | + |
| 31 | + /** |
| 32 | + * {@inheritDoc} |
| 33 | + */ |
| 34 | + protected function setUp() |
| 35 | + { |
| 36 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 37 | + $this->optionText = $this->objectManager->create(Text::class); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Check if newline symbols are normalized in option value |
| 42 | + * |
| 43 | + * @dataProvider optionValueDataProvider |
| 44 | + * @param array $productOptionData |
| 45 | + * @param string $optionValue |
| 46 | + * @param string $expectedOptionValue |
| 47 | + */ |
| 48 | + public function testNormalizeNewlineSymbols( |
| 49 | + array $productOptionData, |
| 50 | + string $optionValue, |
| 51 | + string $expectedOptionValue |
| 52 | + ) { |
| 53 | + $productOption = $this->objectManager->create( |
| 54 | + Option::class, |
| 55 | + ['data' => $productOptionData] |
| 56 | + ); |
| 57 | + |
| 58 | + $this->optionText->setOption($productOption); |
| 59 | + $this->optionText->setUserValue($optionValue); |
| 60 | + $this->optionText->validateUserValue([]); |
| 61 | + |
| 62 | + $this->assertSame($expectedOptionValue, $this->optionText->getUserValue()); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Data provider for testNormalizeNewlineSymbols |
| 67 | + * |
| 68 | + * @return array |
| 69 | + */ |
| 70 | + public function optionValueDataProvider() |
| 71 | + { |
| 72 | + return [ |
| 73 | + [self::STUB_OPTION_DATA, 'string string', 'string string'], |
| 74 | + [self::STUB_OPTION_DATA, "string \r\n string", "string \n string"], |
| 75 | + [self::STUB_OPTION_DATA, "string \n\r string", "string \n string"], |
| 76 | + [self::STUB_OPTION_DATA, "string \r string", "string \n string"] |
| 77 | + ]; |
| 78 | + } |
| 79 | +} |
0 commit comments