Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Only check on description meta tag because Google uses only that tag #57

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/Checks/Meta/DescriptionCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,11 @@ public function check(Response $response, Crawler $crawler): bool

public function getDescriptionContent(Crawler $crawler): ?string
{
$tags = ['description', 'og:description', 'twitter:description'];
/** @var \DOMElement $node */
$node = $crawler->filterXPath('//meta[@name="description"]')->getNode(0);

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');
}
if ($node instanceof \DOMElement && $node->hasAttribute('content')) {
return $node->getAttribute('content');
}

return null;
Expand Down
26 changes: 0 additions & 26 deletions tests/Checks/Meta/DescriptionCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<html><head><meta property="og:description" content="Vormkracht10 is a web development agency based in Amsterdam."></head><body></body></html>', 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('<html><head><meta name="twitter:description" content="Vormkracht10 is a web development agency based in Amsterdam."></head><body></body></html>', 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();
Expand Down