Classes List

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

 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 
<?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 Symfony\Component\Form\ChoiceList\View\ChoiceView;

class TimezoneTypeTest extends BaseTypeTest
{
    const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\TimezoneType';

    public function testTimezonesAreSelectable()
    {
        $choices = $this->factory->create(static::TESTED_TYPE)
            ->createView()->vars['choices'];

        $this->assertArrayHasKey('Africa'$choices);
        $this->assertContains(new ChoiceView('Africa/Kinshasa''Africa/Kinshasa''Kinshasa'), $choices['Africa'], ''falsefalse);

        $this->assertArrayHasKey('America'$choices);
        $this->assertContains(new ChoiceView('America/New_York''America/New_York''New York'), $choices['America'], ''falsefalse);
    }

    public function testSubmitNull($expected = null$norm = null$view = null)
    {
        parent::testSubmitNull($expected$norm'');
    }

    public function testDateTimeZoneInput()
    {
        $form = $this->factory->create(static::TESTED_TYPEnew \DateTimeZone('America/New_York'), array('input' => 'datetimezone'));

        $this->assertSame('America/New_York'$form->createView()->vars['value']);

        $form->submit('Europe/Amsterdam');

        $this->assertEquals(new \DateTimeZone('Europe/Amsterdam'), $form->getData());

        $form = $this->factory->create(static::TESTED_TYPEarray(new \DateTimeZone('America/New_York')), array('input' => 'datetimezone''multiple' => true));

        $this->assertSame(array('America/New_York'), $form->createView()->vars['value']);

        $form->submit(array('Europe/Amsterdam''Europe/Paris'));

        $this->assertEquals(array(new \DateTimeZone('Europe/Amsterdam'), new \DateTimeZone('Europe/Paris')), $form->getData());
    }

    public function testFilterByRegions()
    {
        $choices = $this->factory->create(static::TESTED_TYPEnullarray('regions' => \DateTimeZone::EUROPE))
            ->createView()->vars['choices'];

        $this->assertContains(new ChoiceView('Europe/Amsterdam''Europe/Amsterdam''Amsterdam'), $choices''falsefalse);
    }
}