-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from bopoda/master_issue13
Add test cases according to Google robots.txt tester
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
} | ||
} |