33namespace Feature ;
44
55use Doefom \CurrencyFieldtype \Fieldtypes \CurrencyFieldtype ;
6+ use Doefom \CurrencyFieldtype \Models \Currency ;
67use Statamic \Facades \Site ;
78use Statamic \Fields \Field ;
8- use Statamic \ Statamic ;
9+ use Tests \ TestCase ;
910
10- class CurrencyFieldtypeTest extends \ Orchestra \ Testbench \ TestCase
11+ class CurrencyFieldtypeTest extends TestCase
1112{
1213
1314 protected CurrencyFieldtype $ currencyFieldtype ;
15+ protected Currency $ augmented ;
1416
15- protected function getPackageProviders ($ app )
16- {
17- return [
18- 'Doefom\CurrencyFieldtype\ServiceProvider ' ,
19- \Statamic \Providers \StatamicServiceProvider::class,
20- ];
21- }
22-
17+ /**
18+ * Set up a field of currency fieldtype with the following configuration:
19+ * handle: price
20+ * iso: USD
21+ *
22+ * For NumberFormatter use the locale en_US.
23+ *
24+ * @return void
25+ */
2326 protected function setUp (): void
2427 {
2528 parent ::setUp ();
29+
2630 Site::setCurrent ('en_US ' );
2731
32+ $ value = 1234.56 ;
33+
34+ // --------------------------------------------------------
35+ // SET UP FIELDTYPE
36+ // --------------------------------------------------------
37+
2838 $ field = new Field ('price ' , [
2939 'iso ' => 'USD ' ,
3040 'type ' => 'currency ' ,
@@ -35,12 +45,19 @@ protected function setUp(): void
3545 'visibility ' => 'visible ' ,
3646 'hide_display ' => false ,
3747 ]);
38- $ field ->setValue (1234.56 );
48+ $ field ->setValue ($ value );
3949
4050 $ currencyFieldtype = new CurrencyFieldtype ();
4151 $ currencyFieldtype ->setField ($ field );
4252
4353 $ this ->currencyFieldtype = $ currencyFieldtype ;
54+
55+ // --------------------------------------------------------
56+ // SET UP AUGMENTED INSTANCE
57+ // --------------------------------------------------------
58+
59+ $ this ->augmented = $ this ->currencyFieldtype ->augment ($ value );
60+
4461 }
4562
4663 public function test_pre_process ()
@@ -49,4 +66,66 @@ public function test_pre_process()
4966 $ this ->assertEquals ('1,234.56 ' , $ result );
5067 }
5168
69+ public function test_process ()
70+ {
71+ $ result = $ this ->currencyFieldtype ->process ('1,234.56 ' );
72+ $ this ->assertEquals (1234.56 , $ result );
73+ }
74+
75+ public function test_pre_process_index ()
76+ {
77+ $ result = $ this ->currencyFieldtype ->preProcessIndex (1234.56 );
78+ $ this ->assertEquals ('$1,234.56 ' , $ result );
79+ }
80+
81+ public function test_augmented_value ()
82+ {
83+ $ this ->assertEquals (1234.56 , $ this ->augmented ->value );
84+ }
85+
86+ public function test_augmented_formatted ()
87+ {
88+ $ this ->assertEquals ('$1,234.56 ' , $ this ->augmented ->formatted );
89+ }
90+
91+ public function test_augmented_formatted_no_symbol ()
92+ {
93+ $ this ->assertEquals ('1,234.56 ' , $ this ->augmented ->formattedNoSymbol );
94+ }
95+
96+ public function test_augmented_iso ()
97+ {
98+ $ this ->assertEquals ('USD ' , $ this ->augmented ->iso );
99+ }
100+
101+ public function test_augmented_numeric_code ()
102+ {
103+ $ this ->assertEquals ('840 ' , $ this ->augmented ->numericCode );
104+ }
105+
106+ public function test_augmented_symbol ()
107+ {
108+ $ this ->assertEquals ('$ ' , $ this ->augmented ->symbol );
109+ }
110+
111+ public function test_augmented_append ()
112+ {
113+ $ this ->assertFalse ($ this ->augmented ->append );
114+ }
115+
116+ public function test_augmented_group_separator ()
117+ {
118+ $ this ->assertEquals (', ' , $ this ->augmented ->groupSeparator );
119+ }
120+
121+ public function test_augmented_radix_point ()
122+ {
123+ $ this ->assertEquals ('. ' , $ this ->augmented ->radixPoint );
124+ }
125+
126+ public function test_augmented_digits ()
127+ {
128+ $ this ->assertEquals (2 , $ this ->augmented ->digits );
129+ }
130+
52131}
0 commit comments