2023-06-12 11:07:52 +02:00
|
|
|
<?php
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2023-11-09 10:27:43 +01:00
|
|
|
namespace WerkraumMedia\Events\Tests\Functional\Import\DestinationDataTest;
|
2023-06-12 11:07:52 +02:00
|
|
|
|
|
|
|
use GuzzleHttp\Psr7\Response;
|
2023-11-27 10:04:42 +01:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
2023-06-12 11:07:52 +02:00
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
#[TestDox('DestinationData import')]
|
|
|
|
class ImportHandlesImagesTest extends AbstractTestCase
|
2023-06-12 11:07:52 +02:00
|
|
|
{
|
|
|
|
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',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
#[Test]
|
2023-06-12 11:07:52 +02:00
|
|
|
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'
|
|
|
|
);
|
|
|
|
|
2023-07-04 10:11:26 +02:00
|
|
|
$this->assertEmptyLog();
|
2023-06-12 11:07:52 +02:00
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
#[Test]
|
2023-06-12 11:07:52 +02:00
|
|
|
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'
|
|
|
|
);
|
|
|
|
|
2023-07-04 10:11:26 +02:00
|
|
|
$this->assertEmptyLog();
|
2023-06-12 11:07:52 +02:00
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
#[Test]
|
2023-06-12 11:07:52 +02:00
|
|
|
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'
|
|
|
|
);
|
|
|
|
|
2023-07-04 10:11:26 +02:00
|
|
|
$this->assertEmptyLog();
|
2023-06-12 11:07:52 +02:00
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
#[Test]
|
2023-06-12 11:07:52 +02:00
|
|
|
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'
|
|
|
|
);
|
|
|
|
|
2023-07-04 10:11:26 +02:00
|
|
|
$this->assertEmptyLog();
|
2023-06-12 11:07:52 +02:00
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
#[Test]
|
2023-06-12 11:07:52 +02:00
|
|
|
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'
|
|
|
|
);
|
|
|
|
|
2023-07-04 10:11:26 +02:00
|
|
|
$this->assertEmptyLog();
|
2023-06-12 11:07:52 +02:00
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
#[Test]
|
2023-06-12 11:07:52 +02:00
|
|
|
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'
|
|
|
|
);
|
|
|
|
|
2023-07-04 10:11:26 +02:00
|
|
|
$this->assertEmptyLog();
|
2023-06-12 11:07:52 +02:00
|
|
|
}
|
|
|
|
}
|