16 public $assertCountBefore;
27 protected function setUp() : void
30 $this->testDb->createPlainTables(
36 'obligation_candidate_map'
38 $this->
dbManager = $this->testDb->getDbManager();
39 $this->
dbManager->queryOnce(
"CREATE TABLE license_candidate (group_fk integer) INHERITS (license_ref)");
40 $this->
dbManager->insertTableRow(
'license_map',array(
'license_map_pk'=>0,
'rf_fk'=>2,
'rf_parent'=>1,
'usage'=>LicenseMap::CONCLUSION));
41 $this->
dbManager->insertTableRow(
'license_ref',array(
'rf_pk'=>1,
'rf_shortname'=>
'One',
'rf_fullname'=>
'One-1',
'rf_spdx_id'=>
'One'));
42 $this->
dbManager->insertTableRow(
'license_ref',array(
'rf_pk'=>2,
'rf_shortname'=>
'Two',
'rf_fullname'=>
'Two-2',
'rf_spdx_id'=>
'Two'));
43 $this->
dbManager->insertTableRow(
'license_candidate',
44 array(
'rf_pk'=>3,
'rf_shortname'=>
'Three',
'rf_fullname'=>
'Three-3',
'group_fk'=>$this->groupId,
'rf_spdx_id'=>
'Three'));
45 $this->
dbManager->insertTableRow(
'obligation_ref',
48 'ob_type' =>
'Obligation',
49 'ob_topic' =>
'Obligation-1',
50 'ob_text' =>
'Obligation text',
51 'ob_classification' =>
'white',
52 'ob_modifications' =>
'Yes',
53 'ob_comment' =>
'Obligation comment',
55 'ob_text_updatable' =>
false,
56 'ob_md5' =>
'0ffdddc657a16b95894437b4af736102'
58 $this->
dbManager->insertTableRow(
'obligation_map',
64 $this->
dbManager->insertTableRow(
'obligation_candidate_map',
70 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
73 protected function tearDown() : void
75 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
78 function testProjectedIdOfUnmappedIdIsIdItself()
80 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId);
82 assertThat($licenseMap->getProjectedId($licenseId),is($licenseId));
85 function testProjectedIdOfCandidatesAreRecognized()
87 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId);
89 assertThat($licenseMap->getProjectedId($licenseId),is($licenseId));
92 function testProjectedIdOfUnmappedIdIsParentId()
94 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId);
95 $licenseMap->getGroupId();
96 assertThat($licenseMap->getProjectedId(2),is(1));
99 function testProjectedShortNameOfMappedId()
101 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId);
102 assertThat($licenseMap->getProjectedShortName(2),is(
'One'));
105 function testObligationForLicense()
107 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId);
108 assertThat($licenseMap->getObligationsForLicenseRef(2), contains(2));
111 function testObligationForUnassignedLicense()
113 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId);
114 assertThat($licenseMap->getObligationsForLicenseRef(1), is(emptyArray()));
117 function testObligationForCandidateLicense()
119 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId);
120 assertThat($licenseMap->getObligationsForLicenseRef(3,
true), contains(2));
123 function testProjectedIdOfMappedIdIsIdItselfIfTrivialMap()
125 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId, LicenseMap::TRIVIAL);
126 assertThat($licenseMap->getProjectedId(2),is(2));
129 function testGetTopLevelLicenseRefs()
131 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId, LicenseMap::CONCLUSION);
132 $topLevelLicenses = $licenseMap->getTopLevelLicenseRefs();
133 assertThat($topLevelLicenses,hasItemInArray(
new LicenseRef(1,
'One',
'One-1',
'One')));
134 assertThat($topLevelLicenses, not(hasKeyInArray(2)));
138 public function testGetMappedLicenseRefView()
140 $this->testDb =
new TestPgDb();
141 $this->testDb->createPlainTables(array(
'license_ref',
'license_map'));
142 $this->
dbManager = $this->testDb->getDbManager();
143 $this->
dbManager->queryOnce(
"CREATE TABLE license_candidate (group_fk integer) INHERITS (license_ref)");
144 $this->
dbManager->insertTableRow(
'license_map',array(
'license_map_pk'=>0,
'rf_fk'=>2,
'rf_parent'=>1,
'usage'=>LicenseMap::CONCLUSION));
145 $this->
dbManager->insertTableRow(
'license_ref',array(
'rf_pk'=>1,
'rf_shortname'=>
'One',
'rf_fullname'=>
'One-1',
'rf_spdx_id'=>
'One'));
146 $this->
dbManager->insertTableRow(
'license_ref',array(
'rf_pk'=>2,
'rf_shortname'=>
'Two',
'rf_fullname'=>
'Two-2',
'rf_spdx_id'=>
'Two'));
147 $this->
dbManager->insertTableRow(
'license_candidate',
148 array(
'rf_pk'=>3,
'rf_shortname'=>
'Three',
'rf_fullname'=>
'Three-3',
'group_fk'=>$this->groupId,
'rf_spdx_id'=>
'Three'));
149 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
157 assertThat($map,is(arrayWithSize(3)));
159 array(
'rf_origin'=>1,
'rf_pk'=>1,
'rf_shortname'=>
'One',
'rf_fullname'=>
'One-1',
'rf_spdx_id'=>
'One'),
160 array(
'rf_origin'=>2,
'rf_pk'=>1,
'rf_shortname'=>
'One',
'rf_fullname'=>
'One-1',
'rf_spdx_id'=>
'One'),
161 array(
'rf_origin'=>3,
'rf_pk'=>3,
'rf_shortname'=>
'Three',
'rf_fullname'=>
'Three-3',
'rf_spdx_id'=>
'Three')
163 assertThat($map,containsInAnyOrder($expected));
166 public function testFullMap()
168 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId+1, LicenseMap::CONCLUSION,
true);
169 $map = \Fossology\Lib\Test\Reflectory::getObjectsProperty($licenseMap,
'map');
170 assertThat($map,hasItemInArray(array(
'rf_fk'=>1,
'parent_shortname'=>
'One',
'parent_spdx_id'=>
'One',
'rf_parent'=>1,
'parent_fullname'=>
'One-1')));
171 assertThat($map,hasItemInArray(array(
'rf_fk'=>2,
'parent_shortname'=>
'One',
'parent_spdx_id'=>
'One',
'rf_parent'=>1,
'parent_fullname'=>
'One-1')));
174 public function testFullMapWithCandidates()
176 $licenseMap =
new LicenseMap($this->
dbManager, $this->groupId, LicenseMap::CONCLUSION,
true);
177 $map = \Fossology\Lib\Test\Reflectory::getObjectsProperty($licenseMap,
'map');
178 assertThat($map,hasItemInArray(array(
'rf_fk'=>1,
'parent_shortname'=>
'One',
'parent_spdx_id'=>
'One',
'rf_parent'=>1,
'parent_fullname'=>
'One-1')));
179 assertThat($map,hasItemInArray(array(
'rf_fk'=>2,
'parent_shortname'=>
'One',
'parent_spdx_id'=>
'One',
'rf_parent'=>1,
'parent_fullname'=>
'One-1')));
180 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.