-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
2 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
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
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,74 @@ | ||
<?php | ||
|
||
namespace Leeto\MoonShine\Tests\Fields; | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Leeto\MoonShine\Fields\Date; | ||
use Leeto\MoonShine\Models\MoonshineUser; | ||
use Leeto\MoonShine\Resources\MoonShineUserResource; | ||
use Leeto\MoonShine\Tests\TestCase; | ||
|
||
class DateTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public function test_values() | ||
{ | ||
$user = MoonshineUser::factory()->make([ | ||
'created_at' => '2022-01-01 00:00:00' | ||
]); | ||
|
||
$field = Date::make('Created at') | ||
->format('d.m.Y'); | ||
|
||
$this->assertEquals('2022-01-01', $field->formViewValue($user)); | ||
$this->assertEquals('01.01.2022', $field->indexViewValue($user)); | ||
} | ||
|
||
public function test_nullable() | ||
{ | ||
$user = new MoonshineUser(); | ||
|
||
$field = Date::make('Created at') | ||
->nullable(); | ||
|
||
$this->assertEquals('', $field->formViewValue($user)); | ||
$this->assertEquals('', $field->indexViewValue($user)); | ||
} | ||
|
||
public function test_default() | ||
{ | ||
$user = new MoonshineUser(); | ||
|
||
$field = Date::make('Created at') | ||
->default('2022-01-02'); | ||
|
||
$this->assertEquals('2022-01-02', $field->formViewValue($user)); | ||
|
||
$field = Date::make('Created at') | ||
->nullable() | ||
->default('2022-01-02'); | ||
|
||
$this->assertEquals('2022-01-02', $field->formViewValue($user)); | ||
} | ||
|
||
public function test_save() | ||
{ | ||
$user = new MoonshineUser(); | ||
|
||
$field = Date::make('Created at') | ||
->default('2022-01-02'); | ||
|
||
$item = $field->save($user); | ||
|
||
$this->assertEquals('2022-01-02', $item->created_at->format('Y-m-d')); | ||
|
||
$field = Date::make('Created at') | ||
->nullable(); | ||
|
||
$item = $field->save($user); | ||
|
||
$this->assertNull($item->created_at); | ||
|
||
} | ||
} |