Files
DomFramework/Tests/robotstxtTest.php

182 lines
4.9 KiB
PHP

<?php
/** Test the mrobotstxt.txt file
*/
class test_model extends PHPUnit_Framework_TestCase
{
// Empty Robots
public function test_Construct_1 ()
{
$robotstxt = new robotstxt ("");
$res = $robotstxt->allow ();
$this->assertSame ($res, ["/"]);
}
public function test_Construct_2 ()
{
$robotstxt = new robotstxt ("");
$res = $robotstxt->disallow ();
$this->assertSame ($res, array ());
}
public function test_Construct_3 ()
{
$robotstxt = new robotstxt ("");
$res = $robotstxt->sitemaps ();
$this->assertSame ($res, array ());
}
public function test_Construct_4 ()
{
$robotstxt = new robotstxt ("");
$res = $robotstxt->crawldelay ();
$this->assertSame ($res, 3);
}
// Allow
public function test_allow_1 ()
{
$robotstxt = new robotstxt (
"User-Agent: *\nDisallow:\n");
$res = $robotstxt->allow ();
$this->assertSame ($res, ["/"]);
}
public function test_allow_2 ()
{
$robotstxt = new robotstxt (
"User-Agent: *\nDisallow:\n\nUser-Agent: DomSearch\nDisallow:\n");
$res = $robotstxt->allow ();
$this->assertSame ($res, ["/"]);
}
public function test_allow_3 ()
{
$robotstxt = new robotstxt (
"User-Agent: DomSearch\nDisallow:\n\nUser-Agent: *\nDisallow:\n");
$res = $robotstxt->allow ();
$this->assertSame ($res, ["/"]);
}
public function test_allow_4 ()
{
$robotstxt = new robotstxt (
"User-Agent: DomSearch\n".
"User-Agent: User1\n".
"User-Agent: User2\n".
"Disallow:\n\n".
"User-Agent: *\n".
"Disallow: /\n");
$res = $robotstxt->allow ();
$this->assertSame ($res, ["/"]);
}
// Disallow
public function test_disallow_1 ()
{
$robotstxt = new robotstxt (
"User-Agent: *\nDisallow: /\n");
$res = $robotstxt->disallow ();
$this->assertSame ($res, ["/"]);
}
public function test_disallow_2 ()
{
$robotstxt = new robotstxt (
"User-Agent: *\nDisallow: /\n\nUser-Agent: DomSearch\nDisallow: /\n");
$res = $robotstxt->disallow ();
$this->assertSame ($res, ["/"]);
}
public function test_disallow_3 ()
{
$robotstxt = new robotstxt (
"User-Agent: DomSearch\nDisallow: /\n\nUser-Agent: *\nDisallow: /\n");
$res = $robotstxt->disallow ();
$this->assertSame ($res, ["/"]);
}
// Sitemaps
public function test_sitemaps_1 ()
{
$robotstxt = new robotstxt (
"User-Agent: DomSearch\nDisallow: /\n\nUser-Agent: *\nDisallow: /\n");
$res = $robotstxt->sitemaps ();
$this->assertSame ($res, []);
}
public function test_sitemaps_2 ()
{
$robotstxt = new robotstxt (
"User-Agent: *\nDisallow: /\nSitemap: http://example.com/sitemap.xml");
$res = $robotstxt->sitemaps ();
$this->assertSame ($res, ["http://example.com/sitemap.xml"]);
}
public function test_sitemaps_3 ()
{
$robotstxt = new robotstxt (
"User-Agent: *\nDisallow: /\n".
"Sitemap: http://example.com/sitemap.xml\n".
"Sitemap: http://example.com/SITEMAP.XML");
$res = $robotstxt->sitemaps ();
$this->assertSame ($res,
["http://example.com/sitemap.xml", "http://example.com/SITEMAP.XML"]);
}
// Host
public function test_host_1 ()
{
$robotstxt = new robotstxt (
"User-Agent: *\nDisallow: /\n");
$res = $robotstxt->host ();
$this->assertSame ($res, null);
}
public function test_host_2 ()
{
$robotstxt = new robotstxt (
"User-Agent: *\nDisallow: /\n\nHost: localhost");
$res = $robotstxt->host ();
$this->assertSame ($res, "localhost");
}
// URLAllow
public function test_urlallow_1 ()
{
$robotstxt = new robotstxt ("");
$res = $robotstxt->URLAllow ("/");
$this->assertSame ($res, true);
}
public function test_urlallow_2 ()
{
$robotstxt = new robotstxt (
"User-Agent: *\nDisallow: /");
$res = $robotstxt->URLAllow ("/");
$this->assertSame ($res, false);
}
public function test_urlallow_3 ()
{
$robotstxt = new robotstxt (
"User-Agent: *\nDisallow: /\nAllow: /allow/");
$res = $robotstxt->URLAllow ("/");
$this->assertSame ($res, false);
}
public function test_urlallow_4 ()
{
$robotstxt = new robotstxt (
"User-Agent: *\nDisallow: /\nAllow: /allow/");
$res = $robotstxt->URLAllow ("/allow/file");
$this->assertSame ($res, true);
}
public function test_urlallow_5 ()
{
$robotstxt = new robotstxt (
"User-Agent: *\nDisallow: /\nAllow: /allow/*.gif$");
$res = $robotstxt->URLAllow ("/allow/file.gif");
$this->assertSame ($res, true);
}
public function test_urlallow_6 ()
{
$robotstxt = new robotstxt (
"User-Agent: *\nDisallow: /\nAllow: /allow/*.gif$");
$res = $robotstxt->URLAllow ("/allow/.gif");
$this->assertSame ($res, false);
}
public function test_urlallow_7 ()
{
$robotstxt = new robotstxt (
"User-Agent: *\nDisallow: /\nAllow: /allow/*.gif\$");
$res = $robotstxt->URLAllow ("/allow/file.png");
$this->assertSame ($res, false);
}
}