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);
 }
예제 #2
0
 /**
  * {@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;
 }