Skip to content

Commit 33da0ca

Browse files
author
Dale Sikkema
committed
Merge branch 'MAGETWO-43435-phrase-concatenation' into MAGETWO-44154-cg-race-condition
2 parents c75c203 + d32d965 commit 33da0ca

File tree

8 files changed

+151
-11
lines changed

8 files changed

+151
-11
lines changed

dev/tests/integration/testsuite/Magento/Setup/Console/Command/I18nCollectPhrasesCommandTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,19 @@ public function testExecuteConsoleOutput()
4646

4747
public function testExecuteCsvOutput()
4848
{
49-
$outputPath = BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/output/output.csv';
49+
$outputPath = BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/output/phrases.csv';
5050
$this->tester->execute(
5151
[
52-
'directory' => BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/',
52+
'directory' => BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/phrases/',
5353
'--output' => $outputPath,
5454
]
5555
);
5656

5757
$handle = fopen($outputPath, 'r');
5858
$output = fread($handle, filesize($outputPath));
59-
$expected = '"Hello world","Hello world"' . PHP_EOL . '"Foo bar","Foo bar"' . PHP_EOL;
59+
$expected = file_get_contents(
60+
BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv'
61+
);
6062
$this->assertEquals($expected, $output);
6163
unlink($outputPath);
6264
}

dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/Magento/TestModule/Phrases.php

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"simple text","simple text"
2+
"simple text with 1 string literal placeholder %1","simple text with 1 string literal placeholder %1"
3+
"simple text with 1 variable placeholder %1","simple text with 1 variable placeholder %1"
4+
"simple text with multiple placeholders %1 %2","simple text with multiple placeholders %1 %2"
5+
"first part second part","first part second part"
6+
"first part second part third part","first part second part third part"
7+
"first part second part with one string literal placeholder %1","first part second part with one string literal placeholder %1"
8+
"first part of concat second part with one variable placeholder %1","first part of concat second part with one variable placeholder %1"
9+
"first part of concat second part with two placeholders %1, %2","first part of concat second part with two placeholders %1, %2"
10+
"first part of concat second part third part with one placeholder %1","first part of concat second part third part with one placeholder %1"
11+
"first part of concat second part third part with two placeholders %1, %2","first part of concat second part third part with two placeholders %1, %2"
12+
"string with escaped 'single quotes'","string with escaped 'single quotes'"
13+
"string with placeholder in escaped single quotes '%1'","string with placeholder in escaped single quotes '%1'"
14+
"string with ""double quotes""","string with ""double quotes"""
15+
"string with placeholder in double quotes ""%1""","string with placeholder in double quotes ""%1"""
16+
"string with 'single quotes'","string with 'single quotes'"
17+
"string with placeholder in single quotes '%1'","string with placeholder in single quotes '%1'"
18+
"string with escaped ""double quotes""","string with escaped ""double quotes"""
19+
"string with placeholder in escaped double quotes ""%1""","string with placeholder in escaped double quotes ""%1"""
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/***
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
// @codingStandardsIgnoreFile
8+
9+
use Magento\Framework\Phrase;
10+
11+
/**
12+
* @SuppressWarnings(PHPMD)
13+
*/
14+
class TestPhrases
15+
{
16+
public function awesomeFunction()
17+
{
18+
$str1 = 'str1';
19+
$str2 = 'str2';
20+
21+
// Simple
22+
$simpleCases = [
23+
new Phrase('simple text'),
24+
new Phrase('simple text with 1 string literal placeholder %1', 'arg'),
25+
new Phrase('simple text with 1 variable placeholder %1', $str1),
26+
new Phrase('simple text with multiple placeholders %1 %2', $str1, $str2),
27+
];
28+
29+
// Phrase objects
30+
$phraseObjects = [
31+
// Single concatenation
32+
new Phrase('first part' . ' second part'),
33+
new Phrase('first part' . ' second part' . ' third part'),
34+
35+
// Multiple concatenation
36+
new Phrase('first part' . ' second part with one string literal placeholder %1', 'arg'),
37+
new Phrase('first part of concat' . ' second part with one variable placeholder %1', $str1),
38+
new Phrase('first part of concat' . ' second part with two placeholders %1, %2', $str1, $str2),
39+
new Phrase('first part of concat' . ' second part' . ' third part with one placeholder %1', 'arg'),
40+
new Phrase('first part of concat' . ' second part' . ' third part with two placeholders %1, %2', $str1, $str2),
41+
42+
// Escaped quotes
43+
new Phrase('string with escaped \'single quotes\''),
44+
new Phrase('string with placeholder in escaped single quotes \'%1\'', 'arg'),
45+
new Phrase('string with "double quotes"'),
46+
new Phrase('string with placeholder in double quotes "%1"', 'arg'),
47+
];
48+
49+
$singleQuoteTranslateFunctions = [
50+
// Single concatenation
51+
__('first part' . ' second part'),
52+
__('first part' . ' second part' . ' third part'),
53+
54+
// Multiple concatenation
55+
__('first part' . ' second part with one string literal placeholder %1', 'arg'),
56+
__('first part of concat' . ' second part with one variable placeholder %1', $str1),
57+
__('first part of concat' . ' second part with two placeholders %1, %2', $str1, $str2),
58+
__('first part of concat' . ' second part' . ' third part with one placeholder %1', 'arg'),
59+
__('first part of concat' . ' second part' . ' third part with two placeholders %1, %2', $str1, $str2),
60+
61+
// Escaped quotes
62+
__('string with escaped \'single quotes\''),
63+
__('string with placeholder in escaped single quotes \'%1\'', 'arg'),
64+
__('string with "double quotes"'),
65+
__('string with placeholder in double quotes "%1"', 'arg'),
66+
];
67+
68+
$doubleQuoteTranslateFunctions = [
69+
// Single concatenation
70+
__("first part" . " second part"),
71+
__("first part" . " second part" . " third part"),
72+
73+
// Multiple concatenation
74+
__("first part" . " second part with one string literal placeholder %1", "arg"),
75+
__("first part of concat" . " second part with one variable placeholder %1", $str1),
76+
__("first part of concat" . " second part with two placeholders %1, %2", $str1, $str2),
77+
__("first part of concat" . " second part" . " third part with one placeholder %1", "arg"),
78+
__("first part of concat" . " second part" . " third part with two placeholders %1, %2", $str1, $str2),
79+
80+
// Escaped quotes
81+
__("string with 'single quotes'"),
82+
__("string with placeholder in single quotes '%1'", "arg"),
83+
__("string with escaped \"double quotes\""),
84+
__("string with placeholder in escaped double quotes \"%1\"", "arg"),
85+
];
86+
}
87+
}

setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Php/Tokenizer/PhraseCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ protected function _collectPhrase($phraseTokens)
139139
if ($phraseTokens) {
140140
/** @var \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer\Token $phraseToken */
141141
foreach ($phraseTokens as $phraseToken) {
142-
if ($phraseToken->isConstantEncapsedString()) {
142+
if ($phraseToken->isConstantEncapsedString() || $phraseToken->isConcatenateOperator()) {
143143
$phrase[] = $phraseToken->getValue();
144144
}
145145
}

setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Php/Tokenizer/Token.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ public function isSemicolon()
166166
return $this->getValue() == ';';
167167
}
168168

169+
/**
170+
* @return bool
171+
*/
172+
public function isConcatenateOperator()
173+
{
174+
return $this->getValue() == '.';
175+
}
176+
169177
/**
170178
* Is namespace separator
171179
*

setup/src/Magento/Setup/Test/Unit/Module/I18n/Parser/Adapter/Php/Tokenizer/PhraseCollectorTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,23 @@ protected function createToken(
204204
->willReturn($line);
205205
return $token;
206206
}
207+
208+
public function testCollectPhrases()
209+
{
210+
$firstPart = "'first part'";
211+
$firstPartToken = new Token(\T_CONSTANT_ENCAPSED_STRING, $firstPart);
212+
$concatenationToken = new Token('.', '.');
213+
$secondPart = "' second part'";
214+
$secondPartToken = new Token(\T_CONSTANT_ENCAPSED_STRING, $secondPart);
215+
$phraseTokens = [$firstPartToken, $concatenationToken, $secondPartToken];
216+
$phraseString = "'first part' . ' second part'";
217+
218+
$reflectionMethod = new \ReflectionMethod(
219+
'\Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer\PhraseCollector',
220+
'_collectPhrase'
221+
);
222+
223+
$reflectionMethod->setAccessible(true);
224+
$this->assertSame($phraseString, $reflectionMethod->invoke($this->phraseCollector, $phraseTokens));
225+
}
207226
}

setup/src/Magento/Setup/Test/Unit/Module/I18n/Parser/Adapter/Php/Tokenizer/TokenTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,16 @@ protected function createToken($name, $value)
118118
]
119119
);
120120
}
121+
122+
public function testIsConcatenateOperatorTrue()
123+
{
124+
$token = new \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer\Token('.', '.');
125+
$this->assertTrue($token->isConcatenateOperator());
126+
}
127+
128+
public function testIsConcatenateOperatorFalse()
129+
{
130+
$token = new \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer\Token(',', ',');
131+
$this->assertFalse($token->isConcatenateOperator());
132+
}
121133
}

0 commit comments

Comments
 (0)