Closed
Description
This used to work before migrating to 2.1:
$form = $crawler->selectButton('Créer')->form(array(
'uc_legalbundle_countrygrouptype[name]' => 'Peninsule iberique',
'uc_legalbundle_countrygrouptype[countries]' => array('ES','PT'),
));
Now, it gives me the following stack trace:
1) Uc\LegalBundle\Tests\Controller\CountryGroupControllerTest::testCompleteScenario
InvalidArgumentException: Unreachable field "0"
/home/users/gparis/workspace/legal-backend/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Form.php:459
/home/users/gparis/workspace/legal-backend/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Form.php:496
/home/users/gparis/workspace/legal-backend/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Form.php:500
/home/users/gparis/workspace/legal-backend/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Form.php:74
/home/users/gparis/workspace/legal-backend/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Crawler.php:650
/home/users/gparis/workspace/legal-backend/src/Uc/LegalBundle/Tests/Controller/CountryGroupControllerTest.php:23
"0" refers to the first key of this array: array('ES', 'PT')
Selecting a single value can still be done, like this:
$form = $crawler->selectButton('Créer')->form(array(
'uc_legalbundle_countrygrouptype[name]' => 'Peninsule iberique',
'uc_legalbundle_countrygrouptype[countries]' => 'ES',
));
The form still works in the frontend, here is the code:
<?php
namespace Uc\LegalBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
class CountryGroupType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('countries', new CountryType(), array(
'multiple' => true,
'attr' => array('data-placeholder' => 'select.default_text')))
;
}
public function getName()
{
return 'uc_legalbundle_countrygrouptype';
}
public function getDefaultOptions(array $options)
{
return array('data_class' => 'Uc\LegalBundle\Entity\CountryGroup');
}
}