function testAddReferenceTexts() { $highlight1 = new Highlight(5, 8, 'type1', 2, 6, $this->license1->getId()); $highlights = array($highlight1); $this->highlight->addReferenceTexts($highlights); assertThat($highlight1->getInfoText(), is("10")); }
public function testGetCopyrightHighlights() { $this->testDb->createPlainTables(array(), true); $this->testDb->createInheritedTables(); $uploadDao = M::mock('Fossology\\Lib\\Dao\\UploadDao'); $uploadDao->shouldReceive('getUploadEntry')->with(1)->andReturn(array('pfile_fk' => 8)); $uploadDao->shouldReceive('getUploadEntry')->with(2)->andReturn(array('pfile_fk' => 9)); $copyrightDao = new CopyrightDao($this->dbManager, $uploadDao); $noHighlights = $copyrightDao->getHighlights($uploadTreeId = 1); assertThat($noHighlights, emptyArray()); $this->testDb->insertData(array('copyright')); $highlights = $copyrightDao->getHighlights($uploadTreeId = 1); assertThat($highlights, arrayWithSize(1)); $highlight0 = $highlights[0]; assertThat($highlight0, anInstanceOf(Highlight::classname())); $this->assertInstanceOf('Fossology\\Lib\\Data\\Highlight', $highlight0); assertThat($highlight0->getEnd(), equalTo(201)); $hilights = $copyrightDao->getHighlights($uploadTreeId = 2); assertThat($hilights, arrayWithSize(1)); $hilight0 = $hilights[0]; assertThat($hilight0->getStart(), equalTo(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)); }
public function testCreateSpanEndWithWrappeingHtmlElement() { $this->highlight->shouldReceive('getHtmlElement')->andReturn($this->htmlElement); $result = $this->highlightRenderer->createSpanEnd($this->splitPosition); assertThat($result, is("</element></span>")); }
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); } } }
/** * /brief user defined auxilary function for sorting */ private function startAndLengthFirstSorter(Highlight $a, Highlight $b) { if ($a->getStart() < $b->getStart()) { return -1; } else { if ($a->getStart() > $b->getStart()) { return 1; } else { if ($a->getEnd() > $b->getEnd()) { return -1; } } } return $a->getEnd() == $b->getEnd() ? 0 : 1; }
public function testGetHtmlElement() { assertThat($this->highlight->getHtmlElement(), is($this->htmlElement)); }
/** * @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; }