Merge branch 'master' into cs-fixes

This commit is contained in:
Eriksen Costa 2012-04-07 03:53:28 -03:00
commit abd59c3dbd
10 changed files with 61 additions and 10 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
phpunit.xml
composer.lock
autoload.php
/vendor/

View File

@ -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);
}

View File

@ -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()));
}
}

View File

@ -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

View File

@ -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

View File

@ -14,6 +14,7 @@ services:
class: FooClass
calls:
- [ setBar, [] ]
- [ setBar ]
method_call2:
class: FooClass
calls:

View File

@ -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());
}

View File

@ -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))));
}
}

View File

@ -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'));
}
}

View File

@ -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');