public function testFilterCurrentReusableClearingDecisions()
 {
     $itemId = 543;
     $itemId2 = 432;
     $decision1 = M::mock(ClearingDecision::classname());
     $decision1->shouldReceive("getUploadTreeId")->andReturn($itemId);
     $decision2 = M::mock(ClearingDecision::classname());
     $decision2->shouldReceive("getUploadTreeId")->andReturn($itemId2);
     $filteredClearingDecisions = $this->clearingDecisionFilter->filterCurrentReusableClearingDecisions(array($decision1, $decision2));
     $expecedArray = array($itemId => $decision1, $itemId2 => $decision2);
     assertThat($filteredClearingDecisions, containsInAnyOrder($expecedArray));
 }
 /**
  * @param ClearingDecision $decision
  * @param int $type
  * @param int[] $clearingEventIds
  * @return boolean
  */
 private function clearingDecisionIsDifferentFrom(ClearingDecision $decision, $type, $scope, $clearingEventIds)
 {
     $clearingEvents = $decision->getClearingEvents();
     if (count($clearingEvents) != count($clearingEventIds)) {
         return true;
     }
     foreach ($clearingEvents as $clearingEvent) {
         if (false === array_search($clearingEvent->getEventId(), $clearingEventIds)) {
             return true;
         }
     }
     return $type !== $decision->getType() || $scope !== $decision->getScope();
 }
Exemplo n.º 3
0
 /**
  * @param int $itemId
  * @param ClearingDecision $clearingDecisionToCopy
  */
 protected function createCopyOfClearingDecision($itemId, $userId, $groupId, $clearingDecisionToCopy)
 {
     $clearingEventIdsToCopy = array();
     /** @var ClearingEvent $clearingEvent */
     foreach ($clearingDecisionToCopy->getClearingEvents() as $clearingEvent) {
         $clearingEventIdsToCopy[] = $clearingEvent->getEventId();
     }
     $this->clearingDao->createDecisionFromEvents($itemId, $userId, $groupId, $clearingDecisionToCopy->getType(), $clearingDecisionToCopy->getScope(), $clearingEventIdsToCopy);
 }
 /**
  * @param ClearingDecision $clearingDecision
  */
 public function copy(ClearingDecision $clearingDecision)
 {
     $this->sameFolder = $clearingDecision->getSameFolder();
     $this->clearingEvents = $clearingDecision->getClearingEvents();
     $this->clearingId = $clearingDecision->getClearingId();
     $this->uploadTreeId = $clearingDecision->getUploadTreeId();
     $this->pfileId = $clearingDecision->getPfileId();
     $this->userName = $clearingDecision->getUserName();
     $this->userId = $clearingDecision->getUserId();
     $this->type = $clearingDecision->getType();
     $this->comment = $clearingDecision->getComment();
     $this->reportinfo = $clearingDecision->getReportinfo();
     $this->scope = $clearingDecision->getScope();
     $this->timeStamp = $clearingDecision->getTimeStamp();
 }
 /**
  * @brief user decides no license, then scanner finds licA, than user removes licA -> no new clearing event should be generated as nothing changes the state
  */
 public function testMakeDecisionFromLastEventsWithDelayedScanner()
 {
     /** @var LicenseRef $licenseRef */
     list($scannerResults, $licenseRef) = $this->createScannerDetectedLicenses();
     $isGlobal = false;
     $removedEvent = $this->createClearingEvent(123, $this->timestamp, $licenseRef->getId(), $licenseRef->getShortName(), $licenseRef->getFullName(), ClearingEventTypes::USER, $isRemoved = true);
     $this->clearingDao->shouldReceive("getRelevantClearingEvents")->with($this->itemTreeBounds, $this->groupId)->andReturn(array($licenseRef->getId() => $removedEvent));
     $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")->with($this->itemTreeBounds)->andReturn($scannerResults);
     $clearingDecision = M::mock(ClearingDecision::classname());
     $clearingDecision->shouldReceive("getTimeStamp")->withNoArgs()->andReturn($this->timestamp - 3600);
     $clearingDecision->shouldReceive("getType")->withNoArgs()->andReturn(DecisionTypes::IDENTIFIED);
     $clearingDecision->shouldReceive("getClearingEvents")->withNoArgs()->andReturn(array());
     $this->clearingDao->shouldReceive("getRelevantClearingDecision")->with($this->itemTreeBounds, $this->groupId)->andReturn($clearingDecision);
     $this->clearingDao->shouldReceive("insertClearingEvent")->never();
     $this->clearingDao->shouldReceive("createDecisionFromEvents")->once()->with($this->uploadTreeId, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, DecisionScopes::ITEM, is(arrayContainingInAnyOrder($removedEvent->getEventId())));
     $this->clearingDao->shouldReceive("removeWipClearingDecision")->never();
     $this->clearingDecisionProcessor->makeDecisionFromLastEvents($this->itemTreeBounds, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, $isGlobal);
 }