|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Feature; |
| 4 | + |
| 5 | +use Doefom\CurrencyFieldtype\Fieldtypes\CurrencyFieldtype; |
| 6 | +use Doefom\CurrencyFieldtype\Models\Currency; |
| 7 | +use Statamic\Facades\Site; |
| 8 | +use Statamic\Fields\Field; |
| 9 | +use Tests\TestCase; |
| 10 | + |
| 11 | +class CurrencyFieldtypeWithNullValueTest extends TestCase |
| 12 | +{ |
| 13 | + |
| 14 | + protected CurrencyFieldtype $currencyFieldtype; |
| 15 | + protected Currency $augmented; |
| 16 | + |
| 17 | + /** |
| 18 | + * Set up a field of currency fieldtype with a value of null and the following configuration: |
| 19 | + * handle: price |
| 20 | + * iso: USD |
| 21 | + * |
| 22 | + * For NumberFormatter use the locale en_US. |
| 23 | + * |
| 24 | + * @return void |
| 25 | + */ |
| 26 | + protected function setUp(): void |
| 27 | + { |
| 28 | + parent::setUp(); |
| 29 | + |
| 30 | + Site::setCurrent('en_US'); |
| 31 | + |
| 32 | + $value = null; |
| 33 | + |
| 34 | + // -------------------------------------------------------- |
| 35 | + // SET UP FIELDTYPE |
| 36 | + // -------------------------------------------------------- |
| 37 | + |
| 38 | + $field = new Field('price', [ |
| 39 | + 'iso' => 'USD', |
| 40 | + 'type' => 'currency', |
| 41 | + 'display' => 'Price', |
| 42 | + 'icon' => 'currency', |
| 43 | + 'listable' => 'hidden', |
| 44 | + 'instructions_position' => 'above', |
| 45 | + 'visibility' => 'visible', |
| 46 | + 'hide_display' => false, |
| 47 | + ]); |
| 48 | + $field->setValue($value); |
| 49 | + |
| 50 | + $this->currencyFieldtype = new CurrencyFieldtype(); |
| 51 | + $this->currencyFieldtype->setField($field); |
| 52 | + |
| 53 | + // -------------------------------------------------------- |
| 54 | + // SET UP AUGMENTED INSTANCE |
| 55 | + // -------------------------------------------------------- |
| 56 | + |
| 57 | + $this->augmented = $this->currencyFieldtype->augment($value); |
| 58 | + |
| 59 | + } |
| 60 | + |
| 61 | + public function test_pre_process() |
| 62 | + { |
| 63 | + $result = $this->currencyFieldtype->preProcess(null); |
| 64 | + $this->assertNull($result); |
| 65 | + } |
| 66 | + |
| 67 | + public function test_process() |
| 68 | + { |
| 69 | + $result = $this->currencyFieldtype->process(null); |
| 70 | + $this->assertNull($result); |
| 71 | + } |
| 72 | + |
| 73 | + public function test_pre_process_index() |
| 74 | + { |
| 75 | + $result = $this->currencyFieldtype->preProcessIndex(null); |
| 76 | + $this->assertNull($result); |
| 77 | + } |
| 78 | + |
| 79 | + public function test_augmented_value() |
| 80 | + { |
| 81 | + $this->assertEquals(null, $this->augmented->value); |
| 82 | + } |
| 83 | + |
| 84 | + public function test_augmented_display_value() |
| 85 | + { |
| 86 | + $this->assertEquals(null, $this->augmented->display_value); |
| 87 | + } |
| 88 | + |
| 89 | + public function test_augmented_formatted() |
| 90 | + { |
| 91 | + $this->assertNull($this->augmented->formatted); |
| 92 | + } |
| 93 | + |
| 94 | + public function test_augmented_formatted_no_symbol() |
| 95 | + { |
| 96 | + $this->assertNull($this->augmented->formattedNoSymbol); |
| 97 | + } |
| 98 | + |
| 99 | + public function test_augmented_iso() |
| 100 | + { |
| 101 | + $this->assertEquals('USD', $this->augmented->iso); |
| 102 | + } |
| 103 | + |
| 104 | + public function test_augmented_numeric_code() |
| 105 | + { |
| 106 | + $this->assertEquals('840', $this->augmented->numericCode); |
| 107 | + } |
| 108 | + |
| 109 | + public function test_augmented_symbol() |
| 110 | + { |
| 111 | + $this->assertEquals('$', $this->augmented->symbol); |
| 112 | + } |
| 113 | + |
| 114 | + public function test_augmented_append() |
| 115 | + { |
| 116 | + $this->assertFalse($this->augmented->append); |
| 117 | + } |
| 118 | + |
| 119 | + public function test_augmented_group_separator() |
| 120 | + { |
| 121 | + $this->assertEquals(',', $this->augmented->groupSeparator); |
| 122 | + } |
| 123 | + |
| 124 | + public function test_augmented_radix_point() |
| 125 | + { |
| 126 | + $this->assertEquals('.', $this->augmented->radixPoint); |
| 127 | + } |
| 128 | + |
| 129 | + public function test_augmented_digits() |
| 130 | + { |
| 131 | + $this->assertEquals(2, $this->augmented->digits); |
| 132 | + } |
| 133 | + |
| 134 | +} |
0 commit comments