Example #1
0
 /**
  * {@inheritdoc}
  */
 public function resolve(ConditionInterface $condition)
 {
     if (!isset($this->evaluators[$condition->getType()])) {
         throw new EvaluatorNotFoundException(sprintf('Evaluator for "%s" type not found.', $condition->getType()));
     }
     return $this->evaluators[$condition->getType()];
 }
 function it_return_false_of_regexp_does_not_match(UserAgentToken $token, ConditionInterface $condition, RuleInterface $rule)
 {
     $token->__toString()->willReturn('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.74 Safari/537.36 MRCHROME');
     $condition->getValue()->willReturn('#AppleWebKitt(?:/(?P<webkit_version>\\d+[\\.\\d]+))#is');
     $condition->getDynamicCapabilities()->shouldNotBeCalled()->willReturn(array('webkit_version'));
     $rule->getCapabilities()->willReturn(array('applewebkit' => true))->shouldNotBeCalled();
     $rule->setCapabilities(Argument::exact(array('applewebkit' => true, 'webkit_version' => '537.36')))->shouldNotBeCalled();
     $this->evaluate($token, $condition, $rule)->shouldReturn(false);
 }
 /**
  * {@inheritdoc}
  */
 public function areEquals(NodeInterface $node, ConditionInterface $condition)
 {
     if ($node->isType(NodeInterface::TYPE_SPACE) && $condition->isType(ConditionInterface::TYPE_SPACE)) {
         return true;
     }
     if ($condition->isType(ConditionInterface::TYPE_PLACEHOLDER)) {
         return true;
     }
     if ($node->isType(NodeInterface::TYPE_TEXT) && !$condition->isType(ConditionInterface::TYPE_TEXT)) {
         return false;
     }
     return $node->getValue() === $condition->getValue();
 }
 /**
  * {@inheritdoc}
  */
 public function evaluate(TokenInterface $token, ConditionInterface $condition, RuleInterface $rule)
 {
     $matches = array();
     if (preg_match($condition->getValue(), (string) $token, $matches)) {
         $dynamicCapabilitiesToMerge = array();
         $dynamicCapabilities = $condition->getDynamicCapabilities();
         if (!empty($dynamicCapabilities)) {
             foreach ($dynamicCapabilities as $matchKey) {
                 if (isset($matches[$matchKey])) {
                     $dynamicCapabilitiesToMerge[$matchKey] = $matches[$matchKey];
                 }
             }
         }
         $rule->setCapabilities(array_merge($dynamicCapabilitiesToMerge, $rule->getCapabilities()));
         return true;
     }
     return false;
 }
 function it_return_true_if_text_types_not_correspond(NodeInterface $node, ConditionInterface $condition)
 {
     $node->isType(Argument::exact(NodeInterface::TYPE_SPACE))->willReturn(false);
     $condition->isType(Argument::exact(ConditionInterface::TYPE_SPACE))->willReturn(false);
     $condition->isType(Argument::exact(ConditionInterface::TYPE_PLACEHOLDER))->willReturn(false);
     $node->isType(Argument::exact(NodeInterface::TYPE_TEXT))->willReturn(true)->shouldBeCalledTimes(1);
     $condition->isType(Argument::exact(ConditionInterface::TYPE_TEXT))->willReturn(true)->shouldBeCalledTimes(1);
     $node->getValue()->willReturn('value')->shouldBeCalledTimes(1);
     $condition->getValue()->willReturn('value')->shouldBeCalledTimes(1);
     $this->areEquals($node, $condition)->shouldReturn(true);
 }
Example #6
0
 /**
  * @param ConditionInterface $condition
  * @return bool
  */
 private function isIndexableRule(ConditionInterface $condition)
 {
     return $condition->isType(ConditionInterface::TYPE_TEXT) || $condition->isType(ConditionInterface::TYPE_PLACEHOLDER) || $condition->isType(ConditionInterface::TYPE_SPACE);
 }
 function it_return_false_of_stripos_does_not_match(UserAgentToken $token, ConditionInterface $condition, RuleInterface $rule)
 {
     $token->__toString()->willReturn('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.74 Safari/537.36 MRCHROME');
     $condition->getValue()->willReturn('AppleWebKit2');
     $this->evaluate($token, $condition, $rule)->shouldReturn(false);
 }
 /**
  * {@inheritdoc}
  */
 public function evaluate(TokenInterface $token, ConditionInterface $condition, RuleInterface $rule)
 {
     return false !== strpos((string) $token, $condition->getValue());
 }