-
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #535 from fritz-c/master
Fix: Ensure duplicateAndHydrate works with Fields using static closures
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Layouts; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Laravel\Nova\Fields\DateTime; | ||
use Laravel\Nova\Fields\Text; | ||
use Whitecube\NovaFlexibleContent\Layouts\Layout; | ||
|
||
class LayoutTest extends TestCase | ||
{ | ||
public function testDuplicateAndHydrate(): void | ||
{ | ||
$layout = new Layout('Test Layout', 'test', [ | ||
DateTime::make('Created At'), | ||
Text::make('Name', 'name', static function($resource, $attribute) { | ||
return 'static-name'; | ||
}), | ||
]); | ||
|
||
// Should not throw any exceptions | ||
$duplicate = $layout->duplicateAndHydrate('keylikegenerated', [ | ||
'created_at' => '2023-01-01 00:00:00', | ||
'name' => 'Test' | ||
]); | ||
|
||
$this->assertInstanceOf(Layout::class, $duplicate); | ||
$this->assertEquals('keylikegenerated', $duplicate->key()); | ||
$this->assertEquals('Test Layout', $duplicate->title()); | ||
$this->assertEquals('test', $duplicate->name()); | ||
|
||
// The text field should resolve the value | ||
$textField = $duplicate->fields()[1]; | ||
$textField->resolve(null); | ||
$this->assertEquals('static-name', $textField->value); | ||
} | ||
} |