CountryFieldTest.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\CountryField;
  12. use Symfony\Component\Form\FormContext;
  13. class CountryFieldTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testCountriesAreSelectable()
  16. {
  17. FormContext::setLocale('de_AT');
  18. $field = new CountryField('country');
  19. $choices = $field->getOtherChoices();
  20. $this->assertArrayHasKey('DE', $choices);
  21. $this->assertEquals('Deutschland', $choices['DE']);
  22. $this->assertArrayHasKey('GB', $choices);
  23. $this->assertEquals('Vereinigtes Königreich', $choices['GB']);
  24. $this->assertArrayHasKey('US', $choices);
  25. $this->assertEquals('Vereinigte Staaten', $choices['US']);
  26. $this->assertArrayHasKey('FR', $choices);
  27. $this->assertEquals('Frankreich', $choices['FR']);
  28. $this->assertArrayHasKey('MY', $choices);
  29. $this->assertEquals('Malaysia', $choices['MY']);
  30. }
  31. public function testUnknownCountryIsNotIncluded()
  32. {
  33. $field = new CountryField('country');
  34. $choices = $field->getOtherChoices();
  35. $this->assertArrayNotHasKey('ZZ', $choices);
  36. }
  37. public function testEmptyValueOption()
  38. {
  39. // empty_value false
  40. $field = new CountryField('country', array('empty_value' => false));
  41. $choices = $field->getOtherChoices();
  42. $this->assertArrayNotHasKey('', $choices);
  43. // empty_value as a blank string
  44. $field = new CountryField('country', 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 CountryField('country', array('empty_value' => 'Choose a country'));
  50. $choices = $field->getOtherChoices();
  51. $this->assertArrayHasKey('', $choices);
  52. $this->assertEquals('Choose a country', $choices['']);
  53. }
  54. }