File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments