|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Elasticsearch\Test\Unit\SearchAdapter\Query\ValueTransformer; |
| 9 | + |
| 10 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; |
| 11 | +use Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\TextTransformer; |
| 12 | +use PHPUnit\Framework\TestCase; |
| 13 | + |
| 14 | +/** |
| 15 | + * Test value transformer |
| 16 | + */ |
| 17 | +class TextTransformerTest extends TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @var TextTransformer |
| 21 | + */ |
| 22 | + protected $model; |
| 23 | + |
| 24 | + /** |
| 25 | + * Setup method |
| 26 | + * @return void |
| 27 | + */ |
| 28 | + public function setUp(): void |
| 29 | + { |
| 30 | + $objectManagerHelper = new ObjectManagerHelper($this); |
| 31 | + $this->model = $objectManagerHelper->getObject( |
| 32 | + TextTransformer::class, |
| 33 | + [ |
| 34 | + '$preprocessors' => [], |
| 35 | + ] |
| 36 | + ); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Test transform value |
| 41 | + * |
| 42 | + * @param string $value |
| 43 | + * @param string $expected |
| 44 | + * @return void |
| 45 | + * @dataProvider valuesDataProvider |
| 46 | + */ |
| 47 | + public function testTransform(string $value, string $expected): void |
| 48 | + { |
| 49 | + $result = $this->model->transform($value); |
| 50 | + $this->assertEquals($expected, $result); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Values data provider |
| 55 | + * |
| 56 | + * @return array |
| 57 | + */ |
| 58 | + public function valuesDataProvider(): array |
| 59 | + { |
| 60 | + return [ |
| 61 | + ['Laptop^camera{microphone}', 'Laptop\^camera\{microphone\}'], |
| 62 | + ['Birthday 25-Pack w/ Greatest of All Time Cupcake', 'Birthday 25\-Pack w\/ Greatest of All Time Cupcake'], |
| 63 | + ['Retro vinyl record ~d123 *star', 'Retro vinyl record \~d123 \*star'], |
| 64 | + ]; |
| 65 | + } |
| 66 | +} |
0 commit comments