1515use Symfony \Component \Form \ChoiceList \View \ChoiceView ;
1616use Symfony \Component \Form \Extension \Core \Type \CurrencyType ;
1717use Symfony \Component \Intl \Util \IntlTestHelper ;
18+ use Symfony \Component \OptionsResolver \Exception \InvalidOptionsException ;
1819
1920class CurrencyTypeTest extends BaseTypeTestCase
2021{
@@ -34,7 +35,6 @@ public function testCurrenciesAreSelectable()
3435
3536 $ this ->assertContainsEquals (new ChoiceView ('EUR ' , 'EUR ' , 'Euro ' ), $ choices );
3637 $ this ->assertContainsEquals (new ChoiceView ('USD ' , 'USD ' , 'US Dollar ' ), $ choices );
37- $ this ->assertContainsEquals (new ChoiceView ('SIT ' , 'SIT ' , 'Slovenian Tolar ' ), $ choices );
3838 }
3939
4040 #[RequiresPhpExtension('intl ' )]
@@ -49,7 +49,6 @@ public function testChoiceTranslationLocaleOption()
4949 // Don't check objects for identity
5050 $ this ->assertContainsEquals (new ChoiceView ('EUR ' , 'EUR ' , 'євро ' ), $ choices );
5151 $ this ->assertContainsEquals (new ChoiceView ('USD ' , 'USD ' , 'долар США ' ), $ choices );
52- $ this ->assertContainsEquals (new ChoiceView ('SIT ' , 'SIT ' , 'словенський толар ' ), $ choices );
5352 }
5453
5554 public function testSubmitNull ($ expected = null , $ norm = null , $ view = null )
@@ -61,4 +60,63 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = 'EUR', $expected
6160 {
6261 parent ::testSubmitNullUsesDefaultEmptyData ($ emptyData , $ expectedData );
6362 }
63+
64+ #[RequiresPhpExtension('intl ' )]
65+ public function testAnActiveAndLegalTenderCurrencyIn2006 ()
66+ {
67+ $ choices = $ this ->factory
68+ ->create (static ::TESTED_TYPE , null , [
69+ 'choice_translation_locale ' => 'fr ' ,
70+ 'active_at ' => new \DateTimeImmutable ('2006-01-01 ' , new \DateTimeZone ('Etc/UTC ' )),
71+ 'legal_tender ' => true ,
72+ ])
73+ ->createView ()->vars ['choices ' ];
74+
75+ $ this ->assertContainsEquals (new ChoiceView ('SIT ' , 'SIT ' , 'tolar slovène ' ), $ choices );
76+ }
77+
78+ #[RequiresPhpExtension('intl ' )]
79+ public function testAnExpiredCurrencyIn2007 ()
80+ {
81+ $ choices = $ this ->factory
82+ ->create (static ::TESTED_TYPE , null , [
83+ 'choice_translation_locale ' => 'fr ' ,
84+ 'legal_tender ' => true ,
85+ // The SIT currency expired on 2007-01-14.
86+ 'active_at ' => new \DateTimeImmutable ('2007-01-15 ' , new \DateTimeZone ('Etc/UTC ' )),
87+ ])
88+ ->createView ()->vars ['choices ' ];
89+
90+ $ this ->assertNotContainsEquals (new ChoiceView ('SIT ' , 'SIT ' , 'tolar slovène ' ), $ choices );
91+ }
92+
93+ #[RequiresPhpExtension('intl ' )]
94+ public function testRetrieveExpiredCurrenciesIn2007 ()
95+ {
96+ $ choices = $ this ->factory
97+ ->create (static ::TESTED_TYPE , null , [
98+ 'choice_translation_locale ' => 'fr ' ,
99+ 'legal_tender ' => true ,
100+ 'active_at ' => null ,
101+ // The SIT currency expired on 2007-01-14.
102+ 'not_active_at ' => new \DateTimeImmutable ('2007-01-15 ' , new \DateTimeZone ('Etc/UTC ' )),
103+ ])
104+ ->createView ()->vars ['choices ' ];
105+
106+ $ this ->assertContainsEquals (new ChoiceView ('SIT ' , 'SIT ' , 'tolar slovène ' ), $ choices );
107+ }
108+
109+ public function testAnExceptionShouldBeThrownWhenTheActiveAtAndNotActiveAtOptionsAreBothSet ()
110+ {
111+ $ this ->expectException (InvalidOptionsException::class);
112+
113+ $ this ->expectExceptionMessage ('The "active_at" and "not_active_at" options cannot be used together. ' );
114+
115+ $ this ->factory
116+ ->create (static ::TESTED_TYPE , null , [
117+ 'active_at ' => new \DateTimeImmutable (),
118+ 'not_active_at ' => new \DateTimeImmutable (),
119+ ])
120+ ->createView ();
121+ }
64122}
0 commit comments