26 protected function setUp() : void
28 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
37 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
51 $testDb =
new TestPgDb(
"licenseCsvExport");
52 $testDb->createPlainTables(array(
'license_ref',
'license_map',
'groups',
'obligation_ref',
'obligation_map'));
53 $testDb->createInheritedTables(array(
'license_candidate'));
54 $dbManager = $testDb->getDbManager();
56 $candLicenses = array();
57 $dbManager->insertTableRow(
'groups', array(
58 'group_pk' => 2,
'group_name' =>
'test'
60 for ($i = 1; $i < 4; $i ++) {
61 $licenses[$i] = array(
63 'rf_shortname' =>
'lic' . $i,
64 'rf_spdx_id' =>
'lrf-lic' . $i,
65 'rf_licensetype' =>
'lictype' . $i,
66 'rf_fullname' =>
'lice' . $i,
67 'rf_text' =>
'text' . $i,
69 'rf_notes' =>
'note' . $i,
70 'rf_source' =>
's' . $i,
71 'rf_detector_type' => 1,
74 $dbManager->insertTableRow(
'license_ref', $licenses[$i]);
76 for ($i = 1; $i <= 4; $i ++) {
77 $candLicenses[$i] = array(
79 'rf_shortname' =>
'candlic' . $i,
80 'rf_licensetype' =>
'lictype' . $i,
81 'rf_fullname' =>
'candlice' . $i,
83 'rf_text' =>
'text' . $i,
85 'rf_notes' =>
'note' . $i,
86 'rf_source' =>
's' . $i,
87 'rf_detector_type' => 1,
88 'rf_risk' => ($i - 1),
93 $candLicenses[$i][
'marydone'] =
true;
95 $dbManager->insertTableRow(
'license_candidate', $candLicenses[$i]);
98 $dbManager->insertTableRow(
'license_map', array(
'rf_fk'=>3,
'rf_parent'=>1,
'usage'=>LicenseMap::CONCLUSION));
99 $dbManager->insertTableRow(
'license_map', array(
'rf_fk'=>3,
'rf_parent'=>2,
'usage'=>LicenseMap::REPORT));
102 $head = array(
'shortname',
'fullname',
'spdx_id',
'licensetype',
'text',
'parent_shortname',
'report_shortname',
'url',
'notes',
'source',
'risk',
'group',
'obligations');
103 $out = fopen(
'php://output',
'w');
105 $csv = $licenseCsvExport->createCsv();
107 fputs($out, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) ));
108 fputcsv($out, $head);
109 fputcsv($out, array($licenses[1][
'rf_shortname'],
110 $licenses[1][
'rf_fullname'],
111 $licenses[1][
'rf_spdx_id'],
112 $licenses[1][
'rf_licensetype'],
113 $licenses[1][
'rf_text'],
116 $licenses[1][
'rf_url'],
117 $licenses[1][
'rf_notes'],
118 $licenses[1][
'rf_source'],
119 $licenses[1][
'rf_risk'],
122 fputcsv($out, array($licenses[2][
'rf_shortname'],
123 $licenses[2][
'rf_fullname'],
124 $licenses[2][
'rf_spdx_id'],
125 $licenses[2][
'rf_licensetype'],
126 $licenses[2][
'rf_text'],
129 $licenses[2][
'rf_url'],
130 $licenses[2][
'rf_notes'],
131 $licenses[2][
'rf_source'],
132 $licenses[2][
'rf_risk'],
135 fputcsv($out, array($licenses[3][
'rf_shortname'],
136 $licenses[3][
'rf_fullname'],
137 $licenses[3][
'rf_spdx_id'],
138 $licenses[3][
'rf_licensetype'],
139 $licenses[3][
'rf_text'],
140 $licenses[1][
'rf_shortname'],
141 $licenses[2][
'rf_shortname'],
142 $licenses[3][
'rf_url'],
143 $licenses[3][
'rf_notes'],
144 $licenses[3][
'rf_source'],
145 $licenses[3][
'rf_risk'],
148 fputcsv($out, array($candLicenses[2][
'rf_shortname'],
149 $candLicenses[2][
'rf_fullname'],
151 $candLicenses[2][
'rf_licensetype'],
152 $candLicenses[2][
'rf_text'],
155 $candLicenses[2][
'rf_url'],
156 $candLicenses[2][
'rf_notes'],
157 $candLicenses[2][
'rf_source'],
158 $candLicenses[2][
'rf_risk'],
161 fputcsv($out, array($candLicenses[4][
'rf_shortname'],
162 $candLicenses[4][
'rf_fullname'],
164 $candLicenses[4][
'rf_licensetype'],
165 $candLicenses[4][
'rf_text'],
168 $candLicenses[4][
'rf_url'],
169 $candLicenses[4][
'rf_notes'],
170 $candLicenses[4][
'rf_source'],
171 $candLicenses[4][
'rf_risk'],
173 $expected = ob_get_contents();
176 assertThat($csv, is(equalTo($expected)));
179 $licenseCsvExport->setDelimiter($delimiter);
180 $csv3 = $licenseCsvExport->createCsv(3);
182 fputs($out, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) ));
183 fputcsv($out, $head, $delimiter);
184 fputcsv($out, array($licenses[3][
'rf_shortname'],
185 $licenses[3][
'rf_fullname'],
186 $licenses[3][
'rf_spdx_id'],
187 $licenses[3][
'rf_licensetype'],
188 $licenses[3][
'rf_text'],
189 $licenses[1][
'rf_shortname'],
190 $licenses[2][
'rf_shortname'],
191 $licenses[3][
'rf_url'],
192 $licenses[3][
'rf_notes'],
193 $licenses[3][
'rf_source'],
194 $licenses[3][
'rf_risk'],
198 $expected3 = ob_get_contents();
200 assertThat($csv3, is(equalTo($expected3)));
214 $dbManager = M::mock(DbManager::class);
216 $reflection = new \ReflectionClass($licenseCsvExport);
217 $delimiter = $reflection->getProperty(
'delimiter');
218 $delimiter->setAccessible(
true);
220 $licenseCsvExport->setDelimiter(
'|');
221 assertThat($delimiter->getValue($licenseCsvExport),is(
'|'));
223 $licenseCsvExport->setDelimiter(
'<>');
224 assertThat($delimiter->getValue($licenseCsvExport),is(
'<'));
238 $dbManager = M::mock(DbManager::class);
240 $reflection = new \ReflectionClass($licenseCsvExport);
241 $enclosure = $reflection->getProperty(
'enclosure');
242 $enclosure->setAccessible(
true);
244 $licenseCsvExport->setEnclosure(
'|');
245 assertThat($enclosure->getValue($licenseCsvExport),is(
'|'));
247 $licenseCsvExport->setEnclosure(
'<>');
248 assertThat($enclosure->getValue($licenseCsvExport),is(
'<'));
Test for class LicenseCsvExport.
testCreateCsv()
Test for LicenseCsvExport::createCsv()
setUp()
One time setup for test.
testSetDelimiter()
Test for LicenseCsvExport::setDelimiter()
testSetEnclosure()
Test for LicenseCsvExport::setEnclosure()
Helper class to export license list as a CSV from the DB.
Wrapper class for license map.
static convertToSpdxId($shortname, $spdxId)
Given a license's shortname and spdx id, give out spdx id to use in reports.
Utility functions for specific applications.