Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a69b31f

Browse filesBrowse files
committed
Add tests
1 parent 8404f72 commit a69b31f
Copy full SHA for a69b31f

File tree

6 files changed

+177
-0
lines changed
Filter options

6 files changed

+177
-0
lines changed

‎src/Symfony/Component/Form/ChoiceList/Loader/IntlCallbackChoiceLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/ChoiceList/Loader/IntlCallbackChoiceLoader.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/**
1515
* Callback choice loader optimized for Intl choice types.
1616
*
17+
* @author Jules Pietri <jules@heahprod.com>
1718
* @author Yonel Ceruto <yonelceruto@gmail.com>
1819
*/
1920
class IntlCallbackChoiceLoader extends CallbackChoiceLoader
+104Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Tests\ChoiceList\Loader;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
16+
use Symfony\Component\Form\ChoiceList\LazyChoiceList;
17+
use Symfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader;
18+
19+
/**
20+
* @author Jules Pietri <jules@heahprod.com>
21+
* @author Yonel Ceruto <yonelceruto@gmail.com>
22+
*/
23+
class IntlCallbackChoiceLoaderTest extends TestCase
24+
{
25+
/**
26+
* @var \Symfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader
27+
*/
28+
private static $loader;
29+
30+
/**
31+
* @var callable
32+
*/
33+
private static $value;
34+
35+
/**
36+
* @var array
37+
*/
38+
private static $choices;
39+
40+
/**
41+
* @var string[]
42+
*/
43+
private static $choiceValues;
44+
45+
/**
46+
* @var \Symfony\Component\Form\ChoiceList\LazyChoiceList
47+
*/
48+
private static $lazyChoiceList;
49+
50+
public static function setUpBeforeClass()
51+
{
52+
self::$loader = new IntlCallbackChoiceLoader(function () {
53+
return self::$choices;
54+
});
55+
self::$value = function ($choice) {
56+
return $choice->value ?? null;
57+
};
58+
self::$choices = array(
59+
(object) array('value' => 'choice_one'),
60+
(object) array('value' => 'choice_two'),
61+
);
62+
self::$choiceValues = array('choice_one', 'choice_two');
63+
self::$lazyChoiceList = new LazyChoiceList(self::$loader, self::$value);
64+
}
65+
66+
public function testLoadChoiceList()
67+
{
68+
$this->assertInstanceOf(ChoiceListInterface::class, self::$loader->loadChoiceList(self::$value));
69+
}
70+
71+
public function testLoadChoiceListOnlyOnce()
72+
{
73+
$loadedChoiceList = self::$loader->loadChoiceList(self::$value);
74+
75+
$this->assertSame($loadedChoiceList, self::$loader->loadChoiceList(self::$value));
76+
}
77+
78+
public function testLoadChoicesForValuesLoadsChoiceListOnFirstCall()
79+
{
80+
$this->assertSame(
81+
self::$loader->loadChoicesForValues(self::$choiceValues, self::$value),
82+
self::$lazyChoiceList->getChoicesForValues(self::$choiceValues),
83+
'Choice list should not be reloaded.'
84+
);
85+
}
86+
87+
public function testLoadValuesForChoicesLoadsChoiceListOnFirstCall()
88+
{
89+
$this->assertSame(
90+
self::$loader->loadValuesForChoices(self::$choices, self::$value),
91+
self::$lazyChoiceList->getValuesForChoices(self::$choices),
92+
'Choice list should not be reloaded.'
93+
);
94+
}
95+
96+
public static function tearDownAfterClass()
97+
{
98+
self::$loader = null;
99+
self::$value = null;
100+
self::$choices = array();
101+
self::$choiceValues = array();
102+
self::$lazyChoiceList = null;
103+
}
104+
}

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ public function testCountriesAreSelectable()
3838
$this->assertContains(new ChoiceView('MY', 'MY', 'Malaysia'), $choices, '', false, false);
3939
}
4040

41+
/**
42+
* @requires extension intl
43+
*/
44+
public function testChoiceTranslationLocaleOption()
45+
{
46+
$choices = $this->factory
47+
->create(static::TESTED_TYPE, null, array(
48+
'choice_translation_locale' => 'uk',
49+
))
50+
->createView()->vars['choices'];
51+
52+
// Don't check objects for identity
53+
$this->assertContains(new ChoiceView('DE', 'DE', 'Німеччина'), $choices, '', false, false);
54+
$this->assertContains(new ChoiceView('GB', 'GB', 'Велика Британія'), $choices, '', false, false);
55+
$this->assertContains(new ChoiceView('US', 'US', 'Сполучені Штати'), $choices, '', false, false);
56+
$this->assertContains(new ChoiceView('FR', 'FR', 'Франція'), $choices, '', false, false);
57+
$this->assertContains(new ChoiceView('MY', 'MY', 'Малайзія'), $choices, '', false, false);
58+
}
59+
4160
public function testUnknownCountryIsNotIncluded()
4261
{
4362
$choices = $this->factory->create(static::TESTED_TYPE, 'country')

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ public function testCurrenciesAreSelectable()
3535
$this->assertContains(new ChoiceView('SIT', 'SIT', 'Slovenian Tolar'), $choices, '', false, false);
3636
}
3737

38+
/**
39+
* @requires extension intl
40+
*/
41+
public function testChoiceTranslationLocaleOption()
42+
{
43+
$choices = $this->factory
44+
->create(static::TESTED_TYPE, null, array(
45+
'choice_translation_locale' => 'uk',
46+
))
47+
->createView()->vars['choices'];
48+
49+
// Don't check objects for identity
50+
$this->assertContains(new ChoiceView('EUR', 'EUR', 'євро'), $choices, '', false, false);
51+
$this->assertContains(new ChoiceView('USD', 'USD', 'долар США'), $choices, '', false, false);
52+
$this->assertContains(new ChoiceView('SIT', 'SIT', 'словенський толар'), $choices, '', false, false);
53+
}
54+
3855
public function testSubmitNull($expected = null, $norm = null, $view = null)
3956
{
4057
parent::testSubmitNull($expected, $norm, '');

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ public function testCountriesAreSelectable()
3737
$this->assertContains(new ChoiceView('my', 'my', 'Burmese'), $choices, '', false, false);
3838
}
3939

40+
/**
41+
* @requires extension intl
42+
*/
43+
public function testChoiceTranslationLocaleOption()
44+
{
45+
$choices = $this->factory
46+
->create(static::TESTED_TYPE, null, array(
47+
'choice_translation_locale' => 'uk',
48+
))
49+
->createView()->vars['choices'];
50+
51+
// Don't check objects for identity
52+
$this->assertContains(new ChoiceView('en', 'en', 'англійська'), $choices, '', false, false);
53+
$this->assertContains(new ChoiceView('en_GB', 'en_GB', 'British English'), $choices, '', false, false);
54+
$this->assertContains(new ChoiceView('en_US', 'en_US', 'англійська (США)'), $choices, '', false, false);
55+
$this->assertContains(new ChoiceView('fr', 'fr', 'французька'), $choices, '', false, false);
56+
$this->assertContains(new ChoiceView('my', 'my', 'бірманська'), $choices, '', false, false);
57+
}
58+
4059
public function testMultipleLanguagesIsNotIncluded()
4160
{
4261
$choices = $this->factory->create(static::TESTED_TYPE, 'language')

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ public function testLocalesAreSelectable()
3535
$this->assertContains(new ChoiceView('zh_Hant_MO', 'zh_Hant_MO', 'Chinese (Traditional, Macau SAR China)'), $choices, '', false, false);
3636
}
3737

38+
/**
39+
* @requires extension intl
40+
*/
41+
public function testChoiceTranslationLocaleOption()
42+
{
43+
$choices = $this->factory
44+
->create(static::TESTED_TYPE, null, array(
45+
'choice_translation_locale' => 'uk',
46+
))
47+
->createView()->vars['choices'];
48+
49+
// Don't check objects for identity
50+
$this->assertContains(new ChoiceView('en', 'en', 'англійська'), $choices, '', false, false);
51+
$this->assertContains(new ChoiceView('en_GB', 'en_GB', 'англійська (Велика Британія)'), $choices, '', false, false);
52+
$this->assertContains(new ChoiceView('zh_Hant_MO', 'zh_Hant_MO', 'китайська (традиційна, Макао, О.А.Р Китаю)'), $choices, '', false, false);
53+
}
54+
3855
public function testSubmitNull($expected = null, $norm = null, $view = null)
3956
{
4057
parent::testSubmitNull($expected, $norm, '');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.