public function testMismatchesItemsInAnyOrder()
 {
     $matcher = containsInAnyOrder(array(1, 2, 3));
     $this->assertMismatchDescription('was null', $matcher, null);
     $this->assertMismatchDescription('No item matches: <1>, <2>, <3> in []', $matcher, array());
     $this->assertMismatchDescription('No item matches: <2>, <3> in [<1>]', $matcher, array(1));
     $this->assertMismatchDescription('Not matched: <4>', $matcher, array(4, 3, 2, 1));
 }
 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));
 }
Пример #3
0
 /** @group Functional */
 public function testRunMonkBulkScan()
 {
     $this->setUpTables();
     $this->setUpRepo();
     $userId = 2;
     $groupId = 2;
     $uploadTreeId = 1;
     $licenseId1 = 225;
     $removing1 = false;
     $licenseId2 = 213;
     $removing2 = false;
     $refText = "The GNU General Public License is a free, copyleft license for software and other kinds of works.";
     $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, array($licenseId1 => $removing1, $licenseId2 => $removing2), $refText);
     $this->assertGreaterThan($expected = 0, $bulkId);
     $jobId = 64;
     list($output, $retCode) = $this->runBulkMonk($userId, $groupId, $jobId, $bulkId);
     $this->assertEquals(6, $this->getHeartCount($output));
     $this->rmRepo();
     $this->assertEquals($retCode, 0, 'monk bulk failed: ' . $output);
     $bounds6 = new ItemTreeBounds(6, 'uploadtree_a', 1, 17, 18);
     $bounds7 = new ItemTreeBounds(7, 'uploadtree_a', 1, 15, 16);
     $relevantDecisionsItem6 = $this->clearingDao->getRelevantClearingEvents($bounds6, $groupId);
     $relevantDecisionsItem7 = $this->clearingDao->getRelevantClearingEvents($bounds7, $groupId);
     assertThat(count($relevantDecisionsItem6), is(equalTo(2)));
     assertThat(count($relevantDecisionsItem7), is(equalTo(2)));
     $rfForACE = 225;
     assertThat($relevantDecisionsItem6, hasKeyInArray($rfForACE));
     /** @var ClearingEvent $clearingEvent */
     $clearingEvent = $relevantDecisionsItem6[$rfForACE];
     $eventId = $clearingEvent->getEventId();
     $bulkHighlights = $this->highlightDao->getHighlightBulk(6, $eventId);
     assertThat(count($bulkHighlights), is(1));
     /** @var Highlight $bulkHighlight1 */
     $bulkHighlight1 = $bulkHighlights[0];
     assertThat($bulkHighlight1->getLicenseId(), is(equalTo($licenseId1)));
     assertThat($bulkHighlight1->getType(), is(equalTo(Highlight::BULK)));
     assertThat($bulkHighlight1->getStart(), is(3));
     assertThat($bulkHighlight1->getEnd(), is(103));
     $rfForACE = 213;
     assertThat($relevantDecisionsItem6, hasKeyInArray($rfForACE));
     /** @var ClearingEvent $clearingEvent */
     $clearingEvent = $relevantDecisionsItem6[$rfForACE];
     $eventId = $clearingEvent->getEventId();
     $bulkHighlights = $this->highlightDao->getHighlightBulk(6, $eventId);
     assertThat(count($bulkHighlights), is(1));
     /** @var Highlight $bulkHighlight1 */
     $bulkHighlight2 = $bulkHighlights[0];
     assertThat($bulkHighlight2->getLicenseId(), is(equalTo($licenseId2)));
     assertThat($bulkHighlight2->getType(), is(equalTo(Highlight::BULK)));
     assertThat($bulkHighlight2->getStart(), is(3));
     assertThat($bulkHighlight2->getEnd(), is(103));
     $bulkHighlights = $this->highlightDao->getHighlightBulk(6);
     assertThat(count($bulkHighlights), is(equalTo(2)));
     assertThat($bulkHighlights, containsInAnyOrder($bulkHighlight1, $bulkHighlight2));
 }
Пример #4
0
 /** @group Functional */
 public function testRunMonkScan()
 {
     $this->setUpTables();
     $this->setUpRepo();
     list($output, $retCode) = $this->runMonk($uploadId = 1);
     $this->rmRepo();
     $this->assertEquals($retCode, 0, 'monk failed: ' . $output);
     $this->assertEquals(6, $this->getHeartCount($output));
     $bounds = $this->uploadDao->getParentItemBounds($uploadId);
     $matches = $this->licenseDao->getAgentFileLicenseMatches($bounds);
     $this->assertEquals($expected = 2, count($matches));
     /** @var LicenseMatch */
     $licenseMatch = $matches[0];
     $this->assertEquals($expected = 4, $licenseMatch->getFileId());
     /** @var LicenseRef */
     $matchedLicense = $licenseMatch->getLicenseRef();
     $this->assertEquals($matchedLicense->getShortName(), "GPL-3.0");
     /** @var AgentRef */
     $agentRef = $licenseMatch->getAgentRef();
     $this->assertEquals($agentRef->getAgentName(), "monk");
     $highlights = $this->highlightDao->getHighlightDiffs($this->uploadDao->getItemTreeBounds(7));
     $expectedHighlight = new Highlight(18, 35825, Highlight::MATCH, 20, 35819);
     $expectedHighlight->setLicenseId($matchedLicense->getId());
     $this->assertEquals(array($expectedHighlight), $highlights);
     $highlights = $this->highlightDao->getHighlightDiffs($this->uploadDao->getItemTreeBounds(11));
     $expectedHighlights = array();
     $expectedHighlights[] = new Highlight(18, 339, Highlight::MATCH, 20, 350);
     $expectedHighlights[] = new Highlight(340, 347, Highlight::CHANGED, 351, 357);
     $expectedHighlights[] = new Highlight(348, 35149, Highlight::MATCH, 358, 35819);
     foreach ($expectedHighlights as $expectedHighlight) {
         $expectedHighlight->setLicenseId($matchedLicense->getId());
     }
     assertThat($highlights, containsInAnyOrder($expectedHighlights));
 }
Пример #5
0
 public function testGetMappedLicenseRefView()
 {
     $this->testDb = new TestPgDb();
     $this->testDb->createPlainTables(array('license_ref', 'license_map'));
     $this->dbManager = $this->testDb->getDbManager();
     $this->dbManager->queryOnce("CREATE TABLE license_candidate (group_fk integer) INHERITS (license_ref)");
     $this->dbManager->insertTableRow('license_map', array('license_map_pk' => 0, 'rf_fk' => 2, 'rf_parent' => 1, 'usage' => LicenseMap::CONCLUSION));
     $this->dbManager->insertTableRow('license_ref', array('rf_pk' => 1, 'rf_shortname' => 'One', 'rf_fullname' => 'One-1'));
     $this->dbManager->insertTableRow('license_ref', array('rf_pk' => 2, 'rf_shortname' => 'Two', 'rf_fullname' => 'Two-2'));
     $this->dbManager->insertTableRow('license_candidate', array('rf_pk' => 3, 'rf_shortname' => 'Three', 'rf_fullname' => 'Three-3', 'group_fk' => $this->groupId));
     $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
     $view = LicenseMap::getMappedLicenseRefView(LicenseMap::CONCLUSION);
     $stmt = __METHOD__;
     $this->dbManager->prepare($stmt, $view);
     $res = $this->dbManager->execute($stmt);
     $map = $this->dbManager->fetchAll($res);
     $this->dbManager->freeResult($res);
     assertThat($map, is(arrayWithSize(2)));
     $expected = array(array('rf_origin' => 1, 'rf_pk' => 1, 'rf_shortname' => 'One', 'rf_fullname' => 'One-1'), array('rf_origin' => 2, 'rf_pk' => 1, 'rf_shortname' => 'One', 'rf_fullname' => 'One-1'));
     assertThat($map, containsInAnyOrder($expected));
 }