From ab1e01b066cc20832fd7ca51ec01da427e84b9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Mon, 24 May 2021 19:24:22 +0200 Subject: [PATCH] Make flipp use raw values --- src/SEOManager.php | 14 ++++++++++++-- tests/Pest/FlippTest.php | 13 ++++++++++++- tests/Pest/ModifierTest.php | 9 +++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/SEOManager.php b/src/SEOManager.php index 9331111..22a2876 100644 --- a/src/SEOManager.php +++ b/src/SEOManager.php @@ -109,6 +109,16 @@ class SEOManager )); } + /** Get a value without modifications. */ + public function raw(string $key): string|null + { + return isset($this->values[$key]) + ? value($this->values[$key]) + : value($this->defaults[$key] ?? ( + Str::contains($key, '.') ? $this->get(Str::after($key, '.')) : null + )); + } + /** Configure an extension. */ public function extension(string $name, bool $enabled = true, string $view = null): static { @@ -144,8 +154,8 @@ class SEOManager if ($data === null) { $data = [ - 'title' => $this->title, - 'description' => $this->description, + 'title' => $this->raw('title'), + 'description' => $this->raw('description'), ]; } diff --git a/tests/Pest/FlippTest.php b/tests/Pest/FlippTest.php index 6392ac5..b440540 100644 --- a/tests/Pest/FlippTest.php +++ b/tests/Pest/FlippTest.php @@ -27,7 +27,7 @@ test('the flipp method returns a link to a signed url', function () { seo()->flipp('blog', 'abcdefg'); expect(seo()->flipp('blog', ['title' => 'abc'])) - ->toContain('?s=' . hash_hmac('sha256', 'blog' . base64_encode(json_encode(['title' => 'abc'])), config('services.flipp.key'))); + ->toContain('?s=' . hash_hmac('sha256', 'abcdefg' . base64_encode(json_encode(['title' => 'abc'])), config('services.flipp.key'))); }); test("flipp templates use default data when they're not passed any data explicitly", function () { @@ -57,3 +57,14 @@ test('the blade directive can be used with flipp', function () { expect(blade("@seo('flipp', 'blog')"))->toBe(seo()->flipp('blog')); expect(blade("@seo('flipp', 'blog', ['title' => 'abc'])"))->toBe(seo()->flipp('blog', ['title' => 'abc'])); }); + +test('flipp uses the raw title and description', function () { + seo()->flipp('blog', 'abcdefg'); + + seo()->title(modify: fn (string $title) => $title . ' - modified'); + seo()->title('foo')->description('bar'); + + expect(seo()->flipp('blog')) + ->toContain('s.useflipp.com/abcdefg') + ->toContain(base64_encode(json_encode(['title' => 'foo', 'description' => 'bar']))); +}); diff --git a/tests/Pest/ModifierTest.php b/tests/Pest/ModifierTest.php index 9ae3477..b293563 100644 --- a/tests/Pest/ModifierTest.php +++ b/tests/Pest/ModifierTest.php @@ -19,3 +19,12 @@ test('modifiers are not applied on default values', function () { expect(seo('title'))->toBe('ArchTech — Web development agency'); }); + +test('modifiers can be bypassed by using the raw method', function () { + seo()->title(modify: fn (string $title) => $title . ' | ArchTech'); + + seo()->title('About us'); + + expect(seo()->get('title'))->toBe('About us | ArchTech'); + expect(seo()->raw('title'))->toBe('About us'); +});