diff --git a/.gitignore b/.gitignore index 422f1ce840..83ef63d16b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ phpunit.xml +composer.lock autoload.php /vendor/ diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php index 6ad960bff1..2debb97e25 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php @@ -175,6 +175,9 @@ class EntityChoiceList extends ObjectChoiceList // Optimize performance in case we have an entity loader and // a single-field identifier if (count($this->identifier) === 1 && $this->entityLoader) { + if (empty($values)) { + return array(); + } return $this->entityLoader->getEntitiesByIds(current($this->identifier), $values); } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/EntityChoiceListTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/EntityChoiceListTest.php index e0bc7f6763..97867e7591 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/EntityChoiceListTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/EntityChoiceListTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList; +use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader; use Symfony\Bridge\Doctrine\Tests\DoctrineOrmTestCase; use Symfony\Bridge\Doctrine\Tests\Fixtures\ItemGroupEntity; use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIdentEntity; @@ -250,4 +251,19 @@ class EntityChoiceListTest extends DoctrineOrmTestCase $this->assertEquals(array(1, 2), $choiceList->getValuesForChoices(array($item1, $item2))); $this->assertEquals(array(1, 2), $choiceList->getIndicesForChoices(array($item1, $item2))); } + + // Ticket #3446 + public function testGetEmptyArrayChoicesForEmptyValues() + { + $qb = $this->em->createQueryBuilder()->select('s')->from(self::SINGLE_IDENT_CLASS, 's'); + $entityLoader = new ORMQueryBuilderLoader($qb); + $choiceList = new EntityChoiceList( + $this->em, + self::SINGLE_IDENT_CLASS, + null, + $entityLoader + ); + + $this->assertEquals(array(), $choiceList->getChoicesForValues(array())); + } } diff --git a/src/Symfony/Bridge/Propel1/README.md b/src/Symfony/Bridge/Propel1/README.md index d281c2a21d..f3ca773557 100644 --- a/src/Symfony/Bridge/Propel1/README.md +++ b/src/Symfony/Bridge/Propel1/README.md @@ -15,6 +15,6 @@ Components, declare the following environment variables before running PHPUnit: export PROPEL1=../path/to/Propel - export HTTP_FOUNDATION=../path/to/HttpFoundation - export HTTP_KERNEL=../path/to/HttpKernel - export HTTP_FORM=../path/to/Form + export SYMFONY_HTTP_FOUNDATION=../path/to/HttpFoundation + export SYMFONY_HTTP_KERNEL=../path/to/HttpKernel + export SYMFONY_FORM=../path/to/Form diff --git a/src/Symfony/Bridge/Twig/README.md b/src/Symfony/Bridge/Twig/README.md index 0fac6c5bcd..a2ed06829a 100644 --- a/src/Symfony/Bridge/Twig/README.md +++ b/src/Symfony/Bridge/Twig/README.md @@ -15,8 +15,8 @@ If you also want to run the unit tests that depend on other Symfony Components, declare the following environment variables before running PHPUnit: - export HTTP_TWIG=../path/to/Twig - export HTTP_FORM=../path/to/Form - export HTTP_TRANSLATION=../path/to/Translation - export HTTP_EVENT_DISPATCHER=../path/to/EventDispatcher - export HTTP_LOCALE=../path/to/Locale + export TWIG=../path/to/Twig + export SYMFONY_FORM=../path/to/Form + export SYMFONY_TRANSLATION=../path/to/Translation + export SYMFONY_EVENT_DISPATCHER=../path/to/EventDispatcher + export SYMFONY_LOCALE=../path/to/Locale diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml index 429aa9f679..eaa52bda62 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml @@ -14,6 +14,7 @@ services: class: FooClass calls: - [ setBar, [] ] + - [ setBar ] method_call2: class: FooClass calls: diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php index c094c2126c..ec20ec617d 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php @@ -26,7 +26,9 @@ class CollectionType extends AbstractType public function buildForm(FormBuilder $builder, array $options) { if ($options['allow_add'] && $options['prototype']) { - $prototype = $builder->create($options['prototype_name'], $options['type'], $options['options']); + $prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array( + 'label' => $options['prototype_name'] . 'label__', + ), $options['options'])); $builder->setAttribute('prototype', $prototype->getForm()); } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php b/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php index b51323bb09..d9bbe6222c 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php @@ -200,6 +200,6 @@ class FieldType extends AbstractType private function humanize($text) { - return ucfirst(strtolower(str_replace('_', ' ', $text))); + return ucfirst(trim(strtolower(preg_replace('/[_\s]+/', ' ', $text)))); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php index b8f4b19858..b0bb62508f 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php @@ -185,4 +185,16 @@ class CollectionTypeTest extends TypeTestCase $this->assertSame('__test__', $form->getAttribute('prototype')->getName()); } + + public function testPrototypeDefaultLabel() + { + $form = $this->factory->create('collection', array(), array( + 'type' => 'file', + 'allow_add' => true, + 'prototype' => true, + 'prototype_name' => '__test__', + )); + + $this->assertSame('__test__label__', $form->createView()->get('prototype')->get('label')); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FieldTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FieldTypeTest.php index 7b0aee4d3f..d1a547c8b7 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FieldTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FieldTypeTest.php @@ -188,6 +188,22 @@ class FieldTypeTest extends TypeTestCase $this->assertSame('test', $view->get('translation_domain')); } + public function testPassDefaultLabelToView() + { + $form = $this->factory->createNamed('field', '__test___field'); + $view = $form->createView(); + + $this->assertSame('Test field', $view->get('label')); + } + + public function testPassLabelToView() + { + $form = $this->factory->createNamed('field', '__test___field', null, array('label' => 'My label')); + $view = $form->createView(); + + $this->assertSame('My label', $view->get('label')); + } + public function testDefaultTranslationDomain() { $form = $this->factory->create('field');