Skip to content

Commit d6897d7

Browse files
author
Tom
committed
Merge pull request #6 from waknauss-kingdom/feature/isdisallowed
added isDisallowed Method and Tests
2 parents dbac851 + 96337ef commit d6897d7

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Robot/RobotsTxt.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,15 @@ public function isAllowed($userAgent, $path)
5353
$urlParts = array_filter(explode('/', $path));
5454
return $this->tree->allowed(strtolower($userAgent), $urlParts) !== false;
5555
}
56-
}
56+
57+
/**
58+
* Is the given user agent disallowed access to the given resource?
59+
* @param string $userAgent The user agent to check
60+
* @param string $path The path of the url
61+
* @return bool|null
62+
*/
63+
public function isDisallowed($userAgent, $path)
64+
{
65+
return !$this->isAllowed($userAgent,$path);
66+
}
67+
}

tests/RobotTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ private static function getRobotsTxt($file)
2626
public function testBasicDisallow()
2727
{
2828
$this->assertFalse(self::getRobotsTxt('google')->isAllowed('robot', '/print'), 'robot cannot access /print');
29+
$this->assertTrue(self::getRobotsTxt('google')->isDisallowed('robot','/search'),'robot should not access /search');
2930
}
3031

3132
/**
@@ -34,6 +35,7 @@ public function testBasicDisallow()
3435
public function testBasicAllow()
3536
{
3637
$this->assertTrue(self::getRobotsTxt('google')->isAllowed('robot', '/m/finance'), 'robot can access /m/finance');
38+
$this->assertFalse(self::getRobotsTxt('google')->isDisallowed('robot','/m/finance'),'robot should be able to access /m/finance');
3739
}
3840

3941
/**
@@ -110,4 +112,4 @@ public function testFileWithInvalidLines()
110112
{
111113
$this->assertTrue(self::getRobotsTxt('corrupted')->isAllowed('Googlebot', '/some/other'));
112114
}
113-
}
115+
}

0 commit comments

Comments
 (0)