From a8c475fbd7f645e05aa101e587c33dc4be11bd09 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 16 Dec 2021 14:34:17 +0100 Subject: [PATCH] Reflect TYPO3 behaviour in tests TYPO3 scheduler tasks always have a value for console commands. Region uid will be an empty string if omitted within scheduler task. We reflect that in our tests and adapt code to not break. Furthermore tests call only with strings, as that's what TYPO3 does. --- Classes/Command/DestinationDataImportCommand.php | 9 ++++++++- .../ImportCleansTransientFilesTest.php | 2 +- .../ImportDoesNotUseUploadsFolderTest.php | 2 +- .../DestinationDataTest/ImportsExampleAsExpectedTest.php | 4 ++-- .../ImportsWithoutRegionIfNotProvidedTest.php | 5 +++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Classes/Command/DestinationDataImportCommand.php b/Classes/Command/DestinationDataImportCommand.php index 537d4d6..a8a02d2 100644 --- a/Classes/Command/DestinationDataImportCommand.php +++ b/Classes/Command/DestinationDataImportCommand.php @@ -54,10 +54,17 @@ class DestinationDataImportCommand extends Command { Bootstrap::initializeBackendAuthentication(); + $regionUid = $input->getArgument('region-uid'); + if (is_numeric($regionUid)) { + $regionUid = (int) $regionUid; + } else { + $regionUid = null; + } + return $this->destinationDataImportService->import( $input->getArgument('rest-experience'), $input->getArgument('storage-pid'), - $input->getArgument('region-uid'), + $regionUid, $input->getArgument('files-folder') ); } diff --git a/Tests/Functional/Import/DestinationDataTest/ImportCleansTransientFilesTest.php b/Tests/Functional/Import/DestinationDataTest/ImportCleansTransientFilesTest.php index 24f73a2..21efcaa 100644 --- a/Tests/Functional/Import/DestinationDataTest/ImportCleansTransientFilesTest.php +++ b/Tests/Functional/Import/DestinationDataTest/ImportCleansTransientFilesTest.php @@ -35,7 +35,7 @@ class ImportCleansTransientFilesTest extends AbstractTest ]); $tester = $this->executeCommand([ - 'storage-pid' => 2, + 'storage-pid' => '2', 'rest-experience' => 'beispielstadt', 'files-folder' => $fileImportPath, ]); diff --git a/Tests/Functional/Import/DestinationDataTest/ImportDoesNotUseUploadsFolderTest.php b/Tests/Functional/Import/DestinationDataTest/ImportDoesNotUseUploadsFolderTest.php index e1ffb0a..a2c644c 100644 --- a/Tests/Functional/Import/DestinationDataTest/ImportDoesNotUseUploadsFolderTest.php +++ b/Tests/Functional/Import/DestinationDataTest/ImportDoesNotUseUploadsFolderTest.php @@ -36,7 +36,7 @@ class ImportDoesNotUseUploadsFolderTest extends AbstractTest ]); $tester = $this->executeCommand([ - 'storage-pid' => 2, + 'storage-pid' => '2', 'rest-experience' => 'beispielstadt', 'files-folder' => $fileImportPath, ]); diff --git a/Tests/Functional/Import/DestinationDataTest/ImportsExampleAsExpectedTest.php b/Tests/Functional/Import/DestinationDataTest/ImportsExampleAsExpectedTest.php index 89cd6d7..acaf5fa 100644 --- a/Tests/Functional/Import/DestinationDataTest/ImportsExampleAsExpectedTest.php +++ b/Tests/Functional/Import/DestinationDataTest/ImportsExampleAsExpectedTest.php @@ -36,10 +36,10 @@ class ImportsExampleAsExpectedTest extends AbstractTest ]); $tester = $this->executeCommand([ - 'storage-pid' => 2, + 'storage-pid' => '2', 'rest-experience' => 'beispielstadt', 'files-folder' => $fileImportPath, - 'region-uid' => 1, + 'region-uid' => '1', ]); self::assertSame(0, $tester->getStatusCode()); diff --git a/Tests/Functional/Import/DestinationDataTest/ImportsWithoutRegionIfNotProvidedTest.php b/Tests/Functional/Import/DestinationDataTest/ImportsWithoutRegionIfNotProvidedTest.php index e98b136..e383e79 100644 --- a/Tests/Functional/Import/DestinationDataTest/ImportsWithoutRegionIfNotProvidedTest.php +++ b/Tests/Functional/Import/DestinationDataTest/ImportsWithoutRegionIfNotProvidedTest.php @@ -8,7 +8,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; /** * @testdox DestinationData import */ -class ImportsWithoutRegionIfNotProvided extends AbstractTest +class ImportsWithoutRegionIfNotProvidedTest extends AbstractTest { /** * @test @@ -33,9 +33,10 @@ class ImportsWithoutRegionIfNotProvided extends AbstractTest new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''), ]); $tester = $this->executeCommand([ - 'storage-pid' => 2, + 'storage-pid' => '2', 'rest-experience' => 'beispielstadt', 'files-folder' => $fileImportPath, + 'region-uid' => '', ]); self::assertSame(0, $tester->getStatusCode());