From 9e0d531d36d607e711b97e2c7951fda867397dee Mon Sep 17 00:00:00 2001 From: HeahDude Date: Tue, 27 Dec 2016 15:46:49 +0100 Subject: [PATCH 1/5] [Form] Fixed DateType format option --- .../Form/Extension/Core/Type/DateType.php | 12 +++++--- .../Extension/Core/Type/DateTypeTest.php | 29 +++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php index 8af7a96f13..2bc433f841 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php @@ -51,11 +51,11 @@ class DateType extends AbstractType throw new InvalidOptionsException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom format.'); } - if (null !== $pattern && (false === strpos($pattern, 'y') || false === strpos($pattern, 'M') || false === strpos($pattern, 'd'))) { - throw new InvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" and "d". Its current value is "%s".', $pattern)); - } - if ('single_text' === $options['widget']) { + if (null !== $pattern && false === strpos($pattern, 'y') && false === strpos($pattern, 'M') && false === strpos($pattern, 'd')) { + throw new InvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" or "d". Its current value is "%s".', $pattern)); + } + $builder->addViewTransformer(new DateTimeToLocalizedStringTransformer( $options['model_timezone'], $options['view_timezone'], @@ -65,6 +65,10 @@ class DateType extends AbstractType $pattern )); } else { + if (null !== $pattern && (false === strpos($pattern, 'y') || false === strpos($pattern, 'M') || false === strpos($pattern, 'd'))) { + throw new InvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" and "d". Its current value is "%s".', $pattern)); + } + $yearOptions = $monthOptions = $dayOptions = array( 'error_bubbling' => true, ); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php index ea302d020e..b31fa5e9c5 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php @@ -67,6 +67,22 @@ class DateTypeTest extends TestCase $this->assertEquals('2010-06-02', $form->getViewData()); } + public function testSubmitFromSingleTextDateTimeWithCustomFormat() + { + $form = $this->factory->create('date', null, array( + 'model_timezone' => 'UTC', + 'view_timezone' => 'UTC', + 'widget' => 'single_text', + 'input' => 'datetime', + 'format' => 'yyyy', + )); + + $form->submit('2010'); + + $this->assertDateTimeEquals(new \DateTime('2010-01-01 UTC'), $form->getData()); + $this->assertEquals('2010', $form->getViewData()); + } + public function testSubmitFromSingleTextDateTime() { // we test against "de_AT", so we need the full implementation @@ -337,6 +353,7 @@ class DateTypeTest extends TestCase /** * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException + * @expectedExceptionMessage The "format" option should contain the letters "y", "M" and "d". Its current value is "yy". */ public function testThrowExceptionIfFormatDoesNotContainYearMonthAndDay() { @@ -346,6 +363,18 @@ class DateTypeTest extends TestCase )); } + /** + * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException + * @expectedExceptionMessage The "format" option should contain the letters "y", "M" or "d". Its current value is "wrong". + */ + public function testThrowExceptionIfFormatDoesNotContainYearMonthOrDay() + { + $this->factory->create('date', null, array( + 'widget' => 'single_text', + 'format' => 'wrong', + )); + } + /** * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException */ From 78c0ec5c136e7a7a4b905256910f71e9312207f7 Mon Sep 17 00:00:00 2001 From: Robin Lehrmann Date: Fri, 20 Jan 2017 14:40:15 +0100 Subject: [PATCH 2/5] [FrameworkBundle] fixed custom domain for translations in php templates --- .../Resources/views/translation.html.php | 16 +++++ .../Tests/Translation/PhpExtractorTest.php | 37 ++++++---- .../Translation/PhpExtractor.php | 67 +++++++++++++++++-- 3 files changed, 102 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/views/translation.html.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/views/translation.html.php index c0ae6ec5c6..cb3c763f8f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/views/translation.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/views/translation.html.php @@ -31,3 +31,19 @@ EOF 10, array('%count%' => 10) ) ?> + +trans('other-domain-test-no-params-short-array', [], 'not_messages'); ?> + +trans('other-domain-test-no-params-long-array', array(), 'not_messages'); ?> + +trans('other-domain-test-params-short-array', ['foo' => 'bar'], 'not_messages'); ?> + +trans('other-domain-test-params-long-array', array('foo' => 'bar'), 'not_messages'); ?> + +transChoice('other-domain-test-trans-choice-short-array-%count%', 10, ['%count%' => 10], 'not_messages'); ?> + +transChoice('other-domain-test-trans-choice-long-array-%count%', 10, array('%count%' => 10), 'not_messages'); ?> + +trans('typecast', ['a' => (int) '123'], 'not_messages'); ?> +transChoice('msg1', 10 + 1, [], 'not_messages'); ?> +transChoice('msg2', intval(4.5), [], 'not_messages'); ?> diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/PhpExtractorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/PhpExtractorTest.php index 420d2f2d71..e8c56ee4d5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/PhpExtractorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/PhpExtractorTest.php @@ -39,18 +39,31 @@ EOF; nowdoc key with whitespace and nonescaped \$\n sequences EOF; // Assert - $expectedCatalogue = array('messages' => array( - 'single-quoted key' => 'prefixsingle-quoted key', - 'double-quoted key' => 'prefixdouble-quoted key', - 'heredoc key' => 'prefixheredoc key', - 'nowdoc key' => 'prefixnowdoc key', - "double-quoted key with whitespace and escaped \$\n\" sequences" => "prefixdouble-quoted key with whitespace and escaped \$\n\" sequences", - 'single-quoted key with whitespace and nonescaped \$\n\' sequences' => 'prefixsingle-quoted key with whitespace and nonescaped \$\n\' sequences', - 'single-quoted key with "quote mark at the end"' => 'prefixsingle-quoted key with "quote mark at the end"', - $expectedHeredoc => 'prefix'.$expectedHeredoc, - $expectedNowdoc => 'prefix'.$expectedNowdoc, - '{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', - )); + $expectedCatalogue = array( + 'messages' => array( + 'single-quoted key' => 'prefixsingle-quoted key', + 'double-quoted key' => 'prefixdouble-quoted key', + 'heredoc key' => 'prefixheredoc key', + 'nowdoc key' => 'prefixnowdoc key', + "double-quoted key with whitespace and escaped \$\n\" sequences" => "prefixdouble-quoted key with whitespace and escaped \$\n\" sequences", + 'single-quoted key with whitespace and nonescaped \$\n\' sequences' => 'prefixsingle-quoted key with whitespace and nonescaped \$\n\' sequences', + 'single-quoted key with "quote mark at the end"' => 'prefixsingle-quoted key with "quote mark at the end"', + $expectedHeredoc => 'prefix'.$expectedHeredoc, + $expectedNowdoc => 'prefix'.$expectedNowdoc, + '{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', + ), + 'not_messages' => array( + 'other-domain-test-no-params-short-array' => 'prefixother-domain-test-no-params-short-array', + 'other-domain-test-no-params-long-array' => 'prefixother-domain-test-no-params-long-array', + 'other-domain-test-params-short-array' => 'prefixother-domain-test-params-short-array', + 'other-domain-test-params-long-array' => 'prefixother-domain-test-params-long-array', + 'other-domain-test-trans-choice-short-array-%count%' => 'prefixother-domain-test-trans-choice-short-array-%count%', + 'other-domain-test-trans-choice-long-array-%count%' => 'prefixother-domain-test-trans-choice-long-array-%count%', + 'typecast' => 'prefixtypecast', + 'msg1' => 'prefixmsg1', + 'msg2' => 'prefixmsg2', + ), + ); $actualCatalogue = $catalogue->all(); $this->assertEquals($expectedCatalogue, $actualCatalogue); diff --git a/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php b/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php index cf7f3c5769..97c94fdd14 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php @@ -24,6 +24,8 @@ use Symfony\Component\Translation\Extractor\ExtractorInterface; class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface { const MESSAGE_TOKEN = 300; + const METHOD_ARGUMENTS_TOKEN = 1000; + const DOMAIN_TOKEN = 1001; /** * Prefix for new found message. @@ -38,6 +40,28 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface * @var array */ protected $sequences = array( + array( + '->', + 'trans', + '(', + self::MESSAGE_TOKEN, + ',', + self::METHOD_ARGUMENTS_TOKEN, + ',', + self::DOMAIN_TOKEN, + ), + array( + '->', + 'transChoice', + '(', + self::MESSAGE_TOKEN, + ',', + self::METHOD_ARGUMENTS_TOKEN, + ',', + self::METHOD_ARGUMENTS_TOKEN, + ',', + self::DOMAIN_TOKEN, + ), array( '->', 'trans', @@ -105,11 +129,32 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface } } + private function skipMethodArgument(\Iterator $tokenIterator) + { + $openBraces = 0; + + for (; $tokenIterator->valid(); $tokenIterator->next()) { + $t = $tokenIterator->current(); + + if ('[' === $t[0] || '(' === $t[0]) { + ++$openBraces; + } + + if (']' === $t[0] || ')' === $t[0]) { + --$openBraces; + } + + if ((0 === $openBraces && ',' === $t[0]) || (-1 === $openBraces && ')' === $t[0])) { + break; + } + } + } + /** * Extracts the message from the iterator while the tokens * match allowed message tokens. */ - private function getMessage(\Iterator $tokenIterator) + private function getValue(\Iterator $tokenIterator) { $message = ''; $docToken = ''; @@ -155,16 +200,26 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface for ($key = 0; $key < $tokenIterator->count(); ++$key) { foreach ($this->sequences as $sequence) { $message = ''; + $domain = 'messages'; $tokenIterator->seek($key); - foreach ($sequence as $item) { + foreach ($sequence as $sequenceKey => $item) { $this->seekToNextRelevantToken($tokenIterator); - if ($this->normalizeToken($tokenIterator->current()) == $item) { + if ($this->normalizeToken($tokenIterator->current()) === $item) { $tokenIterator->next(); continue; - } elseif (self::MESSAGE_TOKEN == $item) { - $message = $this->getMessage($tokenIterator); + } elseif (self::MESSAGE_TOKEN === $item) { + $message = $this->getValue($tokenIterator); + + if (count($sequence) === ($sequenceKey + 1)) { + break; + } + } elseif (self::METHOD_ARGUMENTS_TOKEN === $item) { + $this->skipMethodArgument($tokenIterator); + } elseif (self::DOMAIN_TOKEN === $item) { + $domain = $this->getValue($tokenIterator); + break; } else { break; @@ -172,7 +227,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface } if ($message) { - $catalog->set($message, $this->prefix.$message); + $catalog->set($message, $this->prefix.$message, $domain); break; } } From 1e5707fed398ea972268823fcc2cb04e0847de39 Mon Sep 17 00:00:00 2001 From: Jay Klehr Date: Thu, 26 Jan 2017 23:50:33 -0700 Subject: [PATCH 3/5] Casting TableCell value to string. --- .../Component/Console/Helper/TableCell.php | 4 +++ .../Console/Tests/Helper/TableTest.php | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/Symfony/Component/Console/Helper/TableCell.php b/src/Symfony/Component/Console/Helper/TableCell.php index aa0d318079..1b34774f26 100644 --- a/src/Symfony/Component/Console/Helper/TableCell.php +++ b/src/Symfony/Component/Console/Helper/TableCell.php @@ -35,6 +35,10 @@ class TableCell */ public function __construct($value = '', array $options = array()) { + if (is_numeric($value) && !is_string($value)) { + $value = (string) $value; + } + $this->value = $value; // check option names diff --git a/src/Symfony/Component/Console/Tests/Helper/TableTest.php b/src/Symfony/Component/Console/Tests/Helper/TableTest.php index a691405c6b..4f37b8e21d 100644 --- a/src/Symfony/Component/Console/Tests/Helper/TableTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/TableTest.php @@ -509,6 +509,42 @@ TABLE | 1234 | +------+ +TABLE; + + $this->assertEquals($expected, $this->getOutputContent($output)); + } + + public function testTableCellWithNumericIntValue() + { + $table = new Table($output = $this->getOutputStream()); + + $table->setRows(array(array(new TableCell(12345)))); + $table->render(); + + $expected = +<<<'TABLE' ++-------+ +| 12345 | ++-------+ + +TABLE; + + $this->assertEquals($expected, $this->getOutputContent($output)); + } + + public function testTableCellWithNumericFloatValue() + { + $table = new Table($output = $this->getOutputStream()); + + $table->setRows(array(array(new TableCell(12345.01)))); + $table->render(); + + $expected = +<<<'TABLE' ++----------+ +| 12345.01 | ++----------+ + TABLE; $this->assertEquals($expected, $this->getOutputContent($output)); From ad8f18963ee92c0908806834c0cc466fcd8bd825 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 4 Feb 2017 08:36:32 -0800 Subject: [PATCH 4/5] fixed test name --- .../Component/Form/Tests/Extension/Core/Type/DateTypeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php index 282f43ee67..aee6da3478 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php @@ -367,7 +367,7 @@ class DateTypeTest extends TestCase * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException * @expectedExceptionMessage The "format" option should contain the letters "y", "M" or "d". Its current value is "wrong". */ - public function testThrowExceptionIfFormatDoesNotContainYearMonthOrDay() + public function testThrowExceptionIfFormatMissesYearMonthAndDayWithSingleTextWidget() { $this->factory->create('date', null, array( 'widget' => 'single_text', From 57f67e834bcef115a94f0910768c4fe2576d1cfc Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Sat, 4 Feb 2017 19:24:41 +0100 Subject: [PATCH 5/5] Remove 3.1 from PR template --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 216a2ba4e5..c9c3b75340 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,6 +1,6 @@ | Q | A | ------------- | --- -| Branch? | master / 2.7, 2.8, 3.1 or 3.2 +| Branch? | master / 2.7, 2.8 or 3.2 | Bug fix? | yes/no | New feature? | yes/no | BC breaks? | yes/no