LanguageFieldTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\LanguageField;
  12. use Symfony\Component\Form\FormContext;
  13. class LanguageFieldTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testCountriesAreSelectable()
  16. {
  17. FormContext::setLocale('de_AT');
  18. $field = new LanguageField('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('Britisches Englisch', $choices['en_GB']);
  24. $this->assertArrayHasKey('en_US', $choices);
  25. $this->assertEquals('Amerikanisches Englisch', $choices['en_US']);
  26. $this->assertArrayHasKey('fr', $choices);
  27. $this->assertEquals('Französisch', $choices['fr']);
  28. $this->assertArrayHasKey('my', $choices);
  29. $this->assertEquals('Birmanisch', $choices['my']);
  30. }
  31. public function testMultipleLanguagesIsNotIncluded()
  32. {
  33. $field = new LanguageField('language');
  34. $choices = $field->getOtherChoices();
  35. $this->assertArrayNotHasKey('mul', $choices);
  36. }
  37. public function testEmptyValueOption()
  38. {
  39. // empty_value false
  40. $field = new LanguageField('language', array('empty_value' => false));
  41. $choices = $field->getOtherChoices();
  42. $this->assertArrayNotHasKey('', $choices);
  43. // empty_value as a blank string
  44. $field = new LanguageField('language', array('empty_value' => ''));
  45. $choices = $field->getOtherChoices();
  46. $this->assertArrayHasKey('', $choices);
  47. $this->assertEquals('', $choices['']);
  48. // empty_value as a normal string
  49. $field = new LanguageField('language', array('empty_value' => 'Choose a language'));
  50. $choices = $field->getOtherChoices();
  51. $this->assertArrayHasKey('', $choices);
  52. $this->assertEquals('Choose a language', $choices['']);
  53. }
  54. }