38 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
47 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
61 $testDb =
new TestPgDb(
"licenseCsvExport");
62 $testDb->createPlainTables(array(
'license_ref',
'license_map',
'groups'));
63 $testDb->createInheritedTables(array(
'license_candidate'));
64 $dbManager = $testDb->getDbManager();
66 $candLicenses = array();
67 $dbManager->insertTableRow(
'groups', array(
68 'group_pk' => 2,
'group_name' =>
'test' 70 for ($i = 1; $i < 4; $i ++) {
71 $licenses[$i] = array(
73 'rf_shortname' =>
'lic' . $i,
74 'rf_fullname' =>
'lice' . $i,
75 'rf_text' =>
'text' . $i,
77 'rf_notes' =>
'note' . $i,
78 'rf_source' =>
's' . $i,
79 'rf_detector_type' => 1,
82 $dbManager->insertTableRow(
'license_ref', $licenses[$i]);
84 for ($i = 1; $i <= 4; $i ++) {
85 $candLicenses[$i] = array(
87 'rf_shortname' =>
'candlic' . $i,
88 'rf_fullname' =>
'candlice' . $i,
89 'rf_text' =>
'text' . $i,
91 'rf_notes' =>
'note' . $i,
92 'rf_source' =>
's' . $i,
93 'rf_detector_type' => 1,
94 'rf_risk' => ($i - 1),
99 $candLicenses[$i][
'marydone'] =
true;
101 $dbManager->insertTableRow(
'license_candidate', $candLicenses[$i]);
104 $dbManager->insertTableRow(
'license_map', array(
'rf_fk'=>3,
'rf_parent'=>1,
'usage'=>LicenseMap::CONCLUSION));
105 $dbManager->insertTableRow(
'license_map', array(
'rf_fk'=>3,
'rf_parent'=>2,
'usage'=>LicenseMap::REPORT));
108 $head = array(
'shortname',
'fullname',
'text',
'parent_shortname',
'report_shortname',
'url',
'notes',
'source',
'risk',
'group');
109 $out = fopen(
'php://output',
'w');
111 $csv = $licenseCsvExport->createCsv();
113 fputcsv($out, $head);
114 fputcsv($out, array($licenses[1][
'rf_shortname'],
115 $licenses[1][
'rf_fullname'],
116 $licenses[1][
'rf_text'],
119 $licenses[1][
'rf_url'],
120 $licenses[1][
'rf_notes'],
121 $licenses[1][
'rf_source'],
122 $licenses[1][
'rf_risk'],
125 fputcsv($out, array($licenses[2][
'rf_shortname'],
126 $licenses[2][
'rf_fullname'],
127 $licenses[2][
'rf_text'],
130 $licenses[2][
'rf_url'],
131 $licenses[2][
'rf_notes'],
132 $licenses[2][
'rf_source'],
133 $licenses[2][
'rf_risk'],
136 fputcsv($out, array($licenses[3][
'rf_shortname'],
137 $licenses[3][
'rf_fullname'],
138 $licenses[3][
'rf_text'],
139 $licenses[1][
'rf_shortname'],
140 $licenses[2][
'rf_shortname'],
141 $licenses[3][
'rf_url'],
142 $licenses[3][
'rf_notes'],
143 $licenses[3][
'rf_source'],
144 $licenses[3][
'rf_risk'],
147 fputcsv($out, array($candLicenses[2][
'rf_shortname'],
148 $candLicenses[2][
'rf_fullname'],
149 $candLicenses[2][
'rf_text'],
152 $candLicenses[2][
'rf_url'],
153 $candLicenses[2][
'rf_notes'],
154 $candLicenses[2][
'rf_source'],
155 $candLicenses[2][
'rf_risk'],
158 fputcsv($out, array($candLicenses[4][
'rf_shortname'],
159 $candLicenses[4][
'rf_fullname'],
160 $candLicenses[4][
'rf_text'],
163 $candLicenses[4][
'rf_url'],
164 $candLicenses[4][
'rf_notes'],
165 $candLicenses[4][
'rf_source'],
166 $candLicenses[4][
'rf_risk'],
168 $expected = ob_get_contents();
171 assertThat($csv, is(equalTo($expected)));
174 $licenseCsvExport->setDelimiter($delimiter);
175 $csv3 = $licenseCsvExport->createCsv(3);
177 fputcsv($out, $head, $delimiter);
178 fputcsv($out, array($licenses[3][
'rf_shortname'],
179 $licenses[3][
'rf_fullname'],
180 $licenses[3][
'rf_text'],
181 $licenses[1][
'rf_shortname'],
182 $licenses[2][
'rf_shortname'],
183 $licenses[3][
'rf_url'],
184 $licenses[3][
'rf_notes'],
185 $licenses[3][
'rf_source'],
186 $licenses[3][
'rf_risk'],
190 $expected3 = ob_get_contents();
192 assertThat($csv3, is(equalTo($expected3)));
206 $dbManager = M::mock(DbManager::class);
208 $reflection = new \ReflectionClass($licenseCsvExport);
209 $delimiter = $reflection->getProperty(
'delimiter');
210 $delimiter->setAccessible(
true);
212 $licenseCsvExport->setDelimiter(
'|');
213 assertThat($delimiter->getValue($licenseCsvExport),is(
'|'));
215 $licenseCsvExport->setDelimiter(
'<>');
216 assertThat($delimiter->getValue($licenseCsvExport),is(
'<'));
230 $dbManager = M::mock(DbManager::class);
232 $reflection = new \ReflectionClass($licenseCsvExport);
233 $enclosure = $reflection->getProperty(
'enclosure');
234 $enclosure->setAccessible(
true);
236 $licenseCsvExport->setEnclosure(
'|');
237 assertThat($enclosure->getValue($licenseCsvExport),is(
'|'));
239 $licenseCsvExport->setEnclosure(
'<>');
240 assertThat($enclosure->getValue($licenseCsvExport),is(
'<'));
setUp()
One time setup for test.
Helper class to export license list as a CSV from the DB.
Utility functions for specific applications.
testCreateCsv()
Test for LicenseCsvExport::createCsv()
Test for class LicenseCsvExport.
testSetDelimiter()
Test for LicenseCsvExport::setDelimiter()
testSetEnclosure()
Test for LicenseCsvExport::setEnclosure()