8000 Merge branch '2.7' into 2.8 · symfony/symfony@47a8b4d · GitHub
[go: up one dir, main page]

Skip to content

Commit 47a8b4d

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Remove 3.1 from PR template fixed test name Casting TableCell value to string. [FrameworkBundle] fixed custom domain for translations in php templates [Form] Fixed DateType format option
2 parents 6ac1223 + c98832b commit 47a8b4d

File tree

8 files changed

+180
-23
lines changed

8 files changed

+180
-23
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
| Q | A
22
| ------------- | ---
3-
| Branch? | master / 2.7, 2.8, 3.1 or 3.2 <!--see comment below-->
3+
| Branch? | master / 2.7, 2.8 or 3.2 <!--see comment below-->
44
| Bug fix? | yes/no
55
| New feature? | yes/no
66
| BC breaks? | yes/no

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/views/translation.html.php

Lines changed: 16 additions & 0 deletions
33
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,19 @@
3131
10,
3232
array('%count%' => 10)
33
) ?>
34+
35+
<?php echo $view['translator']->trans('other-domain-test-no-params-short-array', [], 'not_messages'); ?>
36+
37+
<?php echo $view['translator']->trans('other-domain-test-no-params-long-array', array(), 'not_messages'); ?>
38+
39+
<?php echo $view['translator']->trans('other-domain-test-params-short-array', ['foo' => 'bar'], 'not_messages'); ?>
40+
41+
<?php echo $view['translator']->trans('other-domain-test-params-long-array', array('foo' => 'bar'), 'not_messages'); ?>
42+
43+
<?php echo $view['translator']->transChoice('other-domain-test-trans-choice-short-array-%count%', 10, ['%count%' => 10], 'not_messages'); ?>
44+
45+
<?php echo $view['translator']->transChoice('other-domain-test-trans-choice-long-array-%count%', 10, array('%count%' => 10), 'not_messages'); ?>
46+
47+
<?php echo $view['translator']->trans('typecast', ['a' => (int) '123'], 'not_messages'); ?>
48+
<?php echo $view['translator']->transChoice('msg1', 10 + 1, [], 'not_messages'); ?>
49+
<?php echo $view['translator']->transChoice('msg2', intval(4.5), [], 'not_messages'); ?>

src/Symfony/Bundle/FrameworkBundle/Tests/Translation/PhpExtractorTest.php

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,31 @@ public function testExtraction($resource)
3939
nowdoc key with whitespace and nonescaped \$\n sequences
4040
EOF;
4141
// Assert
42-
$expectedCatalogue = array('messages' => array(
43-
'single-quoted key' => 'prefixsingle-quoted key',
44-
'double-quoted key' => 'prefixdouble-quoted key',
45-
'heredoc key' => 'prefixheredoc key',
46-
'nowdoc key' => 'prefixnowdoc key',
47-
"double-quoted key with whitespace and escaped \$\n\" sequences" => "prefixdouble-quoted key with whitespace and escaped \$\n\" sequences",
48-
'single-quoted key with whitespace and nonescaped \$\n\' sequences' => 'prefixsingle-quoted key with whitespace and nonescaped \$\n\' sequences',
49-
'single-quoted key with "quote mark at the end"' => 'prefixsingle-quoted key with "quote mark at the end"',
50-
$expectedHeredoc => 'prefix'.$expectedHeredoc,
51-
$expectedNowdoc => 'prefix'.$expectedNowdoc,
52-
'{0} There is no apples|{1} There is one apple|]1,Inf[ There are %count% apples' => 'prefix{0} There is no apples|{1} There is one apple|]1,Inf[ There are %count% apples',
53-
));
42+
$expectedCatalogue = array(
43+
'messages' => array(
44+
'single-quoted key' => 'prefixsingle-quoted key',
45+
'double-quoted key' => 'prefixdouble-quoted key',
46+
'heredoc key' => 'prefixheredoc key',
47+
'nowdoc key' => 'prefixnowdoc key',
48+
"double-quoted key with whitespace and escaped \$\n\" sequences" => "prefixdouble-quoted key with whitespace and escaped \$\n\" sequences",
49+
'single-quoted key with whitespace and nonescaped \$\n\' sequences' => 'prefixsingle-quoted key with whitespace and nonescaped \$\n\' sequences',
50+
'single-quoted key with "quote mark at the end"' => 'prefixsingle-quoted key with "quote mark at the end"',
51+
$expectedHeredoc => 'prefix'.$expectedHeredoc,
52+
$expectedNowdoc => 'prefix'.$expectedNowdoc,
53+
'{0} There is no apples|{1} There is one apple|]1,Inf[ There are %count% apples' => 'prefix{0} There is no apples|{1} There is one apple|]1,Inf[ There are %count% apples',
54+
),
55+
'not_messages' => array(
56+
'other-domain-test-no-params-short-array' => 'prefixother-domain-test-no-params-short-array',
57+
'other-domain-test-no-params-long-array' => 'prefixother-domain-test-no-params-long-array',
58+
'other-domain-test-params-short-array' => 'prefixother-domain-test-params-short-array',
59+
'other-domain-test-params-long-array' => 'prefixother-domain-test-params-long-array',
60+
'other-domain-test-trans-choice-short-array-%count%' => 'prefixother-domain-test-trans-choice-short-array-%count%',
61+
'other-domain-test-trans-choice-long-array-%count%' => 'prefixother-domain-test-trans-choice-long-array-%count%',
62+
'typecast' => 'prefixtypecast',
63+
'msg1' => 'prefixmsg1',
64+
'msg2' => 'prefixmsg2',
65+
),
66+
);
5467
$actualCatalogue = $catalogue->all();
5568

5669
$this->assertEquals($expectedCatalogue, $actualCatalogue);

src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
2525
{
2626
const MESSAGE_TOKEN = 300;
27+
const METHOD_ARGUMENTS_TOKEN = 1000;
28+
const DOMAIN_TOKEN = 1001;
2729

2830
/**
2931
* Prefix for new found message.
@@ -38,6 +40,28 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
3840
* @var array
3941
*/
4042
protected $sequences = array(
43+
array(
44+
'->',
45+
'trans',
46+
'(',
47+
self::MESSAGE_TOKEN,
48+
',',
49+
self::METHOD_ARGUMENTS_TOKEN,
50+
',',
51+
self::DOMAIN_TOKEN,
52+
),
53+
array(
54+
'->',
55+
'transChoice',
56+
'(',
57+
self::MESSAGE_TOKEN,
58+
',',
59+
self::METHOD_ARGUMENTS_TOKEN,
60+
',',
61+
self::METHOD_ARGUMENTS_TOKEN,
62+
',',
63+
self::DOMAIN_TOKEN,
64+
),
4165
array(
4266
'->',
4367
'trans',
@@ -105,11 +129,32 @@ private function seekToNextRelevantToken(\Iterator $tokenIterator)
105129
}
106130
}
107131

132+
private function skipMethodArgument(\Iterator $tokenIterator)
133+
{
134+
$openBraces = 0;
135+
136+
for (; $tokenIterator->valid(); $tokenIterator->next()) {
137+
$t = $tokenIterator->current();
138+
139+
if ('[' === $t[0] || '(' === $t[0]) {
140+
++$openBraces;
141+
}
142+
143+
if (']' === $t[0] || ')' === $t[0]) {
144+
--$openBraces;
145+
}
146+
147+
if ((0 === $openBraces && ',' === $t[0]) || (-1 === $openBraces && ')' === $t[0])) {
148+
break;
149+
}
150+
}
151+
}
152+
108153
/**
109154
* Extracts the message from the iterator while the tokens
110155
* match allowed message tokens.
111156
*/
112-
private function getMessage(\Iterator $tokenIterator)
157+
private function getValue(\Iterator $tokenIterator)
113158
{
114159
$message = '';
115160
$docToken = '';
@@ -155,24 +200,34 @@ protected function parseTokens($tokens, MessageCatalogue $catalog)
155200
for ($key = 0; $key < $tokenIterator->count(); ++$key) {
156201
foreach ($this->sequences as $sequence) {
157202
$message = '';
203+
$domain = 'messages';
158204
$tokenIterator->seek($key);
159205

160-
foreach ($sequence as $item) {
206+
foreach ($sequence as $sequenceKey => $item) {
161207
$this->seekToNextRelevantToken($tokenIterator);
162208

163-
if ($this->normalizeToken($tokenIterator->current()) == $item) {
209+
if ($this->normalizeToken($tokenIterator->current()) === $item) {
164210
$tokenIterator->next();
165211
continue;
166-
} elseif (self::MESSAGE_TOKEN == $item) {
167-
$message = $this->getMessage($tokenIterator);
212+
} elseif (self::MESSAGE_TOKEN === $item) {
213+
$message = $this->getValue($tokenIterator);
214+
215+
if (count($sequence) === ($sequenceKey + 1)) {
216+
break;
217+
}
218+
} elseif (self::METHOD_ARGUMENTS_TOKEN === $item) {
219+
$this->skipMethodArgument($tokenIterator);
220+
} elseif (self::DOMAIN_TOKEN === $item) {
221+
$domain = $this->getValue($tokenIterator);
222+
168223
break;
169224
} else {
170225
break;
171226
}
172227
}
173228

174229
if ($message) {
175-
$catalog->set($message, $this->prefix.$message);
230+
$catalog->set($message, $this->prefix.$message, $domain);
176231
break;
177232
}
178233
}

src/Symfony/Component/Console/Helper/TableCell.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class TableCell
3737
*/
3838
public function __construct($value = '', array $options = array())
3939
{
40+
if (is_numeric($value) && !is_string($value)) {
41+
$value = (string) $value;
42+
}
43+
4044
$this->value = $value;
4145

4246
// check option names

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,42 @@ public function testRenderMultiByte()
535535
| 1234 |
536536
+------+
537537

538+
TABLE;
539+
540+
$this->assertEquals($expected, $this->getOutputContent($output));
541+
}
542+
543+
public function testTableCellWithNumericIntValue()
544+
{
545+
$table = new Table($output = $this->getOutputStream());
546+
547+
$table->setRows(array(array(new TableCell(12345))));
548+
$table->render();
549+
550+
$expected =
551+
<<<'TABLE'
552+
+-------+
553+
| 12345 |
554+
+-------+
555+
556+
TABLE;
557+
558+
$this->assertEquals($expected, $this->getOutputContent($output));
559+
}
560+
561+
public function testTableCellWithNumericFloatValue()
562+
{
563+
$table = new Table($output = $this->getOutputStream());
564+
565+
$table->setRows(array(array(new TableCell(12345.01))));
566+
$table->render();
567+
568+
$expected =
569+
<<<'TABLE'
570+
+----------+
571+
| 12345.01 |
572+
+----------+
573+
538574
TABLE;
539575

540576
$this->assertEquals($expected, $this->getOutputContent($output));

src/Symfony/Component/Form/Extension/Core/Type/DateType.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5656
throw new InvalidOptionsException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom format.');
5757
}
5858

59-
if (null !== $pattern && (false === strpos($pattern, 'y') || false === strpos($pattern, 'M') || false === strpos($pattern, 'd'))) {
60-
throw new InvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" and "d". Its current value is "%s".', $pattern));
61-
}
62-
6359
if ('single_text' === $options['widget']) {
60+
if (null !== $pattern && false === strpos($pattern, 'y') && false === strpos($pattern, 'M') && false === strpos($pattern, 'd')) {
61+
throw new InvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" or "d". Its current value is "%s".', $pattern));
62+
}
63+
6464
$builder->addViewTransformer(new DateTimeToLocalizedStringTransformer(
6565
$options['model_timezone'],
6666
$options['view_timezone'],
@@ -70,6 +70,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
7070
$pattern
7171
));
7272
} else {
73+
if (null !== $pattern && (false === strpos($pattern, 'y') || false === strpos($pattern, 'M') || false === strpos($pattern, 'd'))) {
74+
throw new InvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" and "d". Its current value is "%s".', $pattern));
75+
}
76+
7377
$yearOptions = $monthOptions = $dayOptions = array(
7478
'error_bubbling' => true,
7579
);

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ public function testSubmitFromSingleTextDateTimeWithDefaultFormat()
7777
$this->assertEquals('2010-06-02', $form->getViewData());
7878
}
7979

80+
public function testSubmitFromSingleTextDateTimeWithCustomFormat()
81+
{
82+
$form = $this->factory->create('date', null, array(
83+
'model_timezone' => 'UTC',
84+
'view_timezone' => 'UTC',
85+
'widget' => 'single_text',
86+
'input' => 'datetime',
87+
'format' => 'yyyy',
88+
));
89+
90+
$form->submit('2010');
91+
92+
$this->assertDateTimeEquals(new \DateTime('2010-01-01 UTC'), $form->getData());
93+
$this->assertEquals('2010', $form->getViewData());
94+
}
95+
8096
public function testSubmitFromSingleTextDateTime()
8197
{
8298
// we test against "de_DE", so we need the full implementation
@@ -347,6 +363,7 @@ public function testThrowExceptionIfFormatIsNoPattern()
347363

348364
/**
349365
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
366+
* @expectedExceptionMessage The "format" option should contain the letters "y", "M" and "d". Its current value is "yy".
350367
*/
351368
public function testThrowExceptionIfFormatDoesNotContainYearMonthAndDay()
352369
{
@@ -356,6 +373,18 @@ public function testThrowExceptionIfFormatDoesNotContainYearMonthAndDay()
356373
));
357374
}
358375

376+
/**
377+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
378+
* @expectedExceptionMessage The "format" option should contain the letters "y", "M" or "d". Its current value is "wrong".
379+
*/
380+
public function testThrowExceptionIfFormatMissesYearMonthAndDayWithSingleTextWidget()
381+
{
382+
$this->factory->create('date', null, array(
383+
'widget' => 'single_text',
384+
'format' => 'wrong',
385+
));
386+
}
387+
359388
/**
360389
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
361390
*/

0 commit comments

Comments
 (0)
0