Skip to content

Commit a1eae95

Browse files
committed
Added layout attribute casting test
1 parent 2a5a904 commit a1eae95

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

tests/Fixtures/CustomLayout.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,14 @@ class CustomLayout extends Layout
1919
* @var null|int
2020
**/
2121
protected $limit = 1;
22+
23+
/**
24+
* The attributes that should be cast.
25+
*
26+
* @var array
27+
*/
28+
protected $casts = [
29+
'test' => 'array',
30+
'birthday' => 'date',
31+
];
2232
}

tests/Unit/LayoutManipulationTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Tests\Unit;
44

5+
use Carbon\Carbon;
6+
use Tests\Fixtures\CustomLayout;
57
use Whitecube\LaravelFlexibleContent\Layout;
68

79
it('can generate random uuid as layout ID and keep layout key', function() {
@@ -49,6 +51,16 @@
4951
expect($layout['something'])->toBeNull();
5052
});
5153

54+
it('can cast layout attributes', function() {
55+
$layout = (new CustomLayout())->make(null, [
56+
'test' => json_encode(['foo' => 'bar']),
57+
'birthday' => '1993-03-16'
58+
]);
59+
60+
expect($layout->test)->toBeArray();
61+
expect($layout->birthday)->toBeInstanceOf(Carbon::class);
62+
});
63+
5264
it('can convert layout attributes to array', function() {
5365
$layout = (new Layout())->key('foo')->make(null, ['test' => true, 'something' => false]);
5466

0 commit comments

Comments
 (0)