public function testGetFileNamesGroupByText()
 {
     $this->clearedGetterTest = new TestClearedGetter();
     $uploadId = 1;
     $parentId = 112;
     $uploadTreeTableName = "ut";
     $this->uploadDao->shouldReceive('getUploadtreeTableName')->with($uploadId)->andReturn($uploadTreeTableName);
     $this->treeDao->shouldReceive('getMinimalCoveringItem')->with($uploadId, $uploadTreeTableName)->andReturn($parentId);
     $this->treeDao->shouldReceive('getFullPath')->with(1, $uploadTreeTableName, $parentId)->andReturn("a/1");
     $this->treeDao->shouldReceive('getFullPath')->with(2, $uploadTreeTableName, $parentId)->andReturn("a/2");
     $this->treeDao->shouldReceive('getFullPath')->with(3, $uploadTreeTableName, $parentId)->andReturn("a/b/1");
     $tester = new TestClearedGetter("text");
     $statements = $tester->getCleared($uploadId);
     $expected = array("statements" => array(array("content" => "1", "text" => "t1", "comments" => "c1", "files" => array("a/1")), array("content" => "1", "text" => "t2", "comments" => "c1", "files" => array("a/2")), array("content" => "2", "text" => "t3", "comments" => "c3", "files" => array("a/b/1"))));
     $expected = arsort($expected);
     assertThat($expected, equalTo($statements));
 }
Example #2
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();
 }