Files
DomFramework/Tests/sitemapTest.php

93 lines
2.7 KiB
PHP

<?php
/** Test the sitemap.php file
*/
class sitemapTest extends PHPUnit_Framework_TestCase
{
// Empty Sitemap
public function test_EmptySitemap_1 ()
{
$sitemap = new sitemap ();
$res = $sitemap->analyze ("", "http://example.com");
$this->assertSame ($res, ["urls" => [], "sitemaps" => []]);
}
// Empty Sitemap
public function test_EmptySitemap_2 ()
{
$sitemap = new sitemap ();
$res = $sitemap->analyze (" ", "http://example.com");
$this->assertSame ($res, ["urls" => [], "sitemaps" => []]);
}
// Textual Sitemap
public function test_TextualSitemap_1 ()
{
$sitemap = new sitemap ();
$res = $sitemap->analyze ("http://example.com", "http://example.com");
$this->assertSame ($res,
["urls" => ["http://example.com" => []],
"sitemaps" => []]);
}
public function test_TextualSitemap_2 ()
{
$sitemap = new sitemap ();
$res = $sitemap->analyze ("http://example.com\nhttps://www.example.com\n\n",
"http://example.com");
$this->assertSame ($res,
["urls" => ["http://example.com" => [], "https://www.example.com" => []],
"sitemaps" => []]);
}
// XML Sitemap
public function test_XMLSitemap_1 ()
{
$sitemap = new sitemap ();
$res = $sitemap->analyze (
'<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>http://example.com/</loc>
<lastmod>2006-11-18</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>',
"http://example.com");
$this->assertSame ($res,
["urls" => [
"http://example.com/" => ["changefreq" => "daily",
"priority" => 0.8,
"lastmod" => 1163808000]
],
"sitemaps" => []]);
}
public function test_XMLSitemap_2 ()
{
$sitemap = new sitemap ();
$res = $sitemap->analyze (
'<?xml version="1.0" encoding="utf-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>http://www.example.com/sitemap1.xml.gz</loc>
<lastmod>2004-10-01T18:23:17+00:00</lastmod>
</sitemap>
<sitemap>
<loc>http://www.example.com/sitemap2.xml.gz</loc>
<lastmod>2005-01-01</lastmod>
</sitemap>
</sitemapindex>',
"http://example.com");
$this->assertSame ($res,
["urls" => [],
"sitemaps" => [
"http://www.example.com/sitemap1.xml.gz" => [
"lastmod" => 1096654997,],
"http://www.example.com/sitemap2.xml.gz" => [
"lastmod" => 1104537600, ],
]]);
}
}