LocaleFieldTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\LocaleField;
  12. use Symfony\Component\Form\FormContext;
  13. class LocaleFieldTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testLocalesAreSelectable()
  16. {
  17. FormContext::setLocale('de_AT');
  18. $field = new LocaleField('language');
  19. $choices = $field->getOtherChoices();
  20. $this->assertArrayHasKey('en', $choices);
  21. $this->assertEquals('Englisch', $choices['en']);
  22. $this->assertArrayHasKey('en_GB', $choices);
  23. $this->assertEquals('Englisch (Vereinigtes Königreich)', $choices['en_GB']);
  24. $this->assertArrayHasKey('zh_Hans_MO', $choices);
  25. $this->assertEquals('Chinesisch (vereinfacht, Sonderverwaltungszone Macao)', $choices['zh_Hans_MO']);
  26. }
  27. public function testEmptyValueOption()
  28. {
  29. // empty_value false
  30. $field = new LocaleField('language', array('empty_value' => false));
  31. $choices = $field->getOtherChoices();
  32. $this->assertArrayNotHasKey('', $choices);
  33. // empty_value as a blank string
  34. $field = new LocaleField('language', array('empty_value' => ''));
  35. $choices = $field->getOtherChoices();
  36. $this->assertArrayHasKey('', $choices);
  37. $this->assertEquals('', $choices['']);
  38. // empty_value as a normal string
  39. $field = new LocaleField('language', array('empty_value' => 'Choose a locale'));
  40. $choices = $field->getOtherChoices();
  41. $this->assertArrayHasKey('', $choices);
  42. $this->assertEquals('Choose a locale', $choices['']);
  43. }
  44. }