-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathEntryModelTest.php
More file actions
114 lines (96 loc) · 3.05 KB
/
EntryModelTest.php
File metadata and controls
114 lines (96 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace Tests\Entries;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Eloquent\Entries\EntryModel;
use Tests\TestCase;
class EntryModelTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function it_gets_attributes_from_json_column()
{
$model = new EntryModel([
'slug' => 'the-slug',
'data' => [
'foo' => 'bar',
],
]);
$this->assertEquals('the-slug', $model->slug);
$this->assertEquals('bar', $model->foo);
$this->assertEquals(['foo' => 'bar'], $model->data);
}
#[Test]
public function it_gets_date_as_utc()
{
config()->set('app.timezone', 'America/New_York'); // -05:00
date_default_timezone_set('America/New_York');
DB::table('entries')->insert([
'id' => '1',
'site' => 'en',
'published' => 1,
'date' => '2025-01-01 12:11:10',
'collection' => 'blog',
'data' => '{}',
]);
$date = EntryModel::find(1)->date;
$this->assertInstanceOf(Carbon::class, $date);
$this->assertEquals('2025-01-01T12:11:10+00:00', $date->toIso8601String());
}
#[Test]
public function it_sets_utc_date_from_string()
{
config()->set('app.timezone', 'America/New_York'); // -05:00
date_default_timezone_set('America/New_York');
$model = new EntryModel;
$model->id = 1;
$model->site = 'en';
$model->published = true;
$model->collection = 'blog';
$model->date = '2025-01-01 12:11:10';
$model->data = [];
$model->save();
$this->assertDatabaseHas('entries', [
'id' => 1,
'date' => '2025-01-01 12:11:10',
]);
}
#[Test]
public function it_sets_utc_date_from_carbon()
{
config()->set('app.timezone', 'America/New_York'); // -05:00
date_default_timezone_set('America/New_York');
$model = new EntryModel;
$model->id = 1;
$model->site = 'en';
$model->published = true;
$model->collection = 'blog';
$model->date = Carbon::parse('2025-01-01 12:11:10', 'UTC');
$model->data = [];
$model->save();
$this->assertDatabaseHas('entries', [
'id' => 1,
'date' => '2025-01-01 12:11:10',
]);
}
#[Test]
public function it_sets_non_utc_date_from_carbon()
{
config()->set('app.timezone', 'America/New_York'); // -05:00
date_default_timezone_set('America/New_York');
$model = new EntryModel;
$model->id = 1;
$model->site = 'en';
$model->published = true;
$model->collection = 'blog';
$model->date = Carbon::parse('2025-01-01 12:11:10');
$model->data = [];
$model->save();
$this->assertDatabaseHas('entries', [
'id' => 1,
'date' => '2025-01-01 17:11:10',
]);
}
}