From d46433c10eecac25b1ecc9de42b5a4d78b18db7a Mon Sep 17 00:00:00 2001 From: Phuong Vu Date: Wed, 21 Feb 2024 22:35:38 +0700 Subject: [PATCH 1/2] set custom favicon value & render --- resources/views/components/extensions/favicon.blade.php | 8 ++++++-- src/SEOManager.php | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/resources/views/components/extensions/favicon.blade.php b/resources/views/components/extensions/favicon.blade.php index bafadca..01e850b 100644 --- a/resources/views/components/extensions/favicon.blade.php +++ b/resources/views/components/extensions/favicon.blade.php @@ -1,2 +1,6 @@ - - +@if ($favicon = seo('favicon')) + +@else + + +@endif diff --git a/src/SEOManager.php b/src/SEOManager.php index 9e5b9ad..c93cc29 100644 --- a/src/SEOManager.php +++ b/src/SEOManager.php @@ -216,9 +216,13 @@ public function previewify(string $alias, int|string|array $data = null): string } /** Enable favicon extension. */ - public function favicon(): static + public function favicon(string|bool $value = true): static { - $this->extensions['favicon'] = true; + if (is_string($value) && !empty($value)) { + $this->set('favicon', $value); + } + + $this->extensions['favicon'] = !!$value; return $this; } From be53cea4335b3c02520db5d9d163357633ff0fb4 Mon Sep 17 00:00:00 2001 From: Phuong Vu Date: Wed, 21 Feb 2024 23:12:13 +0700 Subject: [PATCH 2/2] add test --- tests/Pest/FaviconTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Pest/FaviconTest.php b/tests/Pest/FaviconTest.php index 2c9ca40..98e23e2 100644 --- a/tests/Pest/FaviconTest.php +++ b/tests/Pest/FaviconTest.php @@ -41,3 +41,28 @@ assertFileDoesNotExist(public_path('favicon.ico')); assertFileDoesNotExist(public_path('favicon.png')); }); + +test('it should have custom value with non-empty string', function () { + seo()->favicon('foo'); + + expect(seo('favicon'))->toBe('foo'); + expect(meta())->toContain(''); +}); + +test('it should not have custom value with empty string or false', function () { + seo()->favicon(''); + + expect(seo('favicon'))->toBe(null); + expect(meta())->not()->toContain('link rel="icon"'); + + expect(seo('favicon'))->toBe(null); + expect(meta())->not()->toContain('link rel="icon"'); +}); + +test('it should have default favicon setup', function () { + seo()->favicon(); + expect(seo('favicon'))->toBe(null); + + expect(meta())->toContain(''); + expect(meta())->toContain(''); +}); \ No newline at end of file