events/Tests/Functional/Import/DestinationDataTest/ImportHandlesImagesTest.php
Daniel Siepmann (Codappix) 5f6c6eef0e
Handle destination.one files without file name. (#68)
It is possible to have files such as
`https://dam.destination.one/2675868/3dc0a9dccd0dad46c73e669ece428c634ff8324ea3d01a4858a1c43169deed41/.jpg`.
Those were not handled correctly yet.
We now also handle those cases.
We will generate a hash from the URL as file name in order to still use those files.

Relates: #11396
2024-09-17 11:04:22 +02:00

251 lines
10 KiB
PHP

<?php
namespace Wrm\Events\Tests\Functional\Import\DestinationDataTest;
use GuzzleHttp\Psr7\Response;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* @testdox DestinationData import
*/
class ImportHandlesImagesTest extends AbstractTest
{
protected function setUp(): void
{
// Ensure proper type mapping within tests.
// Do not use system magic as this might be different within CI and somewhere else.
$this->configurationToUseInTestInstance['SYS']['FileInfo']['fileExtensionToMimeType']['jpg'] = 'image/jpg';
parent::setUp();
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/DefaultImportConfiguration.php');
$this->setUpConfiguration([
'restUrl = https://example.com/some-path/',
'license = example-license',
'restType = Event',
'restLimit = 3',
'restMode = next_months,12',
'restTemplate = ET2014A.json',
]);
}
/**
* @test
*/
public function addsNewImages(): void
{
$this->setUpResponses([
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithNewImages.json') ?: ''),
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''),
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''),
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''),
]);
$this->executeCommand();
$this->assertPHPDataSet(__DIR__ . '/Assertions/ImportHandlesImagesAddsNewImages.php');
$importedFiles = GeneralUtility::getFilesInDir($this->fileImportPath);
self::assertIsArray($importedFiles, 'Failed to retrieve imported files from filesystem.');
self::assertSame(
[
'lutherkirche-jpg.jpg',
'theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg',
'tueftlerzeit-sfz-rudolstadt-jpg.jpg',
],
array_values($importedFiles),
'Got unexpected number of files'
);
$this->assertEmptyLog();
}
/**
* @test
*/
public function addsNewImageWithoutFileName(): void
{
$this->setUpResponses([
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithNewImageWithoutFileName.json') ?: ''),
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''),
]);
$this->executeCommand();
$this->assertPHPDataSet(__DIR__ . '/Assertions/ImportHandlesImageWithoutFileName.php');
$importedFiles = GeneralUtility::getFilesInDir($this->fileImportPath);
self::assertIsArray($importedFiles, 'Failed to retrieve imported files from filesystem.');
self::assertSame(
[
'bf126089c94f95031fa07bf9d7d9b10c3e58aafebdef31f0b60604da13019b8d.jpg',
],
array_values($importedFiles),
'Got unexpected number of files'
);
$this->assertEmptyLog();
}
/**
* @test
*/
public function addsMultipleImagesToSingleEvent(): void
{
$this->setUpResponses([
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithMultipleImagesForSingleEvent.json') ?: ''),
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''),
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''),
]);
$this->executeCommand();
$this->assertPHPDataSet(__DIR__ . '/Assertions/ImportHandlesImagesAddsMultipleImagestoSingleEvent.php');
$importedFiles = GeneralUtility::getFilesInDir($this->fileImportPath);
self::assertIsArray($importedFiles, 'Failed to retrieve imported files from filesystem.');
self::assertSame(
[
'theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg',
'tueftlerzeit-sfz-rudolstadt-jpg.jpg',
],
array_values($importedFiles),
'Got unexpected number of files'
);
$this->assertEmptyLog();
}
/**
* @test
*/
public function removesNoLongerExistingImages(): void
{
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/ImportHandlesImagesExistingData.php');
copy(__DIR__ . '/Fixtures/ExampleImage.jpg', $this->fileImportPath . '/theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg');
copy(__DIR__ . '/Fixtures/ExampleImage.jpg', $this->fileImportPath . '/tueftlerzeit-sfz-rudolstadt-jpg.jpg');
$this->setUpResponses([
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithSingleImageForSingleEvent.json') ?: ''),
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''),
]);
$this->executeCommand();
$this->assertPHPDataSet(__DIR__ . '/Assertions/ImportHandlesImagesRemovesNoLongerExistingImages.php');
$importedFiles = GeneralUtility::getFilesInDir($this->fileImportPath);
self::assertIsArray($importedFiles, 'Failed to retrieve imported files from filesystem.');
self::assertSame(
[
'theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg',
'tueftlerzeit-sfz-rudolstadt-jpg.jpg',
],
array_values($importedFiles),
'Got unexpected number of files'
);
$this->assertEmptyLog();
}
/**
* @test
*/
public function updatesExistingImage(): void
{
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/ImportHandlesImagesExistingData.php');
copy(__DIR__ . '/Fixtures/ExampleImage.jpg', $this->fileImportPath . '/theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg');
copy(__DIR__ . '/Fixtures/ExampleImage.jpg', $this->fileImportPath . '/tueftlerzeit-sfz-rudolstadt-jpg.jpg');
$this->setUpResponses([
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithMultipleImagesForSingleEvent.json') ?: ''),
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''),
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''),
]);
$this->executeCommand();
$this->assertPHPDataSet(__DIR__ . '/Assertions/ImportHandlesImagesUpdatesExistingImage.php');
$importedFiles = GeneralUtility::getFilesInDir($this->fileImportPath);
self::assertIsArray($importedFiles, 'Failed to retrieve imported files from filesystem.');
self::assertSame(
[
'theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg',
'tueftlerzeit-sfz-rudolstadt-jpg.jpg',
],
array_values($importedFiles),
'Got unexpected number of files'
);
$this->assertEmptyLog();
}
/**
* @test
*/
public function addsNewImageToExistingImages(): void
{
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/ImportHandlesImagesExistingData.php');
copy(__DIR__ . '/Fixtures/ExampleImage.jpg', $this->fileImportPath . '/theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg');
copy(__DIR__ . '/Fixtures/ExampleImage.jpg', $this->fileImportPath . '/tueftlerzeit-sfz-rudolstadt-jpg.jpg');
$this->setUpResponses([
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithOneMoreImageForSingleEvent.json') ?: ''),
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''),
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''),
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''),
]);
$this->executeCommand();
$this->assertPHPDataSet(__DIR__ . '/Assertions/ImportHandlesImagesAddsNewImageToExistingImages.php');
$importedFiles = GeneralUtility::getFilesInDir($this->fileImportPath);
self::assertIsArray($importedFiles, 'Failed to retrieve imported files from filesystem.');
self::assertSame(
[
'lutherkirche-jpg.jpg',
'theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg',
'tueftlerzeit-sfz-rudolstadt-jpg.jpg',
],
array_values($importedFiles),
'Got unexpected number of files'
);
$this->assertEmptyLog();
}
/**
* @test
*/
public function updatesSortingOfImages(): void
{
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/ImportHandlesImagesExistingData.php');
copy(__DIR__ . '/Fixtures/ExampleImage.jpg', $this->fileImportPath . '/theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg');
copy(__DIR__ . '/Fixtures/ExampleImage.jpg', $this->fileImportPath . '/tueftlerzeit-sfz-rudolstadt-jpg.jpg');
$this->setUpResponses([
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithSortedImagesForSingleEvent.json') ?: ''),
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''),
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''),
]);
$this->executeCommand();
$this->assertPHPDataSet(__DIR__ . '/Assertions/ImportHandlesImagesUpdatesSortingOfImages.php');
$importedFiles = GeneralUtility::getFilesInDir($this->fileImportPath);
self::assertIsArray($importedFiles, 'Failed to retrieve imported files from filesystem.');
self::assertSame(
[
'theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg',
'tueftlerzeit-sfz-rudolstadt-jpg.jpg',
],
array_values($importedFiles),
'Got unexpected number of files'
);
$this->assertEmptyLog();
}
}