From 740033f87523a998905fa17a07f2b04ea3cb8e90 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 24 May 2024 09:49:57 -0400 Subject: [PATCH] Fix edge case augmentation to string issues (#335) * 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. --- .gitignore | 1 + src/Cascade.php | 8 ++++---- tests/CascadeTest.php | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index ec9a1ddf..5afbaf36 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules composer.lock /vendor .phpunit.result.cache +.phpunit.cache diff --git a/src/Cascade.php b/src/Cascade.php index dd683978..a9e790d4 100644 --- a/src/Cascade.php +++ b/src/Cascade.php @@ -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]; diff --git a/tests/CascadeTest.php b/tests/CascadeTest.php index fdfe4f9e..92dabc5c 100644 --- a/tests/CascadeTest.php +++ b/tests/CascadeTest.php @@ -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() {