Test for class CustomTextImport.
More...
|
|
static | parseBooleanProvider () |
| |
|
|
| makeLicense (int $id) |
| |
|
| writeTempFile (string $content, string $ext) |
| |
| | markAsCsvSource () |
| |
|
|
| $assertCountBefore |
| |
|
| $dbManager |
| |
|
| $userDao |
| |
|
| $licenseDao |
| |
|
| $importer |
| |
|
| $tmpFiles = [] |
| |
Test for class CustomTextImport.
Definition at line 21 of file CustomTextImportTest.php.
◆ markAsCsvSource()
| Fossology\Lib\Application\CustomTextImportTest::markAsCsvSource |
( |
| ) |
|
|
private |
Force mapHeaders()/importSinglePhrase() into "CSV source" mode without going through a real file.
Definition at line 88 of file CustomTextImportTest.php.
◆ testAssociateLicenseNamesHandlesCommaSeparatedList()
| Fossology\Lib\Application\CustomTextImportTest::testAssociateLicenseNamesHandlesCommaSeparatedList |
( |
| ) |
|
◆ testAssociateLicenseNamesLooksUpSpdxNameDirectly()
| Fossology\Lib\Application\CustomTextImportTest::testAssociateLicenseNamesLooksUpSpdxNameDirectly |
( |
| ) |
|
◆ testAssociateLicenseNamesReportsUnknownLicense()
| Fossology\Lib\Application\CustomTextImportTest::testAssociateLicenseNamesReportsUnknownLicense |
( |
| ) |
|
◆ testAssociateLicensesCountsExistingMappingAsSkippedNotInserted()
| Fossology\Lib\Application\CustomTextImportTest::testAssociateLicensesCountsExistingMappingAsSkippedNotInserted |
( |
| ) |
|
- Test:
- Associate a license that is already mapped to the phrase.
- Verify it is counted as 'skipped', never 'inserted'. Regression: counting an already-existing mapping as "associated" made a duplicate re-import falsely report new licenses added.
Definition at line 341 of file CustomTextImportTest.php.
◆ testAssociateLicensesHandlesMissingMetadataKeysWithoutWarning()
| Fossology\Lib\Application\CustomTextImportTest::testAssociateLicensesHandlesMissingMetadataKeysWithoutWarning |
( |
| ) |
|
- Test:
- Associate a license whose metadata fields are entirely absent from the entry.
- Verify no "Undefined array key" warning is triggered and NULLs are inserted.
Definition at line 364 of file CustomTextImportTest.php.
◆ testAssociateLicensesPassesGroupIdForCandidateResolution()
| Fossology\Lib\Application\CustomTextImportTest::testAssociateLicensesPassesGroupIdForCandidateResolution |
( |
| ) |
|
◆ testAssociateLicensesUsesConstantStatementNameForMappingCheck()
| Fossology\Lib\Application\CustomTextImportTest::testAssociateLicensesUsesConstantStatementNameForMappingCheck |
( |
| ) |
|
- Test:
- Associate the same (cpPk, licenseId) pair via two different entries.
- Verify both mapping-existence checks share a single, constant prepared-statement name rather than one name per pair. Regression: embedding cpPk/licenseId in the statement name creates one server-side prepared statement per row on a large import.
Definition at line 306 of file CustomTextImportTest.php.
◆ testHandleCsvFileCreatesSinglePhrase()
| Fossology\Lib\Application\CustomTextImportTest::testHandleCsvFileCreatesSinglePhrase |
( |
| ) |
|
◆ testHandleCsvFileMultiLicenseSameTextUpdatesExisting()
| Fossology\Lib\Application\CustomTextImportTest::testHandleCsvFileMultiLicenseSameTextUpdatesExisting |
( |
| ) |
|
- Test:
- Write a CSV with 3 rows sharing the same text (one phrase, 3 licenses). This mirrors the output of BulkTextExport for a phrase with 3 license mappings.
- Row 1 creates the phrase and associates GPL-2.0-or-later.
- Rows 2 and 3 detect the duplicate text and add LGPL-2.1-or-later / MPL-1.1+.
- Verify message: "1 phrase(s) created, 2 license(s) added to existing phrase(s)".
Definition at line 901 of file CustomTextImportTest.php.
◆ testHandleCsvFileRejectsColumnCountMismatch()
| Fossology\Lib\Application\CustomTextImportTest::testHandleCsvFileRejectsColumnCountMismatch |
( |
| ) |
|
- Test:
- Write a CSV where a data row has fewer columns than the header.
- Verify handleFile returns a column-count error message without importing.
Definition at line 943 of file CustomTextImportTest.php.
◆ testHandleCsvFileUnescapesNewlinesInText()
| Fossology\Lib\Application\CustomTextImportTest::testHandleCsvFileUnescapesNewlinesInText |
( |
| ) |
|
- Test:
- Write a CSV where the phrase text contains a literal backslash-n two-character sequence (as BulkTextExport would have flattened a real newline into).
- Verify the imported phrase text has a real newline, not '
' text.
Definition at line 964 of file CustomTextImportTest.php.
◆ testHandleJsonFileCreatesTwoPhrases()
| Fossology\Lib\Application\CustomTextImportTest::testHandleJsonFileCreatesTwoPhrases |
( |
| ) |
|
- Test:
- Write a JSON file with two independent phrases in nested licenses[] format.
- Verify handleFile creates 2 phrases.
Definition at line 994 of file CustomTextImportTest.php.
◆ testHandleJsonFileRejectsInvalidJson()
| Fossology\Lib\Application\CustomTextImportTest::testHandleJsonFileRejectsInvalidJson |
( |
| ) |
|
- Test:
- Write a JSON file whose content is not valid JSON.
- Verify handleFile returns an error message containing "Invalid JSON".
Definition at line 1029 of file CustomTextImportTest.php.
◆ testHandleJsonFileRejectsNonArrayRoot()
| Fossology\Lib\Application\CustomTextImportTest::testHandleJsonFileRejectsNonArrayRoot |
( |
| ) |
|
- Test:
- Write a JSON file whose top-level value is a scalar (not an array).
- Verify handleFile returns a "must contain an array" error.
Definition at line 1043 of file CustomTextImportTest.php.
◆ testHandleJsonFileSameTextTwiceAddsLicenseToExisting()
| Fossology\Lib\Application\CustomTextImportTest::testHandleJsonFileSameTextTwiceAddsLicenseToExisting |
( |
| ) |
|
- Test:
- Import a JSON phrase where the same text appears twice in the array but row 2 carries a new license.
- Verify: 1 phrase(s) created, 1 license(s) added to existing phrase(s).
Definition at line 1058 of file CustomTextImportTest.php.
◆ testImportPhrasesEmptyDataReportsNothingNewToImport()
| Fossology\Lib\Application\CustomTextImportTest::testImportPhrasesEmptyDataReportsNothingNewToImport |
( |
| ) |
|
◆ testImportPhrasesOneMalformedRowDoesNotAbortRemainingRows()
| Fossology\Lib\Application\CustomTextImportTest::testImportPhrasesOneMalformedRowDoesNotAbortRemainingRows |
( |
| ) |
|
- Test:
- Import a batch where row 2's text is an array (malformed).
- Verify row 1 and row 3 still succeed and row 2 is reported as an error, instead of a crash aborting the whole batch.
Definition at line 536 of file CustomTextImportTest.php.
◆ testImportPhrasesProducesCorrectCountMessage()
| Fossology\Lib\Application\CustomTextImportTest::testImportPhrasesProducesCorrectCountMessage |
( |
| ) |
|
- Test:
- Import two rows that share the same text but carry different, not-yet-mapped licenses.
- Row 1: new phrase created + MIT associated.
- Row 2: same text, existing phrase, Apache-2.0 added.
- Verify message is "1 phrase(s) created, 1 license(s) added to existing phrase(s)".
Definition at line 716 of file CustomTextImportTest.php.
◆ testImportPhrasesReportsErrorRowsAlongSideSuccesses()
| Fossology\Lib\Application\CustomTextImportTest::testImportPhrasesReportsErrorRowsAlongSideSuccesses |
( |
| ) |
|
- Test:
- Import a mix: one valid new phrase and one row with empty text.
- Verify the message includes "1 phrase(s) created" AND an error for the empty row.
Definition at line 796 of file CustomTextImportTest.php.
◆ testImportPhrasesReportsUnchangedRowsSeparately()
| Fossology\Lib\Application\CustomTextImportTest::testImportPhrasesReportsUnchangedRowsSeparately |
( |
| ) |
|
- Test:
- Import one row where the text already exists and carries no new licenses.
- Verify the result reports it under "already up to date", not as an error, and the overall summary still reads "nothing new to import" isn't used once there is at least one unchanged row to report.
Definition at line 760 of file CustomTextImportTest.php.
◆ testImportSinglePhraseCreatesNewPhrase()
| Fossology\Lib\Application\CustomTextImportTest::testImportSinglePhraseCreatesNewPhrase |
( |
| ) |
|
- Test:
- Provide a unique phrase (no text_md5 match in DB).
- Verify importSinglePhrase inserts the phrase and returns success=true, not existing/unchanged.
Definition at line 566 of file CustomTextImportTest.php.
◆ testImportSinglePhraseOnDuplicateTextWithAlreadyMappedLicenseIsUnchanged()
| Fossology\Lib\Application\CustomTextImportTest::testImportSinglePhraseOnDuplicateTextWithAlreadyMappedLicenseIsUnchanged |
( |
| ) |
|
- Test:
- Simulate a duplicate text whose only license is ALREADY mapped.
- Verify the row is reported as success=true, unchanged=true (not an error). This is the fix for re-importing the same export twice: it must be a safe no-op, not misreported as either a failure or a fresh update.
Definition at line 624 of file CustomTextImportTest.php.
◆ testImportSinglePhraseOnDuplicateTextWithNewLicenseAddsToExisting()
| Fossology\Lib\Application\CustomTextImportTest::testImportSinglePhraseOnDuplicateTextWithNewLicenseAddsToExisting |
( |
| ) |
|
- Test:
- Simulate a duplicate text (existing row in custom_phrase).
- Include a license not yet mapped to that phrase.
- Verify the license is associated with the existing phrase (success=true, existing=true).
Definition at line 587 of file CustomTextImportTest.php.
◆ testImportSinglePhraseOnDuplicateTextWithNoLicenseIsUnchanged()
| Fossology\Lib\Application\CustomTextImportTest::testImportSinglePhraseOnDuplicateTextWithNoLicenseIsUnchanged |
( |
| ) |
|
- Test:
- Simulate a duplicate text with no license payload at all.
- Verify success=true, unchanged=true (not a failure).
Definition at line 660 of file CustomTextImportTest.php.
◆ testImportSinglePhraseOnDuplicateTextWithUnknownLicenseFails()
| Fossology\Lib\Application\CustomTextImportTest::testImportSinglePhraseOnDuplicateTextWithUnknownLicenseFails |
( |
| ) |
|
- Test:
- Simulate a duplicate text whose license entry fails to resolve (unknown license).
- Verify success=false with the unknown license named in the message.
Definition at line 683 of file CustomTextImportTest.php.
◆ testImportSinglePhraseRejectsArrayText()
| Fossology\Lib\Application\CustomTextImportTest::testImportSinglePhraseRejectsArrayText |
( |
| ) |
|
- Test:
- Call importSinglePhrase with 'text' as a JSON array instead of a string (e.g. a hand-edited or malformed import file).
- Verify it returns a clean success=false result instead of an uncaught TypeError from md5(), and never opens a transaction.
Definition at line 469 of file CustomTextImportTest.php.
◆ testImportSinglePhraseRejectsEmptyText()
| Fossology\Lib\Application\CustomTextImportTest::testImportSinglePhraseRejectsEmptyText |
( |
| ) |
|
- Test:
- Call importSinglePhrase with an empty text field.
- Verify it returns success=false without touching the DB.
Definition at line 449 of file CustomTextImportTest.php.
◆ testImportSinglePhraseSkipsLicenseEntryWithArrayShortname()
| Fossology\Lib\Application\CustomTextImportTest::testImportSinglePhraseSkipsLicenseEntryWithArrayShortname |
( |
| ) |
|
- Test:
- One license entry carries an array 'shortname' instead of a string.
- Verify the malformed entry is dropped (not passed to trim()) and the phrase itself still imports successfully instead of crashing.
Definition at line 488 of file CustomTextImportTest.php.
◆ testImportSinglePhraseTreatsArrayIsActiveAsFalse()
| Fossology\Lib\Application\CustomTextImportTest::testImportSinglePhraseTreatsArrayIsActiveAsFalse |
( |
| ) |
|
- Test:
- 'is_active' arrives as a JSON array instead of a boolean/string.
- Verify parseBoolean() treats it as false instead of crashing trim().
Definition at line 513 of file CustomTextImportTest.php.
◆ testMapHeadersBuildsLicensesArrayFromFlatCsvRow()
| Fossology\Lib\Application\CustomTextImportTest::testMapHeadersBuildsLicensesArrayFromFlatCsvRow |
( |
| ) |
|
◆ testMapHeadersDoesNotUnescapeForJsonSource()
| Fossology\Lib\Application\CustomTextImportTest::testMapHeadersDoesNotUnescapeForJsonSource |
( |
| ) |
|
- Test:
- Leave the importer in JSON mode (unescapeNewlines = false, the default).
- Pass text containing a literal backslash-n two-character sequence (e.g. from source code, not an export-time escape).
- Verify mapHeaders leaves it untouched. Regression: unescaping unconditionally would corrupt any JSON-sourced phrase whose real content contains the two characters '\' 'n'.
Definition at line 197 of file CustomTextImportTest.php.
◆ testMapHeadersParsesRemovingLeniently()
| Fossology\Lib\Application\CustomTextImportTest::testMapHeadersParsesRemovingLeniently |
( |
| ) |
|
- Test:
- Build a row with 'Removing' set to a non-literal-"true" truthy value ('1').
- Verify it is still parsed as a remove mapping. Regression: the old code only recognised the exact string "true"; "1"/"yes"/"t" silently became an add mapping instead of a remove.
Definition at line 133 of file CustomTextImportTest.php.
◆ testMapHeadersPassesThroughNestedLicensesArray()
| Fossology\Lib\Application\CustomTextImportTest::testMapHeadersPassesThroughNestedLicensesArray |
( |
| ) |
|
◆ testMapHeadersRestoresEscapedNewlinesForCsvSource()
| Fossology\Lib\Application\CustomTextImportTest::testMapHeadersRestoresEscapedNewlinesForCsvSource |
( |
| ) |
|
- Test:
- Mark the importer as reading a CSV source (unescapeNewlines = true).
- Pass a text value containing literal
escape sequences (as written by BulkTextExport).
- Verify mapHeaders restores them to real newlines.
Definition at line 176 of file CustomTextImportTest.php.
◆ testMapHeadersUnescapesLicenseMetadataForCsvSource()
| Fossology\Lib\Application\CustomTextImportTest::testMapHeadersUnescapesLicenseMetadataForCsvSource |
( |
| ) |
|
- Test:
- Mark the importer as CSV source.
- Pass per-license comment/reportinfo/acknowledgement containing escaped newlines.
- Verify all three are unescaped, not just the phrase text.
Definition at line 214 of file CustomTextImportTest.php.
◆ testParseBoolean()
| Fossology\Lib\Application\CustomTextImportTest::testParseBoolean |
( |
|
$input, |
|
|
bool |
$expected |
|
) |
| |
- Test:
- Call parseBoolean with various truthy and falsy string/bool values.
- Verify each maps to the expected bool.
@dataProvider parseBooleanProvider
Definition at line 244 of file CustomTextImportTest.php.
◆ testReimportingSameDataIsIdempotentAndReportedAsUnchanged()
| Fossology\Lib\Application\CustomTextImportTest::testReimportingSameDataIsIdempotentAndReportedAsUnchanged |
( |
| ) |
|
- Test:
- Re-import the exact same single-phrase, single-license dataset twice in a row (simulating "download export, re-upload unmodified").
- Verify the second import reports 1 unchanged row and 0 created/updated.
Definition at line 820 of file CustomTextImportTest.php.
The documentation for this class was generated from the following file: