예제 #1
0
파일: Rules.php 프로젝트: bee4/robots.txt
 /**
  * Add a new rule to the collection
  * @param Rule $rule
  * @return Rules
  */
 public function add(Rule $rule)
 {
     $userAgent = $this->handleUa($rule->getUserAgent());
     if (isset($this->collection[$userAgent]) && $this->collection[$userAgent] !== $this->defaultRule) {
         throw (new DuplicateRuleException('You can\'t add 2 rules for the same UserAgent'))->setRule($rule);
     }
     $this->collection[$userAgent] = $rule;
     return $this;
 }
예제 #2
0
 public function testPatternSetAndMatch()
 {
     $object = new Rule();
     $object->disallow('/section*');
     $this->assertFalse($object->match('/section/tout/cetuqiadjoa.jpg'));
     $object->allow('/toto*.php$');
     $this->assertTrue($object->match('/toto/tata.PHP'));
     $this->assertTrue($object->match('/toto/tata.php'));
     $object->allow('/truite');
     $this->assertTrue($object->match('/truite/et/tout/cetuqiadjoa.jpg'));
     $object->disallow('/');
     $this->assertFalse($object->match('/to/tata.php'));
 }
예제 #3
0
파일: Rule.php 프로젝트: bee4/robots.txt
 public function testMultipleExpression()
 {
     $this->given($sut = new SUT(''), $sut->disallow('/foo/bar'), $sut->allow('/foo/bar/baz$'), $sut->allow('/foo$'))->when($match = $sut->match('/foo/bar'))->then->boolean($match)->isFalse()->when($match = $sut->match('/foo/bar/baz/'))->then->boolean($match)->isFalse()->when($match = $sut->match('/foo/bar/baz'))->then->boolean($match)->isTrue();
 }
예제 #4
0
파일: Rules.php 프로젝트: bee4/robots.txt
 public function testAddRule()
 {
     $this->given($sut = new SUT(), $ua = 'Google-Bot', $rule = new LUT\Rule($ua), $rule->allow('/url'), $rule->disallow('/private'))->when($sut->add($rule), $get = $sut->get($ua))->then->integer(count($sut))->isEqualTo(2)->object($get)->isInstanceOf('Bee4\\RobotsTxt\\Rule')->isEqualTo($rule)->boolean($sut->match($ua, '/url'))->isTrue()->boolean($sut->match($ua, '/private'))->isFalse();
 }