/** * Assert a filter only match the given event types * * @param EventFilter $filter * @param array $matchedTypes An array of matched event types */ protected function assertFilterMatch(EventFilter $filter, $matchedTypes) { foreach ($this->allEventTypes as $type) { $event = new Event($this->factory, $this->getNodeTypeManager()); $event->setType($type); $mustAccept = in_array($type, $matchedTypes); $message = sprintf("The filter with accepted types '%s' did not match the event type '%s'", $this->eventFilter->getEventTypes(), $type); $this->assertEquals($mustAccept, $filter->match($event), $message); } }
public function testFiltering() { $this->filter->setAbsPath('/something-not-matching'); $buffer = new TestBuffer($this->factory, $this->filter, $this->transport, $this->nodeTypeManager, 'http://localhost:8080/server/tests/jcr%3aroot'); $events = $this->getAndCallMethod($buffer, 'extractEvents', array($this->getDomElement($this->eventXml), 'system')); $this->assertEquals(array(), $events); }
/** * Parse the events in an <entry> section * * @param DOMElement $entry * @param string $currentUserId The current user ID as extracted from * the <entry> part * * @return Event[] */ protected function extractEvents(DOMElement $entry, $currentUserId) { $events = array(); $domEvents = $entry->getElementsByTagName('event'); foreach ($domEvents as $domEvent) { $event = $this->factory->get('Jackalope\\Observation\\Event', array($this->nodeTypeManager)); $event->setType($this->extractEventType($domEvent)); $date = $this->getDomElement($domEvent, 'eventdate', 'The event date was not found while building the event journal:\\n' . $this->getEventDom($domEvent)); $event->setUserId($currentUserId); // The timestamps in Java contain milliseconds, it's not the case in PHP // so we strip millis from the response $event->setDate(substr($date->nodeValue, 0, -3)); $id = $this->getDomElement($domEvent, 'eventidentifier'); if ($id) { $event->setIdentifier($id->nodeValue); } $href = $this->getDomElement($domEvent, 'href'); if ($href) { $path = str_replace($this->workspaceRootUri, '', $href->nodeValue); if (substr($path, -1) === '/') { // Jackrabbit might return paths with trailing slashes. Eliminate them if present. $path = substr($path, 0, -1); } $event->setPath($path); } $primaryNodeType = $this->getDomElement($domEvent, 'eventprimarynodetype'); if ($primaryNodeType) { $event->setPrimaryNodeTypeName($primaryNodeType->nodeValue); } $mixinNodeTypes = $domEvent->getElementsByTagName('eventmixinnodetype'); foreach ($mixinNodeTypes as $mixinNodeType) { $event->addMixinNodeTypeName($mixinNodeType->nodeValue); } $userData = $this->getDomElement($domEvent, 'eventuserdata'); if ($userData) { $event->setUserData($userData->nodeValue); } $eventInfos = $this->getDomElement($domEvent, 'eventinfo'); if ($eventInfos) { foreach ($eventInfos->childNodes as $info) { if ($info->nodeType == XML_ELEMENT_NODE) { $event->addInfo($info->tagName, $info->nodeValue); } } } // abort if we got more events than expected (usually on paging) if ($event->getDate() > $this->creationMillis) { $this->nextMillis = false; return $events; } if ($this->filter->match($event)) { $events[] = $event; } } return $events; }
protected function assertFilterMatch(EventFilter $filter, $expectedResult) { $event = new Event($this->factory, $this->getNodeTypeManager()); $event->setPath('/some/path'); $this->assertEquals($expectedResult, $filter->match($event)); }
protected function assertFilterMatch(EventFilter $filter, $isSupposedToMatch, $path) { $event = new Event($this->factory, $this->getNodeTypeManager()); $event->setPath($path); $this->assertEquals($isSupposedToMatch, $filter->match($event)); }