File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed
Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -21,8 +21,8 @@ public function getMatches($userAgent)
2121 }
2222
2323 $ matches = array_filter ($ this ->userAgents , function ($ elem ) use ($ ua ) {
24- return strpos ($ elem , $ ua ) !== false || $ elem == '* ' ;
24+ return strpos ($ elem , $ ua ) !== false || strpos ( $ ua , $ elem ) !== false || $ elem == '* ' ;
2525 });
26- return $ matches ;
26+ return array_values ( $ matches) ;
2727 }
2828}
Original file line number Diff line number Diff line change @@ -36,4 +36,22 @@ public function givenUserAgentMatch_delegateToAccessRules()
3636 $ this ->assertFalse ((new Record ($ alwaysMatchingUserAgent , $ this ->fooForbidden ))->isAllowed ('Googlebot ' , '/foo ' ));
3737 $ this ->assertTrue ((new Record ($ alwaysMatchingUserAgent , $ this ->allUrlsAllowed ))->isAllowed ('Googlebot ' , '/foo ' ));
3838 }
39+
40+ /**
41+ * @test
42+ */
43+ public function givenNoMatches_returnMatchStrengthOfZero ()
44+ {
45+ $ googleOnly = new Record (new UserAgent (['Googlebot ' ]), new AccessRules ([]));
46+ $ this ->assertTrue ($ googleOnly ->getMatchStrength ('Bing ' ) == 0 , 'No match at all means a match strength of zero ' );
47+ }
48+
49+ /**
50+ * @test
51+ */
52+ public function givenMatch_returnLengthOfMatchedUAAsMatchStrength ()
53+ {
54+ $ googleOnly = new Record (new UserAgent (['Googlebot ' ]), new AccessRules ([]));
55+ $ this ->assertTrue ($ googleOnly ->getMatchStrength ('G ' ) == 9 , 'Length of the matched UA is the strength ' );
56+ }
3957}
Original file line number Diff line number Diff line change @@ -93,4 +93,17 @@ public function givenWildcardAgent_alwaysMatch()
9393 $ this ->assertTrue ($ wildcard ->getMatches ($ ua ) == ['* ' ], 'wilcard matches all ' );
9494 }
9595 }
96+
97+ /**
98+ * @test
99+ * https://developers.google.com/webmasters/control-crawl-index/docs/robots_txt#order-of-precedence-for-user-agents
100+ */
101+ public function givenGoogleExamples_behaveAsExpected ()
102+ {
103+ $ googleUAs = new UserAgent (['googlebot-news ' , '* ' , 'googlebot ' ]);
104+ $ this ->assertContains ('googlebot-news ' , $ googleUAs ->getMatches ('Googlebot-News ' ));
105+ $ this ->assertContains ('googlebot ' , $ googleUAs ->getMatches ('Googlebot-Images ' ));
106+ $ this ->assertNotContains ('googlebot-news ' , $ googleUAs ->getMatches ('Googlebot-Images ' ));
107+ $ this ->assertEquals (['* ' ], $ googleUAs ->getMatches ('otherbot ' ));
108+ }
96109}
You can’t perform that action at this time.
0 commit comments