Skip to content

Commit 13c83d9

Browse files
author
Igor Melnikov
committed
Merge branches 'MAGETWO-60020-config-translation' and 'MAGETWO-60270-static-test' into sprint6-pr
3 parents 13db0b1 + 9cc3204 + 43426e1 commit 13c83d9

File tree

17 files changed

+921
-142
lines changed

17 files changed

+921
-142
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Text.php

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
* Copyright © 2016 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
namespace Magento\Backend\Block\Widget\Grid\Column\Renderer;
7+
8+
use Magento\Framework\DataObject;
69

710
/**
811
* Backend grid item renderer
9-
*
10-
* @author Magento Core Team <core@magentocommerce.com>
1112
*/
12-
namespace Magento\Backend\Block\Widget\Grid\Column\Renderer;
13-
1413
class Text extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
1514
{
1615
/**
@@ -21,30 +20,53 @@ class Text extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRe
2120
protected $_variablePattern = '/\\$([a-z0-9_]+)/i';
2221

2322
/**
24-
* Renders grid column
23+
* Get value for the cel
2524
*
26-
* @param \Magento\Framework\DataObject $row
27-
* @return mixed
25+
* @param DataObject $row
26+
* @return string
2827
*/
29-
public function _getValue(\Magento\Framework\DataObject $row)
28+
public function _getValue(DataObject $row)
3029
{
31-
$format = $this->getColumn()->getFormat() ? $this->getColumn()->getFormat() : null;
32-
$defaultValue = $this->getColumn()->getDefault();
33-
if ($format === null) {
34-
// If no format and it column not filtered specified return data as is.
35-
$data = parent::_getValue($row);
36-
$string = $data === null ? $defaultValue : $data;
37-
return $this->escapeHtml($string);
38-
} elseif (preg_match_all($this->_variablePattern, $format, $matches)) {
39-
// Parsing of format string
40-
$formattedString = $format;
41-
foreach ($matches[0] as $matchIndex => $match) {
42-
$value = $row->getData($matches[1][$matchIndex]);
43-
$formattedString = str_replace($match, $value, $formattedString);
30+
if (null === $this->getColumn()->getFormat()) {
31+
return $this->getSimpleValue($row);
32+
}
33+
return $this->getFormattedValue($row);
34+
}
35+
36+
/**
37+
* Get simple value
38+
*
39+
* @param DataObject $row
40+
* @return string
41+
*/
42+
private function getSimpleValue(DataObject $row)
43+
{
44+
$data = parent::_getValue($row);
45+
$value = null === $data ? $this->getColumn()->getDefault() : $data;
46+
if (true === $this->getColumn()->getTranslate()) {
47+
$value = __($value);
48+
}
49+
return $this->escapeHtml($value);
50+
}
51+
52+
/**
53+
* Replace placeholders in the string with values
54+
*
55+
* @param DataObject $row
56+
* @return string
57+
*/
58+
private function getFormattedValue(DataObject $row)
59+
{
60+
$value = $this->getColumn()->getFormat() ?: null;
61+
if (true === $this->getColumn()->getTranslate()) {
62+
$value = __($value);
63+
}
64+
if (preg_match_all($this->_variablePattern, $value, $matches)) {
65+
foreach ($matches[0] as $index => $match) {
66+
$replacement = $row->getData($matches[1][$index]);
67+
$value = str_replace($match, $replacement, $value);
4468
}
45-
return $formattedString;
46-
} else {
47-
return $this->escapeHtml($format);
4869
}
70+
return $this->escapeHtml($value);
4971
}
5072
}

app/code/Magento/Backend/view/adminhtml/layout/adminhtml_cache_block.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<argument name="width" xsi:type="string">180</argument>
4949
<argument name="align" xsi:type="string">left</argument>
5050
<argument name="sortable" xsi:type="string">0</argument>
51+
<argument name="translate" xsi:type="boolean">true</argument>
5152
</arguments>
5253
</block>
5354
<block class="Magento\Backend\Block\Widget\Grid\Column" as="description">
@@ -57,6 +58,7 @@
5758
<argument name="type" xsi:type="string">text</argument>
5859
<argument name="align" xsi:type="string">left</argument>
5960
<argument name="sortable" xsi:type="string">0</argument>
61+
<argument name="translate" xsi:type="boolean">true</argument>
6062
</arguments>
6163
</block>
6264
<block class="Magento\Backend\Block\Widget\Grid\Column" as="tags">

app/code/Magento/Indexer/view/adminhtml/layout/indexer_indexer_list_grid.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<argument name="index" xsi:type="string">title</argument>
4747
<argument name="sortable" xsi:type="string">0</argument>
4848
<argument name="column_css_class" xsi:type="string">indexer-title</argument>
49+
<argument name="translate" xsi:type="boolean">true</argument>
4950
</arguments>
5051
</block>
5152
<block class="Magento\Backend\Block\Widget\Grid\Column" as="indexer_description">
@@ -54,6 +55,7 @@
5455
<argument name="index" xsi:type="string">description</argument>
5556
<argument name="sortable" xsi:type="string">0</argument>
5657
<argument name="column_css_class" xsi:type="string">indexer-description</argument>
58+
<argument name="translate" xsi:type="boolean">true</argument>
5759
</arguments>
5860
</block>
5961
<block class="Magento\Backend\Block\Widget\Grid\Column" as="indexer_mode">
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Block\Widget\Grid\Column\Renderer;
7+
8+
use Magento\TestFramework\Helper\Bootstrap;
9+
use Magento\TestFramework\ObjectManager;
10+
use Magento\Backend\Block\Widget\Grid\Column;
11+
use Magento\Framework\DataObject;
12+
use Magento\Framework\Phrase;
13+
use Magento\Framework\Phrase\RendererInterface;
14+
15+
class TextTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var ObjectManager
19+
*/
20+
private $objectManager;
21+
22+
/**
23+
* @var RendererInterface
24+
*/
25+
private $origRenderer;
26+
27+
protected function setUp()
28+
{
29+
$this->objectManager = Bootstrap::getObjectManager();
30+
$this->origRenderer = Phrase::getRenderer();
31+
/** @var RendererInterface|PHPUnit_Framework_MockObject_MockObject $rendererMock */
32+
$rendererMock = $this->getMock(RendererInterface::class);
33+
$rendererMock->expects($this->any())
34+
->method('render')
35+
->willReturnCallback(
36+
function ($input) {
37+
return end($input) . ' translated';
38+
}
39+
);
40+
Phrase::setRenderer($rendererMock);
41+
}
42+
43+
protected function tearDown()
44+
{
45+
Phrase::setRenderer($this->origRenderer);
46+
}
47+
48+
/**
49+
* @param array $columnData
50+
* @param array $rowData
51+
* @param string $expected
52+
* @dataProvider renderDataProvider
53+
*/
54+
public function testRender($columnData, $rowData, $expected)
55+
{
56+
/** @var Text $renderer */
57+
$renderer = $this->objectManager->create(Text::class);
58+
/** @var Column $column */
59+
$column = $this->objectManager->create(
60+
Column::class,
61+
[
62+
'data' => $columnData
63+
]
64+
);
65+
/** @var DataObject $row */
66+
$row = $this->objectManager->create(
67+
DataObject::class,
68+
[
69+
'data' => $rowData
70+
]
71+
);
72+
$this->assertEquals(
73+
$expected,
74+
$renderer->setColumn($column)->render($row)
75+
);
76+
}
77+
78+
/**
79+
* @return array
80+
*/
81+
public function renderDataProvider()
82+
{
83+
return [
84+
[
85+
[
86+
'index' => 'title',
87+
'translate' => true
88+
],
89+
[
90+
'title' => 'String'
91+
],
92+
'String translated'
93+
],
94+
[
95+
[
96+
'index' => 'title'
97+
],
98+
[
99+
'title' => 'Doesn\'t need to be translated'
100+
],
101+
'Doesn&#039;t need to be translated'
102+
],
103+
[
104+
[
105+
'format' => '#$subscriber_id $customer_name ($subscriber_email)'
106+
],
107+
[
108+
'subscriber_id' => '10',
109+
'customer_name' => 'John Doe',
110+
'subscriber_email' => 'john@doe.com'
111+
],
112+
'#10 John Doe (john@doe.com)'
113+
],
114+
[
115+
[
116+
'format' => '$customer_name, email: $subscriber_email',
117+
'translate' => true
118+
],
119+
[
120+
'customer_name' => 'John Doe',
121+
'subscriber_email' => 'john@doe.com'
122+
],
123+
'John Doe, email: john@doe.com translated'
124+
],
125+
[
126+
[
127+
'format' => 'String',
128+
'translate' => true
129+
],
130+
[],
131+
'String translated'
132+
],
133+
[
134+
[
135+
'format' => 'Doesn\'t need to be translated'
136+
],
137+
[],
138+
'Doesn&#039;t need to be translated'
139+
]
140+
];
141+
}
142+
}

dev/tests/static/framework/Magento/TestFramework/Utility/ChangedFiles.php

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* Copyright © 2016 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
namespace Magento\TestFramework\Utility;
87

98
use Magento\Framework\App\Utility\Files;
9+
use Magento\TestFramework\Utility\File\RegexIteratorFactory;
1010

1111
/**
1212
* A helper to gather various changed files
@@ -23,7 +23,7 @@ class ChangedFiles
2323
*/
2424
public static function getPhpFiles($changedFilesList)
2525
{
26-
$fileHelper = \Magento\Framework\App\Utility\Files::init();
26+
$fileUtilities = new File(Files::init(), new RegexIteratorFactory());
2727
if (isset($_ENV['INCREMENTAL_BUILD'])) {
2828
$phpFiles = [];
2929
foreach (glob($changedFilesList) as $listFile) {
@@ -36,27 +36,11 @@ function (&$file) {
3636
}
3737
);
3838
if (!empty($phpFiles)) {
39-
$phpFiles = \Magento\Framework\App\Utility\Files::composeDataSets($phpFiles);
40-
$phpFiles = array_intersect_key($phpFiles, $fileHelper->getPhpFiles(
41-
Files::INCLUDE_APP_CODE
42-
| Files::INCLUDE_PUB_CODE
43-
| Files::INCLUDE_LIBS
44-
| Files::INCLUDE_TEMPLATES
45-
| Files::INCLUDE_TESTS
46-
| Files::AS_DATA_SET
47-
| Files::INCLUDE_NON_CLASSES
48-
));
39+
$phpFiles = Files::composeDataSets($phpFiles);
40+
$phpFiles = array_intersect_key($phpFiles, $fileUtilities->getPhpFiles());
4941
}
5042
} else {
51-
$phpFiles = $fileHelper->getPhpFiles(
52-
Files::INCLUDE_APP_CODE
53-
| Files::INCLUDE_PUB_CODE
54-
| Files::INCLUDE_LIBS
55-
| Files::INCLUDE_TEMPLATES
56-
| Files::INCLUDE_TESTS
57-
| Files::AS_DATA_SET
58-
| Files::INCLUDE_NON_CLASSES
59-
);
43+
$phpFiles = $fileUtilities->getPhpFiles();
6044
}
6145

6246
return $phpFiles;

0 commit comments

Comments
 (0)