Seo.php
<?php
namespace Liaison\Test\Addon;
class Seo extends \Tlf\Tester {
/**
*
* @tests seo() method
*/
public function testSeoFromArray(){
$lia = new \Lia();
$package = new \Lia\Package($lia, 'test:idk');
$seo = new \Lia\Addon\Seo($package);
$seo->init_lia();
//@export_start(Usage.Seo)
$seo_data = [
'title' => 'Test Page',
'description' => 'Test description',
'image' => ['/path/to/image.jpg', 'alt text for image'],
'url' => '/canonical/url/',
'site_name' => 'Liaison test',
'keywords'=> 'abc,def,okay',
];
$lia->seo($seo_data);
$html = $lia->getSeoHtml();
//@export_end(Usage.Seo)
$aHtml = trim($html);
$tHtml =
//@export_start(Usage.Seo.Output)
<<<HTML
<title>Test Page</title>
<meta property="og:title" content="Test Page" />
<meta name="description" content="Test description" />
<meta property="og:description" content="Test description" />
<meta property="og:type" content="summary" />
<meta property="twitter:card" content="summary" />
<meta property="og:image" content="alt text for image" />
<meta property="twitter:image" content="/path/to/image.jpg" />
<meta property="og:image:alt" content="alt text for image" />
<link rel="canonical" href="/canonical/url/" />
<meta name="og:url" content="/canonical/url/" />
<meta name="og:site_name" content="Liaison test" />
<meta name="keywords" content="abc,def,okay" />
HTML;
//@export_end(Usage.Seo.Output)
$tHtml = explode("\n",$tHtml);
$tHtml = array_map('trim', $tHtml);
$tHtml = trim(implode("\n",$tHtml));
$this->compare($tHtml, $aHtml);
}
/**
*
* @tests liaison seo methods
* @tests seo html output
* @note if the underlying html changes, just copy+paste output from the test & copy it into the HTML HEREDOC
*/
public function testSeoLiaMethods(){
$lia = new \Lia();
$package = new \Lia\Package($lia, 'test:idk');
$seo = new \Lia\Addon\Seo($package);
$seo->init_lia();
//@export_start(Usage.Seo)
$lia->seoTitle('Test Page');
$lia->seoDescription('Test description');
$lia->seoImage('/path/to/image.jpg', 'alt text for image');
$lia->seoUrl('/canonical/url/');
$lia->seoSiteName('Liaison test');
$html = $lia->getSeoHtml();
//@export_end(Usage.Seo)
$aHtml = trim($html);
$tHtml =
//@export_start(Usage.Seo.Output)
<<<HTML
<title>Test Page</title>
<meta property="og:title" content="Test Page" />
<meta name="description" content="Test description" />
<meta property="og:description" content="Test description" />
<meta property="og:type" content="summary" />
<meta property="twitter:card" content="summary" />
<meta property="og:image" content="alt text for image" />
<meta property="twitter:image" content="/path/to/image.jpg" />
<meta property="og:image:alt" content="alt text for image" />
<link rel="canonical" href="/canonical/url/" />
<meta name="og:url" content="/canonical/url/" />
<meta name="og:site_name" content="Liaison test" />
HTML;
//@export_end(Usage.Seo.Output)
$tHtml = explode("\n",$tHtml);
$tHtml = array_map('trim', $tHtml);
$tHtml = trim(implode("\n",$tHtml));
$this->compare($tHtml, $aHtml);
}
}