Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TranslitTest.php
Go to the documentation of this file.
1 <?php
7 
8 class TranslitTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $model;
14 
15  protected function setUp()
16  {
17  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
18  $this->model = $objectManager->getObject(\Magento\Framework\Filter\Translit::class);
19  }
20 
28  public function testFilter($testString, $result, $resultIconv, $isIconv)
29  {
30  if ($isIconv) {
31  $this->assertEquals($resultIconv, $this->model->filter($testString));
32  } else {
33  $this->assertEquals($result, $this->model->filter($testString));
34  }
35  }
36 
40  public function filterDataProvider()
41  {
42  $isIconv = '"libiconv"' == ICONV_IMPL;
43  return [
44  ['test', 'test', 'test', $isIconv],
45  ['привет мир', 'privet mir', 'privet mir', $isIconv],
46  [
47  'Weiß, Goldmann, Göbel, Weiss, Göthe, Goethe und Götz',
48  'Weiss, Goldmann, Gobel, Weiss, Gothe, Goethe und Gotz',
49  'Weiss, Goldmann, Gobel, Weiss, Gothe, Goethe und Gotz',
50  $isIconv
51  ],
52  [
53  '❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ☎ ❄ ♫ ✂ ▷ ✇ ♎ ⇧ ☮',
54  '❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ☎ ❄ ♫ ✂ ▷ ✇ ♎ ⇧ ☮',
55  ' EUR -> ',
56  $isIconv
57  ],
58  ['™', 'tm', 'tm', $isIconv]
59  ];
60  }
61 
62  public function testFilterConfigured()
63  {
64  $config = $this->getMockBuilder(
65  \Magento\Framework\App\Config\ScopeConfigInterface::class
66  )->disableOriginalConstructor()->setMethods(
67  ['getValue', 'setValue', 'isSetFlag']
68  )->getMock();
69 
70  $config->expects(
71  $this->once()
72  )->method(
73  'getValue'
74  )->with(
75  'url/convert',
76  'default'
77  )->will(
78  $this->returnValue(['char8482' => ['from' => '™', 'to' => 'TM']])
79  );
80 
81  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
82  $this->model = $objectManager->getObject(\Magento\Framework\Filter\Translit::class, ['config' => $config]);
83 
84  $this->assertEquals('TM', $this->model->filter('™'));
85  }
86 }
$objectManager
Definition: bootstrap.php:17
$config
Definition: fraud_order.php:17
testFilter($testString, $result, $resultIconv, $isIconv)