Skip to content

Commit

Permalink
Fix edge case augmentation to string issues (#335)
Browse files Browse the repository at this point in the history
* Add test coverage for parsing antlers syntax in cascade.

* We should only need the raw values here (this stuff is under test).

* Ignore phpunit cache.
  • Loading branch information
jesseleite authored May 24, 2024
1 parent 8ce1a72 commit 740033f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
composer.lock
/vendor
.phpunit.result.cache
.phpunit.cache
8 changes: 4 additions & 4 deletions src/Cascade.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ protected function parse($key, $item)
: $item;

// If they have antlers in the string, they are on their own.
if (is_string($raw) && Str::contains($item, '{{')) {
return $this->parseAntlers($item);
if (is_string($raw) && Str::contains($raw, '{{')) {
return $this->parseAntlers($raw);
}

// For source-based strings, we should get the value from the source.
if (is_string($raw) && Str::startsWith($item, '@seo:')) {
$field = explode('@seo:', $item)[1];
if (is_string($raw) && Str::startsWith($raw, '@seo:')) {
$field = explode('@seo:', $raw)[1];

if (Str::contains($field, '/')) {
$field = explode('/', $field)[1];
Expand Down
18 changes: 18 additions & 0 deletions tests/CascadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ public function it_generates_compiled_title_from_cascaded_parts()
$this->assertEquals('Cool Writings >>> Jamaica', $data['compiled_title']);
}

/** @test */
public function it_parses_antlers()
{
$entry = Entry::findByUri('/about')->entry();

$entry->data(['favourite_colour' => 'Red'])->save();

$data = (new Cascade)
->with(SiteDefaults::load()->all())
->with([
'description' => '{{ favourite_colour | upper }}',
])
->withCurrent($entry)
->get();

$this->assertEquals('RED', $data['description']);
}

/** @test */
public function it_parses_field_references()
{
Expand Down

0 comments on commit 740033f

Please sign in to comment.