TimezoneFieldTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Form;
  11. use Symfony\Component\Form\TimezoneField;
  12. class TimezoneFieldTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testTimezonesAreSelectable()
  15. {
  16. $field = new TimeZoneField('timezone');
  17. $choices = $field->getOtherChoices();
  18. $this->assertArrayHasKey('Africa', $choices);
  19. $this->assertArrayHasKey('Africa/Kinshasa', $choices['Africa']);
  20. $this->assertEquals('Kinshasa', $choices['Africa']['Africa/Kinshasa']);
  21. $this->assertArrayHasKey('America', $choices);
  22. $this->assertArrayHasKey('America/New_York', $choices['America']);
  23. $this->assertEquals('New York', $choices['America']['America/New_York']);
  24. }
  25. public function testEmptyValueOption()
  26. {
  27. // empty_value false
  28. $field = new TimezoneField('timezone', array('empty_value' => false));
  29. $choices = $field->getOtherChoices();
  30. $this->assertArrayNotHasKey('', $choices);
  31. // empty_value as a blank string
  32. $field = new TimezoneField('timezone', array('empty_value' => ''));
  33. $choices = $field->getOtherChoices();
  34. $this->assertArrayHasKey('', $choices);
  35. $this->assertEquals('', $choices['']);
  36. // empty_value as a normal string
  37. $field = new TimezoneField('timezone', array('empty_value' => 'Choose your timezone'));
  38. $choices = $field->getOtherChoices();
  39. $this->assertArrayHasKey('', $choices);
  40. $this->assertEquals('Choose your timezone', $choices['']);
  41. }
  42. }