Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TranslatorTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class TranslatorTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $_object;
16 
20  protected $_helperMock;
21 
25  protected $_xmlDocument;
26 
27  protected function setUp()
28  {
29  $string = <<<XML
30 <?xml version='1.0'?>
31 <layout>
32  <arguments>
33  <node_self_translated translate="true">test</node_self_translated>
34  <node_no_self_translated>test</node_no_self_translated>
35  </arguments>
36  <arguments_parent translate="node node_other">
37  <node>test</node>
38  <node_other> test </node_other>
39  <node_no_translated>no translated</node_no_translated>
40  </arguments_parent>
41  <action_one method="someMethod" />
42  <action_two method="someMethod" translate='one two' />
43  <action_three method="someMethod" translate='one two.value' />
44  <action_four method="someMethod" translate='one two' />
45 </layout>
46 XML;
47 
48  $this->_xmlDocument = simplexml_load_string($string, \Magento\Framework\Simplexml\Element::class);
49 
50  $this->_object = new \Magento\Framework\View\Model\Layout\Translator();
51  }
52 
57  {
58  $args = ['one' => 'test'];
59 
60  $this->_object->translateActionParameters($this->_xmlDocument->action_one, $args);
61  $this->assertEquals('test', $args['one']);
62  }
63 
68  {
69  $args = ['one' => 'test', 'two' => 'test', 'three' => 'test'];
70  $expected = ['one' => new Phrase('test'), 'two' => new Phrase('test'), 'three' => 'test'];
71 
72  $this->_object->translateActionParameters($this->_xmlDocument->action_two, $args);
73  $this->assertEquals($expected, $args);
74  }
75 
80  {
81  $args = ['one' => ['some', 'data'], 'two' => ['value' => 'test'], 'three' => 'test'];
82  $expected = ['one' => ['some', 'data'], 'two' => ['value' => new Phrase('test')], 'three' => 'test'];
83 
84  $this->_object->translateActionParameters($this->_xmlDocument->action_three, $args);
85  $this->assertEquals($expected, $args);
86  }
87 
92  {
93  $args = ['two' => 'test', 'three' => 'test'];
94  $expected = ['two' => new Phrase('test'), 'three' => new Phrase('test')];
95 
96  $this->_object->translateActionParameters($this->_xmlDocument->action_four, $args);
97  $this->assertEquals($expected, $args);
98  }
99 
104  {
105  $actual = $this->_object->translateArgument($this->_xmlDocument->arguments->node_self_translated);
106  $this->assertEquals(new Phrase('test'), $actual);
107  }
108 
113  {
114  $actual = $this->_object->translateArgument($this->_xmlDocument->arguments->node_no_self_translated);
115  $this->assertEquals('test', $actual);
116  }
117 
122  {
123  $actual = $this->_object->translateArgument($this->_xmlDocument->arguments_parent->node);
124  $this->assertEquals(new Phrase('test'), $actual);
125  }
126 
131  {
132  $actual = $this->_object->translateArgument($this->_xmlDocument->arguments_parent->node_other);
133  $this->assertEquals(new Phrase('test'), $actual);
134  }
135 
140  {
141  $actual = $this->_object->translateArgument($this->_xmlDocument->arguments_parent->node_no_translated);
142  $this->assertEquals('no translated', $actual);
143  }
144 }
jquery extjs ext tree mage adminhtml mage translate
Definition: tree.phtml:41