forked from statamic/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support rendering model attributes in Antlers
- Loading branch information
1 parent
5e637d7
commit 70d1358
Showing
2 changed files
with
61 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
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,44 @@ | ||
<?php | ||
|
||
namespace Tests\Antlers\Runtime; | ||
|
||
use Illuminate\Database\Eloquent\Casts\Attribute; | ||
use Illuminate\Support\Collection; | ||
use Mockery; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Statamic\Contracts\Query\Builder; | ||
use Statamic\Tags\Tags; | ||
use Statamic\View\Antlers\Language\Runtime\GlobalRuntimeState; | ||
use Statamic\View\Antlers\Language\Runtime\NodeProcessor; | ||
use Tests\Antlers\Fixtures\Addon\Modifiers\IsBuilder; | ||
use Tests\Antlers\Fixtures\Addon\Tags\VarTestTags as VarTest; | ||
use Tests\Antlers\ParserTestCase; | ||
|
||
class ModelTest extends ParserTestCase | ||
{ | ||
public function test_model_attributes_are_returned() | ||
{ | ||
$model = FakeModel::make(); | ||
$model->title = 'Title'; | ||
|
||
$data = [ | ||
'model' => $model, | ||
]; | ||
|
||
$template = <<<'EOT' | ||
{{ model:title }}{{ model:foo_bar }} | ||
EOT; | ||
|
||
$this->assertSame('TitleFooBar', $this->renderString($template, $data)); | ||
} | ||
} | ||
|
||
class FakeModel extends \Illuminate\Database\Eloquent\Model | ||
{ | ||
public function fooBar(): Attribute | ||
{ | ||
return Attribute::make( | ||
get: fn() => 'FooBar', | ||
); | ||
} | ||
} |