예제 #1
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));
 }
예제 #2
0
 protected function setUp()
 {
     $this->htmlElement = M::mock('Fossology\\Lib\\Html\\HtmlElement');
     $this->highlight = new Highlight($this->start, $this->end, $this->type, $this->refStart, $this->refEnd, $this->infoText, $this->htmlElement);
     $this->highlight->setLicenseId($this->licenseId);
 }
예제 #3
0
 private function addDiffsToHighlights($licenseId, $lineMatches, &$highlights)
 {
     foreach (explode(',', $lineMatches['diff']) as $diff) {
         // t[0+4798] M0 s[0+4834]
         if (preg_match('/t\\[(?P<start>[0-9]*)\\+?(?P<len>[0-9]*)?\\] M(?P<type>.?) s\\[(?P<rf_start>[0-9]*)\\+?(?P<rf_len>[0-9]*)?\\]/', $diff, $diffMatches)) {
             $start = $diffMatches['start'];
             $end = $start + $diffMatches['len'];
             $rfStart = intval($diffMatches['rf_start']);
             $rfEnd = $rfStart + $diffMatches['rf_len'];
             switch ($diffMatches['type']) {
                 case '0':
                     $type = Highlight::MATCH;
                     break;
                 case 'R':
                     $type = Highlight::CHANGED;
                     break;
                 case '-':
                     $type = Highlight::DELETED;
                     break;
                 case '+':
                     $type = Highlight::ADDED;
                     break;
                 default:
                     throw new \Exception('unrecognized diff type');
             }
             $highlight = new Highlight($start, $end, $type, $rfStart, $rfEnd);
             $highlight->setLicenseId($licenseId);
             $highlights[] = $highlight;
         } else {
             throw new \Exception('failed parsing diff element: ' . $diff);
         }
     }
 }
예제 #4
0
 /**
  * @param int $uploadTreeId
  * @param int|null $clearingId
  * @return Highlight[]
  */
 public function getHighlightBulk($uploadTreeId, $clearingId = null)
 {
     $stmt = __METHOD__;
     $sql = "SELECT h.clearing_event_fk, h.start, h.len, ce.rf_fk, rf_text\n            FROM clearing_event ce\n              INNER JOIN highlight_bulk h ON ce.clearing_event_pk = h.clearing_event_fk\n              INNER JOIN license_ref_bulk lrb ON lrb.lrb_pk = h.lrb_fk\n            WHERE ce.uploadtree_fk = \$1";
     $params = array($uploadTreeId);
     if (!empty($clearingId)) {
         $stmt .= ".clearingId";
         $params[] = $clearingId;
         $sql .= " AND h.clearing_event_fk = \$" . count($params);
     }
     $this->dbManager->prepare($stmt, $sql);
     $result = $this->dbManager->execute($stmt, $params);
     $highlightEntries = array();
     while ($row = $this->dbManager->fetchArray($result)) {
         $newHighlight = new Highlight(intval($row['start']), intval($row['start'] + $row['len']), Highlight::BULK, 0, 0);
         $newHighlight->setLicenseId($row['rf_fk']);
         $highlightEntries[] = $newHighlight;
     }
     $this->dbManager->freeResult($result);
     return $highlightEntries;
 }