From 855cbd40722240d5e1c24629fae36b22e555bddf Mon Sep 17 00:00:00 2001 From: Baspa Date: Fri, 26 Jan 2024 13:48:03 +0100 Subject: [PATCH] Only check on description meta tag because Google uses only that tag --- src/Checks/Meta/DescriptionCheck.php | 18 +++++---------- tests/Checks/Meta/DescriptionCheckTest.php | 26 ---------------------- 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/src/Checks/Meta/DescriptionCheck.php b/src/Checks/Meta/DescriptionCheck.php index ac562e8..aac169d 100644 --- a/src/Checks/Meta/DescriptionCheck.php +++ b/src/Checks/Meta/DescriptionCheck.php @@ -44,19 +44,13 @@ public function check(Response $response, Crawler $crawler): bool public function getDescriptionContent(Crawler $crawler): ?string { - $tags = ['description', 'og:description', 'twitter:description']; - - foreach ($tags as $tag) { - $property = $tag === 'og:description' ? 'property' : 'name'; - - /** @var \DOMElement $node */ - $node = $crawler->filterXPath("//meta[@{$property}=\"{$tag}\"]")->getNode(0); - - if ($node instanceof \DOMElement && $node->hasAttribute('content')) { - return $node->getAttribute('content'); - } + /** @var \DOMElement $node */ + $node = $crawler->filterXPath("//meta[@name=\"description\"]")->getNode(0); + + if ($node instanceof \DOMElement && $node->hasAttribute('content')) { + return $node->getAttribute('content'); } - + return null; } diff --git a/tests/Checks/Meta/DescriptionCheckTest.php b/tests/Checks/Meta/DescriptionCheckTest.php index 311affa..2ff12c5 100644 --- a/tests/Checks/Meta/DescriptionCheckTest.php +++ b/tests/Checks/Meta/DescriptionCheckTest.php @@ -4,32 +4,6 @@ use Symfony\Component\DomCrawler\Crawler; use Vormkracht10\Seo\Checks\Meta\DescriptionCheck; -it('can perform the description check on a page with an og:description', function () { - $check = new DescriptionCheck(); - $crawler = new Crawler(); - - Http::fake([ - 'vormkracht10.nl' => Http::response('', 200), - ]); - - $crawler->addHtmlContent(Http::get('vormkracht10.nl')->body()); - - $this->assertTrue($check->check(Http::get('vormkracht10.nl'), $crawler)); -}); - -it('can perform the description check on a page with a twitter:description', function () { - $check = new DescriptionCheck(); - $crawler = new Crawler(); - - Http::fake([ - 'vormkracht10.nl' => Http::response('', 200), - ]); - - $crawler->addHtmlContent(Http::get('vormkracht10.nl')->body()); - - $this->assertTrue($check->check(Http::get('vormkracht10.nl'), $crawler)); -}); - it('can perform the description check on a page with multiple description tags', function () { $check = new DescriptionCheck(); $crawler = new Crawler();