2021-12-15 12:28:06 +01: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;
|
2021-12-15 12:28:06 +01:00
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
use DateTimeImmutable;
|
|
|
|
use DateTimeZone;
|
2021-12-15 12:28:06 +01:00
|
|
|
use GuzzleHttp\Psr7\Response;
|
2023-11-27 10:04:42 +01:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
2021-12-15 12:28:06 +01:00
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
#[TestDox('DestinationData import')]
|
|
|
|
class ImportsExampleAsExpectedTest extends AbstractTestCase
|
2021-12-15 12:28:06 +01:00
|
|
|
{
|
2023-08-10 15:02:05 +02:00
|
|
|
protected function setUp(): void
|
2021-12-15 12:28:06 +01:00
|
|
|
{
|
2023-08-10 15:02:05 +02:00
|
|
|
parent::setUp();
|
2022-08-29 14:44:36 +02:00
|
|
|
|
2021-12-16 10:12:26 +01:00
|
|
|
$this->setUpConfiguration([
|
2022-01-26 14:16:12 +01:00
|
|
|
'restUrl = https://example.com/some-path/',
|
2021-12-16 10:12:26 +01:00
|
|
|
'license = example-license',
|
|
|
|
'restType = Event',
|
|
|
|
'restLimit = 3',
|
|
|
|
'restMode = next_months,12',
|
|
|
|
'restTemplate = ET2014A.json',
|
2021-12-15 12:28:06 +01:00
|
|
|
]);
|
2023-08-10 15:02:05 +02:00
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
#[Test]
|
2023-08-10 15:02:05 +02:00
|
|
|
public function importsExampleAsExpected(): void
|
|
|
|
{
|
2023-11-27 10:04:42 +01:00
|
|
|
$this->setDateAspect(new DateTimeImmutable('2021-07-13', new DateTimeZone('Europe/Berlin')));
|
2023-08-10 15:02:05 +02:00
|
|
|
|
|
|
|
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/SingleImportConfigurationWithCategories.php');
|
|
|
|
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/SingleRegion.php');
|
|
|
|
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/SingleCategory.php');
|
2021-12-15 12:28:06 +01:00
|
|
|
|
2021-12-16 10:12:26 +01:00
|
|
|
$requests = &$this->setUpResponses([
|
2022-01-26 14:16:12 +01:00
|
|
|
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/Response.json') ?: ''),
|
2021-12-15 12:28:06 +01:00
|
|
|
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') ?: ''),
|
2021-12-16 10:12:26 +01:00
|
|
|
]);
|
2021-12-15 12:28:06 +01:00
|
|
|
|
2022-11-22 13:49:57 +01:00
|
|
|
$tester = $this->executeCommand();
|
2021-12-15 12:28:06 +01:00
|
|
|
|
|
|
|
self::assertSame(0, $tester->getStatusCode());
|
|
|
|
|
2022-01-26 14:16:12 +01:00
|
|
|
self::assertCount(4, $requests, 'Unexpected number of requests were made.');
|
|
|
|
self::assertSame('https://example.com/some-path/?experience=beispielstadt&licensekey=example-license&type=Event&mode=next_months%2C12&limit=3&template=ET2014A.json', (string)$requests[0]['request']->getUri());
|
|
|
|
self::assertSame('https://dam.destination.one/849917/279ac45b3fc701a7197131f627164fffd9f8cc77bc75165e2fc2b864ed606920/theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg', (string)$requests[1]['request']->getUri());
|
|
|
|
self::assertSame('https://dam.destination.one/828118/f13bbf5602ffc406ebae2faa3527654dea84194666bce4925a1ca8bd3f50c5e9/tueftlerzeit-sfz-rudolstadt-jpg.jpg', (string)$requests[2]['request']->getUri());
|
|
|
|
self::assertSame('https://dam.destination.one/853436/109ac1cf87913e21b5e2b0ef0cc63d223a14374364952a855746a8e7c3fcfc36/lutherkirche-jpg.jpg', (string)$requests[3]['request']->getUri());
|
2021-12-15 12:28:06 +01:00
|
|
|
|
|
|
|
self::assertCount(
|
|
|
|
0,
|
|
|
|
$this->getAllRecords('tx_events_domain_model_partner'),
|
|
|
|
'Added unexpected partners.'
|
|
|
|
);
|
|
|
|
self::assertCount(
|
|
|
|
1,
|
|
|
|
$this->getAllRecords('tx_events_domain_model_region'),
|
|
|
|
'Added or removed unexpected region.'
|
|
|
|
);
|
2023-11-27 10:04:42 +01:00
|
|
|
$this->assertPHPDataSet(__DIR__ . '/Assertions/ImportsExampleAsExpected.php');
|
2021-12-15 12:28:06 +01:00
|
|
|
|
2023-07-04 10:11:26 +02:00
|
|
|
$importedFiles = GeneralUtility::getFilesInDir($this->fileImportPath);
|
2021-12-15 12:28:06 +01:00
|
|
|
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'
|
|
|
|
);
|
2021-12-20 10:15:26 +01:00
|
|
|
|
2023-07-04 10:11:26 +02:00
|
|
|
$this->assertEmptyLog();
|
2021-12-15 12:28:06 +01:00
|
|
|
}
|
2023-08-10 15:02:05 +02:00
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
#[Test]
|
2023-08-10 15:02:05 +02:00
|
|
|
public function importsSource(): void
|
|
|
|
{
|
|
|
|
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/DefaultImportConfiguration.php');
|
|
|
|
$this->setUpResponses([
|
|
|
|
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithSources.json') ?: ''),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->executeCommand();
|
|
|
|
|
|
|
|
$this->assertPHPDataSet(__DIR__ . '/Assertions/ImportsSource.php');
|
|
|
|
$this->assertEmptyLog();
|
|
|
|
}
|
2023-11-29 10:36:59 +01:00
|
|
|
|
|
|
|
#[Test]
|
|
|
|
public function importsKeywords(): void
|
|
|
|
{
|
|
|
|
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/DefaultImportConfiguration.php');
|
|
|
|
$this->setUpResponses([
|
|
|
|
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithKeywords.json') ?: ''),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->executeCommand();
|
|
|
|
|
|
|
|
$this->assertPHPDataSet(__DIR__ . '/Assertions/ImportsKeywords.php');
|
|
|
|
$this->assertEmptyLog();
|
|
|
|
}
|
2021-12-15 12:28:06 +01:00
|
|
|
}
|