24 protected function setUp() : void
27 $this->testDb->createPlainTables(
33 'obligation_candidate_map'
35 $this->
dbManager = $this->testDb->getDbManager();
36 $this->
dbManager->queryOnce(
"CREATE TABLE license_candidate (group_fk integer) INHERITS (license_ref)");
37 $this->
dbManager->insertTableRow(
'license_map',array(
'license_map_pk'=>0,
'rf_fk'=>2,
'rf_parent'=>1,
'usage'=>LicenseMap::CONCLUSION));
38 $this->
dbManager->insertTableRow(
'license_ref',array(
'rf_pk'=>1,
'rf_shortname'=>
'One',
'rf_fullname'=>
'One-1',
'rf_spdx_id'=>
'One'));
39 $this->
dbManager->insertTableRow(
'license_ref',array(
'rf_pk'=>2,
'rf_shortname'=>
'Two',
'rf_fullname'=>
'Two-2',
'rf_spdx_id'=>
'Two'));
40 $this->
dbManager->insertTableRow(
'license_candidate',
41 array(
'rf_pk'=>3,
'rf_shortname'=>
'Three',
'rf_fullname'=>
'Three-3',
'group_fk'=>$this->groupId,
'rf_spdx_id'=>
'Three'));
42 $this->
dbManager->insertTableRow(
'obligation_ref',
45 'ob_type' =>
'Obligation',
46 'ob_topic' =>
'Obligation-1',
47 'ob_text' =>
'Obligation text',
48 'ob_classification' =>
'white',
49 'ob_modifications' =>
'Yes',
50 'ob_comment' =>
'Obligation comment',
52 'ob_text_updatable' =>
false,
53 'ob_md5' =>
'0ffdddc657a16b95894437b4af736102'
55 $this->
dbManager->insertTableRow(
'obligation_map',
61 $this->
dbManager->insertTableRow(
'obligation_candidate_map',
67 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
70 protected function tearDown() : void
72 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
75 function testProjectedIdOfUnmappedIdIsIdItself()
77 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId);
79 assertThat($licenseMap->getProjectedId($licenseId),is($licenseId));
82 function testProjectedIdOfCandidatesAreRecognized()
84 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId);
86 assertThat($licenseMap->getProjectedId($licenseId),is($licenseId));
89 function testProjectedIdOfUnmappedIdIsParentId()
91 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId);
92 $licenseMap->getGroupId();
93 assertThat($licenseMap->getProjectedId(2),is(1));
96 function testProjectedShortNameOfMappedId()
98 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId);
99 assertThat($licenseMap->getProjectedShortName(2),is(
'One'));
102 function testObligationForLicense()
104 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId);
105 assertThat($licenseMap->getObligationsForLicenseRef(2), contains(2));
108 function testObligationForUnassignedLicense()
110 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId);
111 assertThat($licenseMap->getObligationsForLicenseRef(1), is(emptyArray()));
114 function testObligationForCandidateLicense()
116 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId);
117 assertThat($licenseMap->getObligationsForLicenseRef(3,
true), contains(2));
120 function testProjectedIdOfMappedIdIsIdItselfIfTrivialMap()
122 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId, LicenseMap::TRIVIAL);
123 assertThat($licenseMap->getProjectedId(2),is(2));
126 function testGetTopLevelLicenseRefs()
128 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId, LicenseMap::CONCLUSION);
129 $topLevelLicenses = $licenseMap->getTopLevelLicenseRefs();
130 assertThat($topLevelLicenses,hasItemInArray(
new LicenseRef(1,
'One',
'One-1',
'One')));
131 assertThat($topLevelLicenses, not(hasKeyInArray(2)));
135 public function testGetMappedLicenseRefView()
137 $this->testDb =
new TestPgDb();
138 $this->testDb->createPlainTables(array(
'license_ref',
'license_map'));
139 $this->
dbManager = $this->testDb->getDbManager();
140 $this->
dbManager->queryOnce(
"CREATE TABLE license_candidate (group_fk integer) INHERITS (license_ref)");
141 $this->
dbManager->insertTableRow(
'license_map',array(
'license_map_pk'=>0,
'rf_fk'=>2,
'rf_parent'=>1,
'usage'=>LicenseMap::CONCLUSION));
142 $this->
dbManager->insertTableRow(
'license_ref',array(
'rf_pk'=>1,
'rf_shortname'=>
'One',
'rf_fullname'=>
'One-1',
'rf_spdx_id'=>
'One'));
143 $this->
dbManager->insertTableRow(
'license_ref',array(
'rf_pk'=>2,
'rf_shortname'=>
'Two',
'rf_fullname'=>
'Two-2',
'rf_spdx_id'=>
'Two'));
144 $this->
dbManager->insertTableRow(
'license_candidate',
145 array(
'rf_pk'=>3,
'rf_shortname'=>
'Three',
'rf_fullname'=>
'Three-3',
'group_fk'=>$this->groupId,
'rf_spdx_id'=>
'Three'));
146 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
154 assertThat($map,is(arrayWithSize(3)));
156 array(
'rf_origin'=>1,
'rf_pk'=>1,
'rf_shortname'=>
'One',
'rf_fullname'=>
'One-1',
'rf_spdx_id'=>
'One'),
157 array(
'rf_origin'=>2,
'rf_pk'=>1,
'rf_shortname'=>
'One',
'rf_fullname'=>
'One-1',
'rf_spdx_id'=>
'One'),
158 array(
'rf_origin'=>3,
'rf_pk'=>3,
'rf_shortname'=>
'Three',
'rf_fullname'=>
'Three-3',
'rf_spdx_id'=>
'Three')
160 assertThat($map,containsInAnyOrder($expected));
163 public function testFullMap()
165 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId+1, LicenseMap::CONCLUSION,
true);
166 $map = \Fossology\Lib\Test\Reflectory::getObjectsProperty($licenseMap,
'map');
167 assertThat($map,hasItemInArray(array(
'rf_fk'=>1,
'parent_shortname'=>
'One',
'parent_spdx_id'=>
'One',
'rf_parent'=>1,
'parent_fullname'=>
'One-1')));
168 assertThat($map,hasItemInArray(array(
'rf_fk'=>2,
'parent_shortname'=>
'One',
'parent_spdx_id'=>
'One',
'rf_parent'=>1,
'parent_fullname'=>
'One-1')));
171 public function testFullMapWithCandidates()
173 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId, LicenseMap::CONCLUSION,
true);
174 $map = \Fossology\Lib\Test\Reflectory::getObjectsProperty($licenseMap,
'map');
175 assertThat($map,hasItemInArray(array(
'rf_fk'=>1,
'parent_shortname'=>
'One',
'parent_spdx_id'=>
'One',
'rf_parent'=>1,
'parent_fullname'=>
'One-1')));
176 assertThat($map,hasItemInArray(array(
'rf_fk'=>2,
'parent_shortname'=>
'One',
'parent_spdx_id'=>
'One',
'rf_parent'=>1,
'parent_fullname'=>
'One-1')));
177 assertThat($map,hasItemInArray(array(
'rf_fk'=>3,
'parent_shortname'=>
'Three',
'parent_spdx_id'=>
'Three',
'rf_parent'=>3,
'parent_fullname'=>
'Three-3')));
static getMappedLicenseRefView($usageExpr=' $1')
Query to get license map view along with license ref.
fo_dbManager * dbManager
fo_dbManager object
Contains business rules for FOSSology.