function it_handle_handlers(HandlerInterface $handler, RuleInterface $rule) { $configuration = array(); $this->addHandler($handler); $handler->handle(Argument::exact($configuration), Argument::exact($rule->getWrappedObject()))->shouldBeCalled(); $this->handle($configuration, $rule); }
function it_visit_token(MatcherInterface $matcher, TokenInterface $token, CollatorInterface $collator, MatcherInterface $matcher, MergingStrategyInterface $mergingStrategy, RuleInterface $rule) { $this->beConstructedWith($matcher, $mergingStrategy); $rules = new \ArrayIterator(array($rule->getWrappedObject())); $matcher->match(Argument::exact($token->getWrappedObject()))->shouldBeCalledTimes(1)->willReturn($rules); $mergingStrategy->merge(Argument::exact($rules), Argument::exact($collator->getWrappedObject()))->shouldBeCalledTimes(1); $this->visit($token, $collator)->shouldReturn(VisitorInterface::STATE_SEEKING); }
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); }
/** * @param array $configuration * @param RuleInterface $rule */ private function handleConditions(array $configuration, RuleInterface $rule) { foreach ($configuration['conditions'] as $position => $conditionConfiguration) { $condition = new Condition(); $condition->setType($conditionConfiguration['type']); $condition->setValue($conditionConfiguration['value']); $condition->setStrategy(isset($conditionConfiguration['strategy']) ? $conditionConfiguration['strategy'] : ConditionInterface::STRATEGY_NEXT); $condition->setPosition($position); $condition->setDynamicCapabilities(isset($conditionConfiguration['capabilities']) ? $conditionConfiguration['capabilities'] : array()); $rule->addCondition($condition); } }
function it_return_negative_analyse_occurrences(IncrementationInterface $incrementation, DynamicCapabilitiesProcessorInterface $dynamicCapabilitiesProcessor, OccurrencesInterface $occurences, OccurrenceInterface $occurence1, OccurrenceInterface $occurence2, RuleInterface $rule) { $this->beConstructedWith($incrementation, $dynamicCapabilitiesProcessor); $rule->getConditions()->shouldBeCalled()->willReturn(array(1, 2, 3)); $occurence1->getRule()->shouldBeCalled()->willReturn($rule); $occurence2->getRule()->shouldBeCalled()->willReturn($rule); $dynamicCapabilitiesProcessor->process(Argument::exact($occurence1->getWrappedObject()))->shouldBeCalled(); $dynamicCapabilitiesProcessor->process(Argument::exact($occurence2->getWrappedObject()))->shouldBeCalled(); $occurencesIterator = array($occurence1, $occurence2); $occurences->getFirstOccurrences()->shouldBeCalled()->willReturn($occurencesIterator); $occurences->getNext(Argument::exact($occurence1->getWrappedObject()))->shouldBeCalled()->willReturn($occurence2); $occurences->getNext(Argument::exact($occurence2->getWrappedObject()))->shouldBeCalled()->willReturn(false); $incrementation->oughtToBeIncrement($occurence2->getWrappedObject(), $occurence1->getWrappedObject())->shouldBeCalled()->willReturn(true); $results = $this->analyse($occurences); $results->shouldBeAnInstanceOf('\\Iterator'); $results->shouldHaveCount(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; }
function it_handle_configuration(RuleInterface $rule) { $configuration = array('priority' => 1, 'category' => 'browser', 'capabilities' => array('is_bot' => true), 'conditions' => array(array('type' => 'text', 'value' => 'chrome', 'strategy' => 'sequence', 'capabilities' => array('is_modile' => true)))); $rule->setPriority(Argument::exact($configuration['priority']))->shouldBeCalled(); $rule->setCategory(Argument::exact($configuration['category']))->shouldBeCalled(); $rule->setCapabilities(Argument::exact($configuration['capabilities']))->shouldBeCalled(); $rule->addCondition(Argument::type('DeviceDetectorIO\\DeviceDetector\\Rule\\Condition\\ConditionInterface'))->shouldBeCalled(); $this->handle($configuration, $rule); }