Add sitemap support
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5355 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
92
Tests/sitemapTest.php
Normal file
92
Tests/sitemapTest.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/** Test the sitemap.php file
|
||||
*/
|
||||
class test_sitemap 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, ],
|
||||
]]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user