36 protected function setUp():
void
39 $GLOBALS[
'SysConf'][
'auth'][
'UserId'] = 1;
40 $GLOBALS[
'SysConf'][
'auth'][
'GroupId'] = 1;
42 $this->
dbManager = M::mock(DbManager::class);
43 $this->userDao = M::mock(UserDao::class);
44 $this->licenseDao = M::mock(LicenseDao::class);
49 protected function tearDown():
void
59 $lic = M::mock(License::class);
60 $lic->shouldReceive(
'getId')->andReturn($id);
74 $spdxName =
'GPL-2.0-only';
78 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
84 $this->licenseDao->shouldNotReceive(
'insertLicense');
86 $this->
dbManager->shouldReceive(
'getSingleRow')
88 $this->
dbManager->shouldReceive(
'insertTableRow')->once();
90 $result = Reflectory::invokeObjectsMethodnameWith(
93 [$cpPk, $spdxName,
false]
96 $this->assertSame(1, $result[
'associated']);
97 $this->assertEmpty($result[
'failed']);
98 $this->assertEmpty($result[
'created']);
107 $spdxName =
'GPL-2.0-or-later';
110 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
115 $this->licenseDao->shouldNotReceive(
'insertLicense');
117 $this->
dbManager->shouldReceive(
'getSingleRow')->andReturn(
null);
118 $this->
dbManager->shouldReceive(
'insertTableRow')->once();
120 $result = Reflectory::invokeObjectsMethodnameWith(
123 [$cpPk, $spdxName,
false]
126 $this->assertSame(1, $result[
'associated']);
137 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
142 $this->
dbManager->shouldReceive(
'getSingleRow')->andReturn(
null);
143 $this->
dbManager->shouldReceive(
'insertTableRow')->once();
145 $result = Reflectory::invokeObjectsMethodnameWith(
148 [$cpPk,
' MIT ',
false]
151 $this->assertSame(1, $result[
'associated']);
161 $unknownLic =
'My-Custom-1.0';
163 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
164 ->with($unknownLic)->once()->andReturn(
null);
165 $this->licenseDao->shouldReceive(
'insertLicense')
166 ->with($unknownLic,
'',
null)->once()->andReturn(99);
167 $this->licenseDao->shouldReceive(
'getLicenseById')
168 ->with(99)->once()->andReturn($this->
makeLicense(99));
170 $this->
dbManager->shouldReceive(
'getSingleRow')->andReturn(
null);
171 $this->
dbManager->shouldReceive(
'insertTableRow')->once();
173 $result = Reflectory::invokeObjectsMethodnameWith(
176 [$cpPk, $unknownLic,
false,
true]
179 $this->assertSame(1, $result[
'associated']);
180 $this->assertContains($unknownLic, $result[
'created']);
191 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
192 ->with(
'MIT')->once()->andReturn($this->
makeLicense(1));
193 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
194 ->with(
'Apache-2.0')->once()->andReturn($this->
makeLicense(2));
196 $this->
dbManager->shouldReceive(
'getSingleRow')->andReturn(
null);
197 $this->
dbManager->shouldReceive(
'insertTableRow')->twice();
199 $result = Reflectory::invokeObjectsMethodnameWith(
202 [$cpPk,
'MIT, Apache-2.0',
false]
205 $this->assertSame(2, $result[
'associated']);
216 $text =
'This software is provided as-is.';
219 $this->
dbManager->shouldReceive(
'getSingleRow')
220 ->andReturn([
'cp_pk' => 1]);
223 $this->
dbManager->shouldNotReceive(
'insertPreparedAndReturn');
225 $result = Reflectory::invokeObjectsMethodnameWith(
227 'importSinglePhrase',
231 $this->assertFalse($result[
'success']);
232 $this->assertStringContainsString(
'Duplicate', $result[
'message']);
241 $result = Reflectory::invokeObjectsMethodnameWith(
243 'importSinglePhrase',
247 $this->assertFalse($result[
'success']);
248 $this->assertStringContainsString(
'required', strtolower($result[
'message']));
260 'Text' =>
'some phrase',
261 'Acknowledgement' =>
'ack text',
262 'Comments' =>
'a comment',
263 'Is Active' =>
'true',
264 'Licenses To Add' =>
'MIT',
265 'Licenses To Remove' =>
'GPL-2.0-only',
268 $mapped = Reflectory::invokeObjectsMethodnameWith(
274 $this->assertSame(
'some phrase', $mapped[
'text']);
275 $this->assertSame(
'ack text', $mapped[
'acknowledgement']);
276 $this->assertSame(
'a comment', $mapped[
'comments']);
277 $this->assertSame(
'true', $mapped[
'is_active']);
278 $this->assertSame(
'MIT', $mapped[
'licenses_to_add']);
279 $this->assertSame(
'GPL-2.0-only', $mapped[
'licenses_to_remove']);
290 'acknowledgement' =>
'',
291 'licenses_to_add' =>
'MIT',
292 'licenses_to_remove' =>
'',
295 $mapped = Reflectory::invokeObjectsMethodnameWith(
301 $this->assertSame(
'phrase', $mapped[
'text']);
302 $this->assertSame(
'MIT', $mapped[
'licenses_to_add']);
315 $result = Reflectory::invokeObjectsMethodnameWith(
320 $this->assertSame($expected, $result);
323 public function parseBooleanProvider(): array
350 $mapped = [
'acknowledgement' =>
'First note | Second note | Third note'];
352 $result = Reflectory::invokeObjectsMethodnameWith(
354 'normalizeBulkExportValues',
358 $this->assertSame(
'First note; Second note; Third note', $result[
'acknowledgement']);
367 $mapped = [
'acknowledgement' => [
'Note A',
'Note B']];
369 $result = Reflectory::invokeObjectsMethodnameWith(
371 'normalizeBulkExportValues',
375 $this->assertSame(
'Note A; Note B', $result[
'acknowledgement']);
384 $mapped = [
'text' =>
'line one\\nline two\\nline three'];
386 $result = Reflectory::invokeObjectsMethodnameWith(
388 'normalizeBulkExportValues',
392 $this->assertSame(
"line one\nline two\nline three", $result[
'text']);
404 $this->
dbManager->shouldReceive(
'getSingleRow')
405 ->with(M::pattern(
'/custom_phrase/'), M::any(), M::any())
407 $this->
dbManager->shouldReceive(
'insertPreparedAndReturn')
411 $result = $this->importer->importJsonData(
412 [[
'text' =>
'a unique phrase that is new']],
416 $this->assertStringContainsString(
'1', $result);
426 $result = $this->importer->importJsonData(
427 [[
'text' =>
''], [
'acknowledgement' =>
'orphan']],
432 $this->assertStringContainsString(
'0', $result);
Unit tests for CustomTextImport — covering the C2 fix and import logic (alias mapping,...
testAssociateLicensesLooksUpOrLaterNameDirectly()
testParseBoolean($input, bool $expected)
testImportPhrasesSkipsDuplicateText()
testImportJsonDataReturnsCountMessage()
testNormalizeBulkExportValuesPipeAcknowledgement()
testMapHeadersMapsLowerCaseNames()
testNormalizeBulkExportValuesRestoresNewlines()
testImportJsonDataSkipsRowsWithoutText()
testAutoCreatesUnknownValidLicense()
testAssociateLicensesTrimsWhitespace()
testAssociateLicensesHandlesCommaSeparatedList()
testAssociateLicensesLooksUpSpdxNameDirectly()
testMapHeadersMapsCapitalisedNames()
testNormalizeBulkExportValuesArrayAcknowledgement()
testImportPhraseRejectsEmptyText()
Import custom text phrases from CSV/JSON.
fo_dbManager * dbManager
fo_dbManager object
Utility functions for specific applications.