-
-
Notifications
You must be signed in to change notification settings - Fork 554
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for some of the date modifiers
- Loading branch information
1 parent
4445e8c
commit b99c96d
Showing
5 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Tests\Modifiers; | ||
|
||
use Illuminate\Support\Carbon; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Statamic\Modifiers\Modify; | ||
use Tests\TestCase; | ||
|
||
class FormatTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
config()->set('statamic.system.display_timezone', 'Europe/Berlin'); // +1 hour | ||
} | ||
|
||
#[Test] | ||
public function it_formats_date() | ||
{ | ||
$this->assertSame('1st January 2025 3:45pm', $this->modify(Carbon::parse('2025-01-01 15:45'), 'jS F Y g:ia')); | ||
} | ||
|
||
public function modify($value, $format) | ||
{ | ||
return Modify::value($value)->format($format)->fetch(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Tests\Modifiers; | ||
|
||
use Illuminate\Support\Carbon; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Statamic\Modifiers\Modify; | ||
use Tests\TestCase; | ||
|
||
class FormatTranslatedTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Carbon::setLocale('de'); | ||
|
||
config()->set('statamic.system.display_timezone', 'Europe/Berlin'); // +1 hour | ||
} | ||
|
||
#[Test] | ||
public function it_formats_date() | ||
{ | ||
$this->assertSame('Mittwoch 1 Januar 2025, 15:45', $this->modify(Carbon::parse('2025-01-01 15:45'), 'l j F Y, H:i')); | ||
} | ||
|
||
public function modify($value, $format) | ||
{ | ||
return Modify::value($value)->formatTranslated($format)->fetch(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Tests\Modifiers; | ||
|
||
use Illuminate\Support\Carbon; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Statamic\Modifiers\Modify; | ||
use Tests\TestCase; | ||
|
||
class IsoFormatTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
config()->set('statamic.system.display_timezone', 'Europe/Berlin'); // +1 hour | ||
} | ||
|
||
#[Test] | ||
public function it_formats_date() | ||
{ | ||
$this->assertSame('2025.01.01 15:45', $this->modify(Carbon::parse('2025-01-01 15:45'), 'YYYY.MM.DD HH:mm')); | ||
} | ||
|
||
public function modify($value, $format) | ||
{ | ||
return Modify::value($value)->isoFormat($format)->fetch(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Tests\Modifiers; | ||
|
||
use Illuminate\Support\Carbon; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Statamic\Modifiers\Modify; | ||
use Tests\TestCase; | ||
|
||
class ModifyDateTest extends TestCase | ||
{ | ||
#[Test] | ||
public function it_modifies_date() | ||
{ | ||
$this->assertEquals($this->modify(Carbon::parse('2025-01-01'), '+2 months')->format('Y-m-d'), '2025-03-01'); | ||
} | ||
|
||
public function modify($value, $modify) | ||
{ | ||
return Modify::value($value)->modifyDate($modify)->fetch(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Tests\Modifiers; | ||
|
||
use Illuminate\Support\Carbon; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Statamic\Modifiers\Modify; | ||
use Tests\TestCase; | ||
|
||
class TimezoneTest extends TestCase | ||
{ | ||
#[Test] | ||
public function it_converts_date_into_timezone() | ||
{ | ||
$this->assertEquals( | ||
$this->modify(Carbon::parse('2025-01-01 15:45'), 'Europe/Berlin')->format('Y-m-d H:i'), | ||
'2025-01-01 16:45' | ||
); | ||
} | ||
|
||
public function modify($value, $timezone) | ||
{ | ||
return Modify::value($value)->timezone($timezone)->fetch(); | ||
} | ||
} |