* @license BSD
*/
namespace Domframework\Tests;
use Domframework\Sitemap;
/** 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(
'
http://example.com/
2006-11-18
daily
0.8
',
"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(
'
http://www.example.com/sitemap1.xml.gz
2004-10-01T18:23:17+00:00
http://www.example.com/sitemap2.xml.gz
2005-01-01
',
"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, ],
]]
);
}
}