public function testGetNonArtifactDescendantsWithoutMaterialize()
 {
     $uploadTreeProxy = new UploadTreeProxy($uploadId = 1, $options = array(), $uploadTreeTableName = 'uploadtree_a');
     $artifact = new ItemTreeBounds(2, 'uploadtree_a', $uploadId, 2, 3);
     $artifactDescendants = $uploadTreeProxy->getNonArtifactDescendants($artifact);
     assertThat($artifactDescendants, emptyArray());
     $zip = new ItemTreeBounds(1, 'uploadtree_a', $uploadId, 1, 24);
     $zipDescendants = $uploadTreeProxy->getNonArtifactDescendants($zip);
     assertThat(array_keys($zipDescendants), arrayContainingInAnyOrder(array(6, 7, 8, 10, 11, 12)));
 }
 public function testQueryTwoScanners()
 {
     $this->testDb->getDbManager()->queryOnce('CREATE TABLE monk_ars AS SELECT * FROM nomos_ars WHERE 0=1');
     $this->testDb->insertData(array('monk_ars'));
     $uploadId = 2;
     $agentNames = array('nomos', 'monk');
     $latestScannerProxy = new LatestScannerProxy($uploadId, $agentNames, 'latest_scanner', "AND agent_enabled='true'");
     $sql = $latestScannerProxy->getDbViewQuery();
     $scanners = $this->getAllColumns($sql);
     assertThat($scanners, arrayContainingInAnyOrder(array(array('agent_pk' => 6, 'agent_name' => 'nomos'), array('agent_pk' => 5, 'agent_name' => 'monk'))));
 }
Example #3
0
 public function testMainLicenseIds()
 {
     $this->testDb->createPlainTables(array('upload_clearing_license'));
     $uploadId = 101;
     $mainLicIdsInitially = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdsInitially, is(emptyArray()));
     $this->clearingDao->makeMainLicense($uploadId, $this->groupId, $licenseId = 402);
     $mainLicIdsAfterAddingOne = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdsAfterAddingOne, arrayContaining(array($licenseId)));
     $this->clearingDao->makeMainLicense($uploadId, $this->groupId, $licenseId);
     $mainLicIdsAfterAddingOneTwice = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdsAfterAddingOneTwice, is(arrayWithSize(1)));
     $this->clearingDao->makeMainLicense($uploadId, $this->groupId, $licenseId2 = 403);
     $mainLicIdsAfterAddingOther = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdsAfterAddingOther, arrayContainingInAnyOrder(array($licenseId, $licenseId2)));
     $this->clearingDao->removeMainLicense($uploadId, $this->groupId, $licenseId2);
     $mainLicIdsAfterRemovingOne = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdsAfterRemovingOne, is(arrayWithSize(1)));
     $this->clearingDao->removeMainLicense($uploadId, $this->groupId, $licenseId2);
     $mainLicIdAfterRemovingSomethingNotInSet = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdAfterRemovingSomethingNotInSet, is(arrayWithSize(1)));
     $this->clearingDao->removeMainLicense($uploadId, $this->groupId + 1, $licenseId);
     $mainLicIdAfterInsertToOtherGroup = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdAfterInsertToOtherGroup, is(arrayWithSize(1)));
     $this->clearingDao->removeMainLicense($uploadId + 1, $this->groupId, $licenseId);
     $mainLicIdAfterInsertToOtherUpload = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdAfterInsertToOtherUpload, is(arrayWithSize(1)));
 }
Example #4
0
 /**
  * @test
  * @dataProvider objects
  */
 public function findFilesIn_withDirectory_returnsAllFilesIncludingNestedFilesFromDirectory(array $objects, array $expectedFiles)
 {
     $this->directory->objects = $objects;
     $files = $this->fileSystem->findFilesIn($this->directory);
     assertThat($files, is(arrayContainingInAnyOrder($expectedFiles)));
 }
 public function testMyJobs()
 {
     $groupId = 2;
     $GLOBALS['SysConf']['auth'][Auth::GROUP_ID] = $groupId;
     $GLOBALS['SysConf']['auth'][Auth::USER_ID] = 1;
     $this->uploadPermissionDao->shouldReceive('isAccessible')->withArgs(array(anything(), $groupId))->andReturnUsing(function ($upload, $group) {
         return $upload == 1 || $upload == 2 || $upload == 4;
     });
     $testOurJobs = $this->showJobsDao->myJobs(true);
     assertThat($testOurJobs, is(arrayContainingInAnyOrder($this->job_pks)));
     $testMyJobs = $this->showJobsDao->myJobs(false);
     assertThat($testMyJobs, equalTo(array(1)));
     $this->dbManager->queryOnce("UPDATE job SET job_queued=job_queued-INTERVAL '30 days' WHERE job_pk=1");
     $this->dbManager->prepare(__METHOD__ . 'insert.perm_upload', "INSERT INTO perm_upload (perm_upload_pk, perm, upload_fk, group_fk) VALUES (\$1, \$2, \$3, \$4)");
     $testOutdatedJobs = $this->showJobsDao->myJobs(true);
     assertThat($testOutdatedJobs, equalTo(array(2)));
 }
Example #6
0
 public function testGetLicenseShortnamesContained()
 {
     $this->testDb->createPlainTables(array('license_ref', 'license_file', 'uploadtree'));
     $this->dbManager->queryOnce("CREATE TABLE \"uploadtree_a\" AS SELECT * FROM uploadtree");
     $this->testDb->createViews(array('license_file_ref'));
     $this->testDb->insertData(array('license_file', 'uploadtree_a'));
     $this->testDb->insertData_license_ref($limit = 3);
     $stmt = __METHOD__ . '.select.license_ref';
     $this->dbManager->prepare($stmt, "SELECT rf_pk,rf_shortname FROM license_ref");
     $licRes = $this->dbManager->execute($stmt);
     $licAll = array();
     while ($erg = $this->dbManager->fetchArray($licRes)) {
         $licAll[$erg['rf_pk']] = $erg['rf_shortname'];
     }
     $this->dbManager->freeResult($licRes);
     $pfileId = 42;
     $agentId = 23;
     $matchPercent = 50;
     $uploadtreeId = 512;
     $uploadId = 123;
     $left = 2009;
     $right = 2014;
     $mydate = "'2014-06-04 14:01:30.551093+02'";
     foreach ($licAll as $licenseRefNumber => $shortname) {
         $this->dbManager->queryOnce("INSERT INTO license_file (rf_fk, agent_fk, rf_match_pct, rf_timestamp, pfile_fk)\n            VALUES ({$licenseRefNumber}, {$agentId}, {$matchPercent}, {$mydate}, {$pfileId})");
     }
     $this->dbManager->queryOnce("INSERT INTO uploadtree (uploadtree_pk, upload_fk, pfile_fk, lft, rgt)\n            VALUES ({$uploadtreeId}, {$uploadId}, {$pfileId}, {$left}, {$right})");
     $licDao = new LicenseDao($this->dbManager);
     $itemTreeBounds = new ItemTreeBounds($uploadtreeId, "uploadtree", $uploadId, $left, $right);
     $licenses = $licDao->getLicenseShortnamesContained($itemTreeBounds);
     assertThat($licenses, is(arrayContainingInAnyOrder(array_values($licAll))));
     $licensesForBadAgent = $licDao->getLicenseShortnamesContained($itemTreeBounds, array(2 * $agentId));
     assertThat($licensesForBadAgent, is(emptyArray()));
     $licensesForNoAgent = $licDao->getLicenseShortnamesContained($itemTreeBounds, array());
     assertThat($licensesForNoAgent, is(emptyArray()));
     $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
 }
Example #7
0
 private function runnerReuserScanWithARepoClearingEnhanced($runner)
 {
     $this->setUpTables();
     $this->setUpRepo();
     $originallyClearedItemId = 23;
     /* upload 3 in the test db is the same as upload 2 -> items 13-24 in upload 2 correspond to 33-44 */
     $reusingUploadItemShift = 20;
     $this->dbManager->queryOnce("UPDATE uploadtree_a SET pfile_fk=351 WHERE uploadtree_pk={$originallyClearedItemId}+{$reusingUploadItemShift}", __METHOD__ . '.minorChange');
     $this->uploadDao->addReusedUpload($uploadId = 3, $reusedUpload = 2, $this->groupId, $this->groupId, $reuseMode = 1);
     $repoPath = $this->testDb->getFossSysConf() . '/repo/files/';
     $this->treeDao->shouldReceive('getRepoPathOfPfile')->with(4)->andReturn($repoPath . '04621571bcbabce75c4dd1c6445b87dec0995734.59cacdfce5051cd8a1d8a1f2dcce40a5.12320');
     $this->treeDao->shouldReceive('getRepoPathOfPfile')->with(351)->andReturn($repoPath . 'c518ce1658140b65fa0132ad1130cb91512416bf.8e913e594d24ff3aeabe350107d97815.35829');
     list($clearingLicense1, $clearingLicense2, $addedEventIds) = $this->insertDecisionFromTwoEvents(DecisionScopes::REPO, $originallyClearedItemId);
     $clearingLicenses = array($clearingLicense1, $clearingLicense2);
     list($success, $output, $retCode) = $runner->run($uploadId, $this->userId, $this->groupId);
     $this->assertTrue($success, 'cannot run runner');
     $this->assertEquals($retCode, 0, 'reuser failed: ' . $output);
     $newUploadClearings = $this->getFilteredClearings($uploadId, $this->groupId);
     $potentiallyReusableClearings = $this->getFilteredClearings($reusedUpload, $this->groupId);
     assertThat($newUploadClearings, is(arrayWithSize(1)));
     assertThat($potentiallyReusableClearings, is(arrayWithSize(1)));
     /** @var ClearingDecision */
     $potentiallyReusableClearing = $potentiallyReusableClearings[0];
     /** @var ClearingDecision */
     $newClearing = $newUploadClearings[0];
     /* they are actually the same ClearingDecision
      * only sameFolder and sameUpload are different */
     assertThat($newClearing, not(equalTo($potentiallyReusableClearing)));
     assertThat($newClearing->getClearingLicenses(), arrayContainingInAnyOrder($clearingLicenses));
     assertThat($newClearing->getType(), equalTo($potentiallyReusableClearing->getType()));
     assertThat($newClearing->getScope(), equalTo($potentiallyReusableClearing->getScope()));
     assertThat($newClearing->getUploadTreeId(), equalTo($potentiallyReusableClearing->getUploadTreeId() + $reusingUploadItemShift));
     /* reuser should have not created a correct local event history */
     $bounds = $this->uploadDao->getItemTreeBounds($originallyClearedItemId + $reusingUploadItemShift);
     $newEvents = $this->clearingDao->getRelevantClearingEvents($bounds, $this->groupId);
     assertThat($newEvents, is(arrayWithSize(count($clearingLicenses))));
     /** @var ClearingEvent $newEvent */
     foreach ($newEvents as $newEvent) {
         assertThat($newEvent->getEventId(), anyOf($addedEventIds));
         assertThat($newEvent->getClearingLicense(), anyOf($clearingLicenses));
     }
     $this->rmRepo();
 }
 /**
  * @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);
 }