/** @group Functional */ public function testRun() { $this->setUpTables(); $this->setUpRepo(); list($output, $retCode) = $this->runNinka($uploadId = 1); $this->rmRepo(); $this->assertEquals($retCode, 0, 'ninka failed: ' . $output); $bounds = $this->uploadDao->getParentItemBounds($uploadId); $matches = $this->licenseDao->getAgentFileLicenseMatches($bounds); $this->assertEquals($expected = 6, count($matches)); foreach ($matches as $licenseMatch) { /** @var LicenseRef */ $matchedLicense = $licenseMatch->getLicenseRef(); switch ($licenseMatch->getFileId()) { case 7: case 4: $expectedLicense = "GPL-3.0+"; break; case 3: $expectedLicense = "UnclassifiedLicense"; break; default: $expectedLicense = "No_license_found"; break; } $this->assertEquals($expectedLicense, $matchedLicense->getShortName(), "unexpected license for fileId " . $licenseMatch->getFileId()); /** @var AgentRef */ $agentRef = $licenseMatch->getAgentRef(); $this->assertEquals($agentRef->getAgentName(), "ninka"); } }
/** * @param ItemTreeBounds $itemTreeBounds * @return LicenseMatch[][][] map licenseId->agentName->licenseMatches */ public function getLatestScannerDetectedMatches(ItemTreeBounds $itemTreeBounds) { $agentDetectedLicenses = array(); $licenseFileMatches = $this->licenseDao->getAgentFileLicenseMatches($itemTreeBounds); foreach ($licenseFileMatches as $licenseMatch) { $licenseRef = $licenseMatch->getLicenseRef(); $licenseId = $licenseRef->getId(); if ($licenseRef->getShortName() === "No_license_found") { continue; } $agentRef = $licenseMatch->getAgentRef(); $agentName = $agentRef->getAgentName(); $agentId = $agentRef->getAgentId(); $agentDetectedLicenses[$agentName][$agentId][$licenseId][] = $licenseMatch; } return $this->filterLatestScannerDetectedMatches($agentDetectedLicenses, $itemTreeBounds->getUploadId()); }
/** @group Functional */ public function testRunMonkTwiceOnAScan() { $this->setUpTables(); $this->setUpRepo(); list($output, $retCode) = $this->runMonk($uploadId = 1); list($output2, $retCode2) = $this->runMonk($uploadId); $this->assertEquals($retCode, 0, 'monk failed: ' . $output); $this->assertEquals(6, $this->getHeartCount($output)); $this->assertEquals($retCode2, 0, 'monk failed: ' . $output2); $this->assertEquals(0, $this->getHeartCount($output2)); $this->rmRepo(); $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"); }
public function testGetAgentFileLicenseMatchesWithLicenseMapping() { $this->testDb->createPlainTables(array('license_ref', 'uploadtree', 'license_file', 'agent', 'license_map')); $this->testDb->insertData_license_ref(); $lic0 = $this->dbManager->getSingleRow("Select * from license_ref limit 1", array(), __METHOD__ . '.anyLicense'); $licRefId = $lic0['rf_pk']; $licenseFileId = 1; $pfileId = 42; $agentId = 23; $matchPercent = 50; $uploadtreeId = 512; $uploadID = 123; $left = 2009; $right = 2014; $agentName = "fake"; $agentRev = 1; $lic1 = $this->dbManager->getSingleRow("SELECT * FROM license_ref WHERE rf_pk!=\$1 LIMIT 1", array($licRefId), __METHOD__ . '.anyOtherLicense'); $licVarId = $lic1['rf_pk']; $mydate = "'2014-06-04 14:01:30.551093+02'"; $this->dbManager->insertTableRow('license_map', array('license_map_pk' => 0, 'rf_fk' => $licVarId, 'rf_parent' => $licRefId, 'usage' => LicenseMap::CONCLUSION)); $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk, rf_fk, agent_fk, rf_match_pct, rf_timestamp, pfile_fk)\n VALUES ({$licenseFileId}, {$licVarId}, {$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})"); $stmt = __METHOD__ . '.insert.agent'; $this->dbManager->prepare($stmt, "INSERT INTO agent (agent_pk, agent_name, agent_rev, agent_enabled) VALUES (\$1,\$2,\$3,\$4)"); $this->dbManager->execute($stmt, array($agentId, $agentName, $agentRev, 'true')); $licDao = new LicenseDao($this->dbManager); $itemTreeBounds = new ItemTreeBounds($uploadtreeId, "uploadtree", $uploadID, $left, $right); $matches = $licDao->getAgentFileLicenseMatches($itemTreeBounds, LicenseMap::CONCLUSION); $licenseRef = new LicenseRef($licRefId, $lic0['rf_shortname'], $lic0['rf_fullname']); $agentRef = new AgentRef($agentId, $agentName, $agentRev); $expected = array(new LicenseMatch($pfileId, $licenseRef, $agentRef, $licenseFileId, $matchPercent)); assertThat($matches, equalTo($expected)); $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore); }