Skip to content

Commit

Permalink
Merge pull request #49 from bopoda/master_issue13
Browse files Browse the repository at this point in the history
Add test cases according to Google robots.txt tester
  • Loading branch information
bopoda authored Apr 8, 2017
2 parents 9c16861 + 7675b68 commit e6b0b21
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<file>tests/TyposDirectiveTest.php</file>
<file>tests/t1gorTest.php</file>
<file>tests/MultipleUserAgentsRulesTest.php</file>
<file>tests/Issue13Test.php</file>
</testsuite>
</testsuites>
</phpunit>
60 changes: 60 additions & 0 deletions tests/Issue13Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

<?php

class Issue13Test extends \PHPUnit\Framework\TestCase
{
/**
* Load library
*/
public static function setUpBeforeClass()
{
require_once(realpath(__DIR__.'/../RobotsTxtParser.php'));
require_once(realpath(__DIR__.'/../RobotsTxtValidator.php'));
}

public function testIsUrlAllow1()
{
$robotsTxtContentIssue = "
User-agent: *
Allow: /anyfolder #length 10 exactly
Disallow: /*.html #length 2 or 7?
";

$parserRobotsTxt = new RobotsTxtParser($robotsTxtContentIssue);
$rulesRobotsTxt = $parserRobotsTxt->getRules();
$robotsTxtValidator = new RobotsTxtValidator($rulesRobotsTxt);

#length 10 is more significant
$this->assertTrue($robotsTxtValidator->isUrlAllow('/anyfolder.html'));
}

public function testIsUrlAllow2()
{
$robotsTxtContentIssue = "
User-agent: *
Allow: /any #length 4 exactly
Disallow: /*.html #length 2 or 7?
";
$parserRobotsTxt = new RobotsTxtParser($robotsTxtContentIssue);
$rulesRobotsTxt = $parserRobotsTxt->getRules();
$robotsTxtValidator = new RobotsTxtValidator($rulesRobotsTxt);

# it is not allowed according to google, so here length 7.
$this->assertFalse($robotsTxtValidator->isUrlAllow('/anyfolder.html'));
}

public function testIsUrlAllow3()
{
$robotsTxtContentIssue = "
User-agent: *
Allow: /any #length 4
Disallow: /any* #length 5
";
$parserRobotsTxt = new RobotsTxtParser($robotsTxtContentIssue);
$rulesRobotsTxt = $parserRobotsTxt->getRules();
$robotsTxtValidator = new RobotsTxtValidator($rulesRobotsTxt);

#disallowed because disallow length is longer (5 vs 4)
$this->assertFalse($robotsTxtValidator->isUrlAllow('/any'));
}
}

0 comments on commit e6b0b21

Please sign in to comment.