|
12 | 12 | namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
13 | 13 |
|
14 | 14 | use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
| 15 | +use Symfony\Component\Form\Exception\LogicException; |
15 | 16 | use Symfony\Component\Intl\Util\IntlTestHelper;
|
16 | 17 |
|
17 | 18 | class LanguageTypeTest extends BaseTypeTest
|
@@ -86,6 +87,52 @@ public function testChoiceTranslationLocaleAndAlpha3Option()
|
86 | 87 | $this->assertNotContainsEquals(new ChoiceView('my', 'my', 'бірманська'), $choices);
|
87 | 88 | }
|
88 | 89 |
|
| 90 | + /** |
| 91 | + * @requires extension intl |
| 92 | + */ |
| 93 | + public function testChoiceSelfTranslationOption() |
| 94 | + { |
| 95 | + $choices = $this->factory |
| 96 | + ->create(static::TESTED_TYPE, null, [ |
| 97 | + 'choice_self_translation' => true, |
| 98 | + ]) |
| 99 | + ->createView()->vars['choices']; |
| 100 | + |
| 101 | + $this->assertContainsEquals(new ChoiceView('cs', 'cs', 'čeština'), $choices); |
| 102 | + $this->assertContainsEquals(new ChoiceView('es', 'es', 'español'), $choices); |
| 103 | + $this->assertContainsEquals(new ChoiceView('fr', 'fr', 'français'), $choices); |
| 104 | + $this->assertContainsEquals(new ChoiceView('ta', 'ta', 'தமிழ்'), $choices); |
| 105 | + $this->assertContainsEquals(new ChoiceView('uk', 'uk', 'українська'), $choices); |
| 106 | + $this->assertContainsEquals(new ChoiceView('yi', 'yi', 'ייִדיש'), $choices); |
| 107 | + $this->assertContainsEquals(new ChoiceView('zh', 'zh', '中文'), $choices); |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * @requires extension intl |
| 112 | + */ |
| 113 | + public function testChoiceSelfTranslationAndAlpha3Options() |
| 114 | + { |
| 115 | + $choices = $this->factory |
| 116 | + ->create(static::TESTED_TYPE, null, [ |
| 117 | + 'alpha3' => true, |
| 118 | + 'choice_self_translation' => true, |
| 119 | + ]) |
| 120 | + ->createView()->vars['choices']; |
| 121 | + |
| 122 | + $this->assertContainsEquals(new ChoiceView('spa', 'spa', 'español'), $choices, '', false, false); |
| 123 | + $this->assertContainsEquals(new ChoiceView('yid', 'yid', 'ייִדיש'), $choices, '', false, false); |
| 124 | + } |
| 125 | + |
| 126 | + public function testSelfTranslationNotAllowedWithChoiceTranslation() |
| 127 | + { |
| 128 | + $this->expectException(LogicException::class); |
| 129 | + |
| 130 | + $this->factory->create(static::TESTED_TYPE, null, [ |
| 131 | + 'choice_translation_locale' => 'es', |
| 132 | + 'choice_self_translation' => true, |
| 133 | + ]); |
| 134 | + } |
| 135 | + |
89 | 136 | public function testMultipleLanguagesIsNotIncluded()
|
90 | 137 | {
|
91 | 138 | $choices = $this->factory->create(static::TESTED_TYPE, 'language')
|
|
0 commit comments