Ejemplo n.º 1
0
 private function runnerDeciderScanWithTwoEventAndNoAgentShouldMakeADecision($runner)
 {
     $this->setUpTables();
     $this->setUpRepo();
     $jobId = 42;
     $licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
     $licenseRef2 = $this->licenseDao->getLicenseByShortName("3DFX")->getRef();
     $addedLicenses = array($licenseRef1, $licenseRef2);
     assertThat($addedLicenses, not(arrayContaining(null)));
     $eventId1 = $this->clearingDao->insertClearingEvent($originallyClearedItemId = 23, $userId = 2, $groupId = 3, $licenseRef1->getId(), false);
     $eventId2 = $this->clearingDao->insertClearingEvent($originallyClearedItemId, 5, $groupId, $licenseRef2->getId(), true);
     $this->dbManager->queryOnce("UPDATE clearing_event SET job_fk={$jobId}");
     $addedEventIds = array($eventId1, $eventId2);
     list($success, $output, $retCode) = $runner->run($uploadId = 2, $userId, $groupId, $jobId, $args = "");
     $this->assertTrue($success, 'cannot run runner');
     $this->assertEquals($retCode, 0, 'decider failed (did you make test?): ' . $output);
     assertThat($this->getHeartCount($output), equalTo(1));
     $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
     $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
     assertThat($decisions, is(arrayWithSize(1)));
     /** @var ClearingDecision $deciderMadeDecision*/
     $deciderMadeDecision = $decisions[0];
     foreach ($deciderMadeDecision->getClearingEvents() as $event) {
         assertThat($event->getEventId(), is(anyOf($addedEventIds)));
     }
     $this->rmRepo();
 }
Ejemplo n.º 2
0
 public function testAnyOfHasAReadableDescription()
 {
     $this->assertDescription('("good" or "bad" or "ugly")', anyOf('good', 'bad', 'ugly'));
 }
Ejemplo n.º 3
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();
 }
Ejemplo n.º 4
0
 /**
  * Testing the hamcrest functions
  */
 public function testHamcrestTest()
 {
     $mock = ShortifyPunit::mock('SimpleClassForMocking');
     ShortifyPunit::when($mock)->first_method()->second_method(anything())->returns(1);
     ShortifyPunit::when($mock)->first_method(1)->second_method(equalTo(1))->returns(2);
     ShortifyPunit::when($mock)->first_method(2)->second_method(anything(), equalTo(1))->returns(3);
     ShortifyPunit::when($mock)->first_method(3)->second_method(containsString('foo bar'), anInstanceOf('SimpleClassForMocking'))->returns(4);
     ShortifyPunit::when($mock)->first_method(equalTo(4))->second_method(1)->returns(5);
     ShortifyPunit::when($mock)->first_method(equalTo(5))->second_method(not(1))->third_method(anyOf(1, 2, 3))->returns(6);
     ShortifyPunit::when($mock)->first_method(equalTo(5))->second_method(not(1))->third_method(anything())->returns(7);
     // HHVM Cannot serialize Exceptions
     //$exception = new \Exception('some message');
     $this->assertEquals($mock->first_method()->second_method(1), 1);
     $this->assertEquals($mock->first_method()->second_method(array()), 1);
     $this->assertNull($mock->first_method('foo'));
     //$this->assertNull($mock->first_method()->second_method('foo bar', $exception));
     $this->assertEquals($mock->first_method(1)->second_method(1), 2);
     $this->assertNull($mock->first_method(1)->second_method('bar'));
     $this->assertEquals($mock->first_method(2)->second_method('anything', 1), 3);
     $this->assertNull($mock->first_method(2)->second_method(false, 2));
     $this->assertEquals($mock->first_method(3)->second_method('foo bar', $mock), 4);
     $this->assertNull($mock->first_method(3)->second_method('foo', $mock));
     //$this->assertNull($mock->first_method(3)->second_method('foo bar', $exception));
     $this->assertEquals($mock->first_method(4)->second_method(1), 5);
     $this->assertEquals($mock->first_method(5)->second_method(2)->third_method(1), 6);
     $this->assertEquals($mock->first_method(5)->second_method(3)->third_method(2), 6);
     $this->assertEquals($mock->first_method(5)->second_method(2)->third_method(4), 7);
 }
Ejemplo n.º 5
0
<?php

$act = "tedit";
$ref = pageLinkAct(array('id' => $id, 'src' => $src));
$title = sprintf(T_("Editing ticket %s"), "<span class=\"ticketid\">{$id}</span>");
pageHeader(array('title' => $title));
// form values
$name = anyOf(@$_POST['name'], $DATA['name']);
$comment = anyOf(@$_POST['comment'], $DATA['cmt']);
$hasPass = hasPassHash($DATA);
$pass = anyOf(@$_POST['pass'], "");
$clear = anyOf(@$_POST['clear'], "");
$permanent = anyOf(@$_POST['ticket_permanent'], !($DATA['expire'] || $DATA["last_time"] || $DATA["expire_dln"]));
$notify = anyOf(@$_POST['notify'], join(", ", getEMailAddrs($DATA['notify_email'])));
// current expiration values
if (isset($_POST['ticket_totaldays'])) {
    $totalDays = $_POST['ticket_totaldays'];
} elseif ($DATA["expire"]) {
    $totalDays = ceil(($DATA["expire"] - time()) / (3600 * 24));
} elseif ($permanent) {
    $totalDays = $defaults['ticket']['total'] / (3600 * 24);
} else {
    $totalDays = 0;
}
if (isset($_POST['ticket_lastdldays'])) {
    $lastDlDays = $_POST['ticket_lastdldays'];
} elseif ($DATA["last_time"]) {
    $lastDlDays = ceil($DATA["last_time"] / (3600 * 24));
} elseif ($permanent) {
    $lastDlDays = $defaults['ticket']['lastdl'] / (3600 * 24);
} else {