-
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.
- Loading branch information
Showing
8 changed files
with
90 additions
and
12 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,20 @@ | ||
<?php | ||
|
||
namespace markhuot\keystone\base; | ||
|
||
class ContextBag | ||
{ | ||
public function __construct( | ||
protected array $context | ||
) { } | ||
|
||
public function __isset($key) | ||
{ | ||
return true; | ||
} | ||
|
||
public function __get($key) | ||
{ | ||
return $this->context[$key] ?? null; | ||
} | ||
} |
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
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,43 @@ | ||
<?php | ||
|
||
use markhuot\keystone\models\Component; | ||
|
||
use function markhuot\craftpest\helpers\test\dd; | ||
|
||
it('saves type', function () { | ||
$component = Component::factory()->type('site/components/with-context')->create(); | ||
$component->refresh(); | ||
|
||
expect($component->data->type)->toBe('site/components/with-context'); | ||
}); | ||
|
||
it('renders context', function () { | ||
$component = Component::factory()->type('site/components/with-context')->create(); | ||
$response = $component->setContext(['foo' => 'bar'])->render(); | ||
|
||
expect($response)->toBe('bar'); | ||
}); | ||
|
||
it('renders collections with context', function () { | ||
$fragment = Component::factory()->type('keystone/fragment')->create(); | ||
Component::factory()->type('site/components/with-context')->path($fragment->id)->create(); | ||
|
||
$response = $fragment->getSlot()->render(['foo' => 'bar']); | ||
expect(trim((string) $response))->toBe('bar'); | ||
}); | ||
|
||
it('renders object templates from context', function () { | ||
$text = Component::factory()->type('keystone/text')->create(); | ||
$text->data->merge(['text' => '{foo}'])->save(); | ||
|
||
expect(trim(strip_tags($text->setContext(['foo' => 'bar'])->render())))->toBe('bar'); | ||
}); | ||
|
||
it('renders object templates from slot context', function () { | ||
$fragment = Component::factory()->type('keystone/fragment')->create(); | ||
$text = Component::factory()->type('keystone/text')->path($fragment->id)->create(); | ||
$text->data->merge(['text' => '{foo}'])->save(); | ||
|
||
$response = $fragment->getSlot()->render(['foo' => 'bar']); | ||
expect(trim(strip_tags((string) $response)))->toBe('bar'); | ||
}); |
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 @@ | ||
{{ component.getContext().foo }} |