Skip to content

Commit 9df2a69

Browse files
committed
added isDisallowed Method and Tests
1 parent dbac851 commit 9df2a69

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/Robot/RobotsTxt.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,20 @@ public function isAllowed($userAgent, $path)
5353
$urlParts = array_filter(explode('/', $path));
5454
return $this->tree->allowed(strtolower($userAgent), $urlParts) !== false;
5555
}
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+
$status = $this->isAllowed($userAgent, $path);
66+
if ($status===true) {
67+
return false;
68+
}
69+
70+
return true;
71+
}
5672
}

tests/RobotTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ public function testBasicDisallow()
2828
$this->assertFalse(self::getRobotsTxt('google')->isAllowed('robot', '/print'), 'robot cannot access /print');
2929
}
3030

31+
/**
32+
* Test that we are not allowed to access a resource which is forbidden using the isDisallowed method
33+
*/
34+
public function testBasicDisallow_Disallowed_method()
35+
{
36+
$this->assertTrue(self::getRobotsTxt('google')->isDisallowed('robot','/search'),'robot should not access /search');
37+
}
38+
39+
/**
40+
* Test that we are allowed to access a given resource using the isDisallowed method
41+
*/
42+
public function testBasicIsDisallowed_returning_false()
43+
{
44+
$this->assertFalse(self::getRobotsTxt('google')->isDisallowed('robot','/m/finance'),'robot should be able to access /m/finance');
45+
}
46+
3147
/**
3248
* Test we are allowed to access a resource with Allow:
3349
*/

0 commit comments

Comments
 (0)