35 protected function setUp()
38 $this->testDb->createPlainTables(
44 'obligation_candidate_map' 46 $this->
dbManager = $this->testDb->getDbManager();
47 $this->
dbManager->queryOnce(
"CREATE TABLE license_candidate (group_fk integer) INHERITS (license_ref)");
48 $this->
dbManager->insertTableRow(
'license_map',array(
'license_map_pk'=>0,
'rf_fk'=>2,
'rf_parent'=>1,
'usage'=>LicenseMap::CONCLUSION));
49 $this->
dbManager->insertTableRow(
'license_ref',array(
'rf_pk'=>1,
'rf_shortname'=>
'One',
'rf_fullname'=>
'One-1'));
50 $this->
dbManager->insertTableRow(
'license_ref',array(
'rf_pk'=>2,
'rf_shortname'=>
'Two',
'rf_fullname'=>
'Two-2'));
51 $this->
dbManager->insertTableRow(
'license_candidate',
52 array(
'rf_pk'=>3,
'rf_shortname'=>
'Three',
'rf_fullname'=>
'Three-3',
'group_fk'=>$this->groupId));
53 $this->
dbManager->insertTableRow(
'obligation_ref',
56 'ob_type' =>
'Obligation',
57 'ob_topic' =>
'Obligation-1',
58 'ob_text' =>
'Obligation text',
59 'ob_classification' =>
'white',
60 'ob_modifications' =>
'Yes',
61 'ob_comment' =>
'Obligation comment',
63 'ob_text_updatable' =>
false,
64 'ob_md5' =>
'0ffdddc657a16b95894437b4af736102' 66 $this->
dbManager->insertTableRow(
'obligation_map',
72 $this->
dbManager->insertTableRow(
'obligation_candidate_map',
78 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
81 protected function tearDown()
83 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
86 function testProjectedIdOfUnmappedIdIsIdItself()
90 assertThat($licenseMap->getProjectedId($licenseId),is($licenseId));
93 function testProjectedIdOfCandidatesAreRecognized()
97 assertThat($licenseMap->getProjectedId($licenseId),is($licenseId));
100 function testProjectedIdOfUnmappedIdIsParentId()
103 $licenseMap->getGroupId();
104 assertThat($licenseMap->getProjectedId(2),is(1));
107 function testProjectedShortNameOfMappedId()
110 assertThat($licenseMap->getProjectedShortName(2),is(
'One'));
113 function testObligationForLicense()
116 assertThat($licenseMap->getObligationsForLicenseRef(2), contains(2));
119 function testObligationForUnassignedLicense()
122 assertThat($licenseMap->getObligationsForLicenseRef(1), is(emptyArray()));
125 function testObligationForCandidateLicense()
128 assertThat($licenseMap->getObligationsForLicenseRef(3,
true), contains(2));
131 function testProjectedIdOfMappedIdIsIdItselfIfTrivialMap()
134 assertThat($licenseMap->getProjectedId(2),is(2));
137 function testGetTopLevelLicenseRefs()
140 $topLevelLicenses = $licenseMap->getTopLevelLicenseRefs();
141 assertThat($topLevelLicenses,hasItemInArray(
new LicenseRef(1,
'One',
'One-1')));
142 assertThat($topLevelLicenses, not(hasKeyInArray(2)));
146 public function testGetMappedLicenseRefView()
149 $this->testDb->createPlainTables(array(
'license_ref',
'license_map'));
150 $this->
dbManager = $this->testDb->getDbManager();
151 $this->
dbManager->queryOnce(
"CREATE TABLE license_candidate (group_fk integer) INHERITS (license_ref)");
152 $this->
dbManager->insertTableRow(
'license_map',array(
'license_map_pk'=>0,
'rf_fk'=>2,
'rf_parent'=>1,
'usage'=>LicenseMap::CONCLUSION));
153 $this->
dbManager->insertTableRow(
'license_ref',array(
'rf_pk'=>1,
'rf_shortname'=>
'One',
'rf_fullname'=>
'One-1'));
154 $this->
dbManager->insertTableRow(
'license_ref',array(
'rf_pk'=>2,
'rf_shortname'=>
'Two',
'rf_fullname'=>
'Two-2'));
155 $this->
dbManager->insertTableRow(
'license_candidate',
156 array(
'rf_pk'=>3,
'rf_shortname'=>
'Three',
'rf_fullname'=>
'Three-3',
'group_fk'=>$this->groupId));
157 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
165 assertThat($map,is(arrayWithSize(2)));
167 array(
'rf_origin'=>1,
'rf_pk'=>1,
'rf_shortname'=>
'One',
'rf_fullname'=>
'One-1'),
168 array(
'rf_origin'=>2,
'rf_pk'=>1,
'rf_shortname'=>
'One',
'rf_fullname'=>
'One-1')
170 assertThat($map,containsInAnyOrder($expected));
173 public function testFullMap()
175 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId+1, LicenseMap::CONCLUSION,
true);
176 $map = \Fossology\Lib\Test\Reflectory::getObjectsProperty($licenseMap,
'map');
177 assertThat($map,hasItemInArray(array(
'rf_fk'=>1,
'parent_shortname'=>
'One',
'rf_parent'=>1)));
178 assertThat($map,hasItemInArray(array(
'rf_fk'=>2,
'parent_shortname'=>
'One',
'rf_parent'=>1)));
181 public function testFullMapWithCandidates()
183 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId, LicenseMap::CONCLUSION,
true);
184 $map = \Fossology\Lib\Test\Reflectory::getObjectsProperty($licenseMap,
'map');
185 assertThat($map,hasItemInArray(array(
'rf_fk'=>1,
'parent_shortname'=>
'One',
'rf_parent'=>1)));
186 assertThat($map,hasItemInArray(array(
'rf_fk'=>2,
'parent_shortname'=>
'One',
'rf_parent'=>1)));
187 assertThat($map,hasItemInArray(array(
'rf_fk'=>3,
'parent_shortname'=>
'Three',
'rf_parent'=>3)));
Wrapper class for license map.
Contains business rules for FOSSology.
fo_dbManager * dbManager
fo_dbManager object
static getMappedLicenseRefView($usageExpr='$1')
Query to get license map view along with license ref.