Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commita69b31f

Browse files
committed
Add tests
1 parent8404f72 commita69b31f

File tree

6 files changed

+177
-0
lines changed

6 files changed

+177
-0
lines changed

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

Lines 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 IntlCallbackChoiceLoaderextends CallbackChoiceLoader
Lines 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+
namespaceSymfony\Component\Form\Tests\ChoiceList\Loader;
13+
14+
usePHPUnit\Framework\TestCase;
15+
useSymfony\Component\Form\ChoiceList\ChoiceListInterface;
16+
useSymfony\Component\Form\ChoiceList\LazyChoiceList;
17+
useSymfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader;
18+
19+
/**
20+
* @author Jules Pietri <jules@heahprod.com>
21+
* @author Yonel Ceruto <yonelceruto@gmail.com>
22+
*/
23+
class IntlCallbackChoiceLoaderTestextends TestCase
24+
{
25+
/**
26+
* @var \Symfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader
27+
*/
28+
privatestatic$loader;
29+
30+
/**
31+
* @var callable
32+
*/
33+
privatestatic$value;
34+
35+
/**
36+
* @var array
37+
*/
38+
privatestatic$choices;
39+
40+
/**
41+
* @var string[]
42+
*/
43+
privatestatic$choiceValues;
44+
45+
/**
46+
* @var \Symfony\Component\Form\ChoiceList\LazyChoiceList
47+
*/
48+
privatestatic$lazyChoiceList;
49+
50+
publicstaticfunctionsetUpBeforeClass()
51+
{
52+
self::$loader =newIntlCallbackChoiceLoader(function () {
53+
returnself::$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 =newLazyChoiceList(self::$loader,self::$value);
64+
}
65+
66+
publicfunctiontestLoadChoiceList()
67+
{
68+
$this->assertInstanceOf(ChoiceListInterface::class,self::$loader->loadChoiceList(self::$value));
69+
}
70+
71+
publicfunctiontestLoadChoiceListOnlyOnce()
72+
{
73+
$loadedChoiceList =self::$loader->loadChoiceList(self::$value);
74+
75+
$this->assertSame($loadedChoiceList,self::$loader->loadChoiceList(self::$value));
76+
}
77+
78+
publicfunctiontestLoadChoicesForValuesLoadsChoiceListOnFirstCall()
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+
publicfunctiontestLoadValuesForChoicesLoadsChoiceListOnFirstCall()
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+
publicstaticfunctiontearDownAfterClass()
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‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ public function testCountriesAreSelectable()
3838
$this->assertContains(newChoiceView('MY','MY','Malaysia'),$choices,'',false,false);
3939
}
4040

41+
/**
42+
* @requires extension intl
43+
*/
44+
publicfunctiontestChoiceTranslationLocaleOption()
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(newChoiceView('DE','DE','Німеччина'),$choices,'',false,false);
54+
$this->assertContains(newChoiceView('GB','GB','Велика Британія'),$choices,'',false,false);
55+
$this->assertContains(newChoiceView('US','US','Сполучені Штати'),$choices,'',false,false);
56+
$this->assertContains(newChoiceView('FR','FR','Франція'),$choices,'',false,false);
57+
$this->assertContains(newChoiceView('MY','MY','Малайзія'),$choices,'',false,false);
58+
}
59+
4160
publicfunctiontestUnknownCountryIsNotIncluded()
4261
{
4362
$choices =$this->factory->create(static::TESTED_TYPE,'country')

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ public function testCurrenciesAreSelectable()
3535
$this->assertContains(newChoiceView('SIT','SIT','Slovenian Tolar'),$choices,'',false,false);
3636
}
3737

38+
/**
39+
* @requires extension intl
40+
*/
41+
publicfunctiontestChoiceTranslationLocaleOption()
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(newChoiceView('EUR','EUR','євро'),$choices,'',false,false);
51+
$this->assertContains(newChoiceView('USD','USD','долар США'),$choices,'',false,false);
52+
$this->assertContains(newChoiceView('SIT','SIT','словенський толар'),$choices,'',false,false);
53+
}
54+
3855
publicfunctiontestSubmitNull($expected =null,$norm =null,$view =null)
3956
{
4057
parent::testSubmitNull($expected,$norm,'');

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ public function testCountriesAreSelectable()
3737
$this->assertContains(newChoiceView('my','my','Burmese'),$choices,'',false,false);
3838
}
3939

40+
/**
41+
* @requires extension intl
42+
*/
43+
publicfunctiontestChoiceTranslationLocaleOption()
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(newChoiceView('en','en','англійська'),$choices,'',false,false);
53+
$this->assertContains(newChoiceView('en_GB','en_GB','British English'),$choices,'',false,false);
54+
$this->assertContains(newChoiceView('en_US','en_US','англійська (США)'),$choices,'',false,false);
55+
$this->assertContains(newChoiceView('fr','fr','французька'),$choices,'',false,false);
56+
$this->assertContains(newChoiceView('my','my','бірманська'),$choices,'',false,false);
57+
}
58+
4059
publicfunctiontestMultipleLanguagesIsNotIncluded()
4160
{
4261
$choices =$this->factory->create(static::TESTED_TYPE,'language')

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ public function testLocalesAreSelectable()
3535
$this->assertContains(newChoiceView('zh_Hant_MO','zh_Hant_MO','Chinese (Traditional, Macau SAR China)'),$choices,'',false,false);
3636
}
3737

38+
/**
39+
* @requires extension intl
40+
*/
41+
publicfunctiontestChoiceTranslationLocaleOption()
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(newChoiceView('en','en','англійська'),$choices,'',false,false);
51+
$this->assertContains(newChoiceView('en_GB','en_GB','англійська (Велика Британія)'),$choices,'',false,false);
52+
$this->assertContains(newChoiceView('zh_Hant_MO','zh_Hant_MO','китайська (традиційна, Макао, О.А.Р Китаю)'),$choices,'',false,false);
53+
}
54+
3855
publicfunctiontestSubmitNull($expected =null,$norm =null,$view =null)
3956
{
4057
parent::testSubmitNull($expected,$norm,'');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp