|
4 | 4 |
|
5 | 5 | use PHPUnit\Framework\Attributes\DataProvider; |
6 | 6 | use PHPUnit\Framework\Attributes\Test; |
| 7 | +use Statamic\Facades\Blueprint; |
7 | 8 | use Statamic\Facades\Collection; |
8 | 9 | use Statamic\Facades\Entry; |
9 | 10 | use Statamic\Facades\Fieldset; |
10 | 11 | use Statamic\Facades\GlobalSet; |
| 12 | +use Statamic\Facades\Taxonomy; |
11 | 13 | use Statamic\Facades\Term; |
12 | 14 | use Statamic\Facades\User; |
13 | 15 | use Statamic\UpdateScripts\ConvertDatesToUtc; |
@@ -56,7 +58,6 @@ public function it_converts_date_fields_in_entries(string $fieldHandle, array $f |
56 | 58 | date_default_timezone_set('America/New_York'); |
57 | 59 |
|
58 | 60 | $collection = tap(Collection::make('articles'))->save(); |
59 | | - |
60 | 61 | $collection->entryBlueprint()->setContents(['fields' => [$field]])->save(); |
61 | 62 |
|
62 | 63 | $entry = Entry::make()->collection('articles')->data([$fieldHandle => $original]); |
@@ -93,16 +94,42 @@ public function it_converts_entry_date_field_in_entries() |
93 | 94 |
|
94 | 95 | #[Test] |
95 | 96 | #[DataProvider('dateFieldsProvider')] |
96 | | - public function it_converts_entry_date_field_in_terms() |
| 97 | + public function it_converts_date_fields_in_terms(string $fieldHandle, array $field, $original, $expected) |
97 | 98 | { |
98 | | - $this->markTestIncomplete(); |
| 99 | + config()->set('app.timezone', 'America/New_York'); // -05:00 |
| 100 | + date_default_timezone_set('America/New_York'); |
| 101 | + |
| 102 | + $taxonomy = tap(Taxonomy::make('tags'))->save(); |
| 103 | + $taxonomy->termBlueprint()->setContents(['fields' => [$field]])->save(); |
| 104 | + |
| 105 | + $term = Term::make()->taxonomy('tags')->data([$fieldHandle => $original]); |
| 106 | + $term->save(); |
| 107 | + |
| 108 | + $this->runUpdateScript(ConvertDatesToUtc::class); |
| 109 | + |
| 110 | + $this->assertEquals($expected, $term->fresh()->get($fieldHandle)); |
99 | 111 | } |
100 | 112 |
|
101 | 113 | #[Test] |
102 | 114 | #[DataProvider('dateFieldsProvider')] |
103 | | - public function it_converts_entry_date_field_in_globals() |
| 115 | + public function it_converts_date_fields_in_globals(string $fieldHandle, array $field, $original, $expected) |
104 | 116 | { |
105 | | - $this->markTestIncomplete(); |
| 117 | + config()->set('app.timezone', 'America/New_York'); // -05:00 |
| 118 | + date_default_timezone_set('America/New_York'); |
| 119 | + |
| 120 | + $globalSet = tap(GlobalSet::make('settings'))->save(); |
| 121 | + $globalSet->addLocalization( |
| 122 | + $globalSet->makeLocalization('en')->data([$fieldHandle => $original]) |
| 123 | + ); |
| 124 | + $globalSet->save(); |
| 125 | + |
| 126 | + Blueprint::make('settings')->setNamespace('globals')->setContents(['fields' => [$field]])->save(); |
| 127 | + |
| 128 | + $this->runUpdateScript(ConvertDatesToUtc::class); |
| 129 | + |
| 130 | + $globalSet = GlobalSet::find('settings'); |
| 131 | + |
| 132 | + $this->assertEquals($expected, $globalSet->inDefaultSite()->get($fieldHandle)); |
106 | 133 | } |
107 | 134 |
|
108 | 135 | #[Test] |
|
0 commit comments