Classes List

Symfony\Component\Form\Tests\Extension\Core\Type\ExtendedChoiceTypeTest

 1 
 2 
 3 
 4 
 5 
 6 
 7 
 8 
 9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
 19 
 20 
 21 
 22 
 23 
 24 
 25 
 26 
 27 
 28 
 29 
 30 
 31 
 32 
 33 
 34 
 35 
 36 
 37 
 38 
 39 
 40 
 41 
 42 
 43 
 44 
 45 
 46 
 47 
 48 
 49 
 50 
 51 
 52 
 53 
 54 
 55 
 56 
 57 
 58 
 59 
 60 
 61 
 62 
 63 
 64 
 65 
 66 
 67 
 68 
 69 
 70 
 71 
 72 
 73 
 74 
 75 
 76 
 77 
 78 
 79 
 80 
 81 
 82 
 83 
 84 
 85 
 86 
 87 
 88 
<?php

/* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */


namespace Symfony\Component\Form\Tests\Extension\Core\Type;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\Forms;
use Symfony\Component\Form\Tests\Fixtures\ChoiceTypeExtension;
use Symfony\Component\Form\Tests\Fixtures\LazyChoiceTypeExtension;

class ExtendedChoiceTypeTest extends TestCase
{
    /** * @group legacy * @dataProvider provideTestedTypes */
    public function testLegacyChoicesAreOverridden($type)
    {
        $factory = Forms::createFormFactoryBuilder()
            ->addTypeExtension(new ChoiceTypeExtension($type))
            ->getFormFactory()
        ;

        $choices = $factory->create($type)->createView()->vars['choices'];

        $this->assertCount(2$choices);
        $this->assertSame('A'$choices[0]->label);
        $this->assertSame('a'$choices[0]->value);
        $this->assertSame('B'$choices[1]->label);
        $this->assertSame('b'$choices[1]->value);
    }

    /** * @dataProvider provideTestedTypes */
    public function testChoicesAreOverridden($type)
    {
        $factory = Forms::createFormFactoryBuilder()
            ->addTypeExtension(new ChoiceTypeExtension($type))
            ->getFormFactory()
        ;

        $choices = $factory->create($typenullarray('choice_loader' => null))->createView()->vars['choices'];

        $this->assertCount(2$choices);
        $this->assertSame('A'$choices[0]->label);
        $this->assertSame('a'$choices[0]->value);
        $this->assertSame('B'$choices[1]->label);
        $this->assertSame('b'$choices[1]->value);
    }

    /** * @dataProvider provideTestedTypes */
    public function testChoiceLoaderIsOverridden($type)
    {
        $factory = Forms::createFormFactoryBuilder()
            ->addTypeExtension(new LazyChoiceTypeExtension($type))
            ->getFormFactory()
        ;

        $choices = $factory->create($type)->createView()->vars['choices'];

        $this->assertCount(2$choices);
        $this->assertSame('Lazy A'$choices[0]->label);
        $this->assertSame('lazy_a'$choices[0]->value);
        $this->assertSame('Lazy B'$choices[1]->label);
        $this->assertSame('lazy_b'$choices[1]->value);
    }

    public function provideTestedTypes()
    {
        yield array(CountryTypeTest::TESTED_TYPE);
        yield array(CurrencyTypeTest::TESTED_TYPE);
        yield array(LanguageTypeTest::TESTED_TYPE);
        yield array(LocaleTypeTest::TESTED_TYPE);
        yield array(TimezoneTypeTest::TESTED_TYPE);
    }
}