Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 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'));
 }
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
0
 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();
 }