folderweb/devel/tests/helpers/extract_meta_description.phpt

46 lines
1.4 KiB
Text
Raw Permalink Normal View History

--TEST--
extractMetaDescription: returns description from metadata fields or first content paragraph
--FILE--
<?php
require '/var/www/app/constants.php';
require '/var/www/app/hooks.php';
require '/var/www/app/content.php';
require '/var/www/app/helpers.php';
$dir = sys_get_temp_dir() . '/phpt_metadesc_' . getmypid();
mkdir($dir);
// search_description takes priority
echo extractMetaDescription($dir, ['search_description' => 'SEO description', 'summary' => 'Summary']) . "\n";
// summary is fallback when no search_description
echo extractMetaDescription($dir, ['summary' => 'Page summary']) . "\n";
// null metadata, no content files
echo (extractMetaDescription($dir, null) ?? 'null') . "\n";
// First paragraph from markdown (skips headings and short lines)
file_put_contents("$dir/index.md", "# Title\n\nThis is the opening paragraph of the post.\n\nSecond paragraph.");
echo extractMetaDescription($dir, null) . "\n";
unlink("$dir/index.md");
// Heading-only markdown with no usable paragraph
file_put_contents("$dir/index.md", "# Just a Heading\n\nShort.\n");
echo (extractMetaDescription($dir, null) ?? 'null') . "\n";
unlink("$dir/index.md");
// First <p> from HTML
file_put_contents("$dir/index.html", "<h1>Title</h1><p>HTML paragraph text here.</p>");
echo extractMetaDescription($dir, null) . "\n";
unlink("$dir/index.html");
rmdir($dir);
?>
--EXPECT--
SEO description
Page summary
null
This is the opening paragraph of the post.
null
HTML paragraph text here.