mirror of
https://github.com/werkraum-media/events.git
synced 2024-11-10 00:56:10 +01:00
Use new import class and move url building and fetching
This commit is contained in:
parent
295ad8645a
commit
b5d095659a
16 changed files with 452 additions and 137 deletions
|
@ -7,6 +7,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
|||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use TYPO3\CMS\Core\Core\Bootstrap;
|
||||
use Wrm\Events\Domain\DestinationData\Import;
|
||||
use Wrm\Events\Service\DestinationDataImportService;
|
||||
|
||||
class DestinationDataImportCommand extends Command
|
||||
|
@ -61,11 +62,11 @@ class DestinationDataImportCommand extends Command
|
|||
$regionUid = null;
|
||||
}
|
||||
|
||||
return $this->destinationDataImportService->import(
|
||||
return $this->destinationDataImportService->import(new Import(
|
||||
$input->getArgument('rest-experience'),
|
||||
$input->getArgument('storage-pid'),
|
||||
$regionUid,
|
||||
$input->getArgument('files-folder')
|
||||
);
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
62
Classes/Domain/DestinationData/Import.php
Normal file
62
Classes/Domain/DestinationData/Import.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Wrm\Events\Domain\DestinationData;
|
||||
|
||||
/**
|
||||
* Actual request to import.
|
||||
* Includes all configuration specific to a concrete import.
|
||||
*/
|
||||
class Import
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $restExperience;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $storagePid;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $regionUid;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $filesFolder;
|
||||
|
||||
public function __construct(
|
||||
string $restExperience,
|
||||
int $storagePid,
|
||||
?int $regionUid,
|
||||
string $filesFolder
|
||||
) {
|
||||
$this->restExperience = $restExperience;
|
||||
$this->storagePid = $storagePid;
|
||||
$this->regionUid = $regionUid;
|
||||
$this->filesFolder = $filesFolder;
|
||||
}
|
||||
|
||||
public function getRestExperience(): string
|
||||
{
|
||||
return $this->restExperience;
|
||||
}
|
||||
|
||||
public function getStoragePid(): int
|
||||
{
|
||||
return $this->storagePid;
|
||||
}
|
||||
|
||||
public function getRegionUid(): ?int
|
||||
{
|
||||
return $this->regionUid;
|
||||
}
|
||||
|
||||
public function getFilesFolder(): string
|
||||
{
|
||||
return $this->filesFolder;
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
|||
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
|
||||
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
||||
use Wrm\Events\Domain\DestinationData\Import;
|
||||
use Wrm\Events\Domain\Model\Category;
|
||||
use Wrm\Events\Domain\Model\Date;
|
||||
use Wrm\Events\Domain\Model\Event;
|
||||
|
@ -34,49 +35,9 @@ use Wrm\Events\Service\DestinationDataImportService\DataFetcher;
|
|||
class DestinationDataImportService
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @var Import
|
||||
*/
|
||||
private $restUrl;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $restLicenseKey;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $restType;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $restLimit;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $restMode;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $restTemplate;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $restExperience;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $storagePid;
|
||||
|
||||
/**
|
||||
* @var ?int
|
||||
*/
|
||||
private $regionUid;
|
||||
private $import;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
|
@ -88,16 +49,6 @@ class DestinationDataImportService
|
|||
*/
|
||||
private $categoryParentUid;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $filesFolder;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $settings = [];
|
||||
|
||||
/**
|
||||
* @var Environment
|
||||
*/
|
||||
|
@ -210,34 +161,19 @@ class DestinationDataImportService
|
|||
$this->environment = $environment;
|
||||
$this->dataFetcher = $dataFetcher;
|
||||
|
||||
// Get Typoscript Settings
|
||||
$this->settings = $this->configurationManager->getConfiguration(
|
||||
$settings = $this->configurationManager->getConfiguration(
|
||||
ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS,
|
||||
'Events',
|
||||
'Pi1'
|
||||
);
|
||||
|
||||
// Set properties
|
||||
$this->restUrl = $this->settings['destinationData']['restUrl'];
|
||||
$this->restLicenseKey = $this->settings['destinationData']['license'];
|
||||
$this->restType = $this->settings['destinationData']['restType'];
|
||||
$this->restLimit = $this->settings['destinationData']['restLimit'];
|
||||
$this->restMode = $this->settings['destinationData']['restMode'];
|
||||
$this->restTemplate = $this->settings['destinationData']['restTemplate'];
|
||||
$this->categoriesPid = (int) $this->settings['destinationData']['categoriesPid'];
|
||||
$this->categoryParentUid = (int) $this->settings['destinationData']['categoryParentUid'];
|
||||
)['destinationData'] ?? [];
|
||||
$this->categoriesPid = (int) $settings['categoriesPid'];
|
||||
$this->categoryParentUid = (int) $settings['categoryParentUid'];
|
||||
}
|
||||
|
||||
public function import(
|
||||
string $restExperience,
|
||||
int $storagePid,
|
||||
?int $regionUid,
|
||||
string $filesFolder
|
||||
Import $import
|
||||
): int {
|
||||
$this->restExperience = $restExperience;
|
||||
$this->storagePid = $storagePid;
|
||||
$this->regionUid = $regionUid;
|
||||
$this->filesFolder = $filesFolder;
|
||||
$this->import = $import;
|
||||
|
||||
// Get configuration
|
||||
$frameworkConfiguration = $this->configurationManager->getConfiguration(
|
||||
|
@ -247,41 +183,23 @@ class DestinationDataImportService
|
|||
// Set storage pid
|
||||
$persistenceConfiguration = [
|
||||
'persistence' => [
|
||||
'storagePid' => $this->storagePid,
|
||||
'storagePid' => $this->import->getStoragePid(),
|
||||
],
|
||||
];
|
||||
|
||||
// Set Configuration
|
||||
$this->configurationManager->setConfiguration(array_merge($frameworkConfiguration, $persistenceConfiguration));
|
||||
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
|
||||
|
||||
$this->logger->info('Starting Destination Data Import Service');
|
||||
$restUrl = $this->restUrl . '?experience=' . $this->restExperience . '&licensekey=' . $this->restLicenseKey . '&type=' . $this->restType . '&mode=' . $this->restMode . '&limit=' . $this->restLimit . '&template=' . $this->restTemplate;
|
||||
$this->logger->info('Try to get data from ' . $restUrl);
|
||||
|
||||
try {
|
||||
$fetchedData = $this->fetchData($restUrl);
|
||||
$data = $this->dataFetcher->fetchSearchResult($import);
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error('Could not receive data.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
return $this->processData($fetchedData);
|
||||
}
|
||||
|
||||
private function fetchData(string $restUrl): array
|
||||
{
|
||||
$jsonContent = file_get_contents($restUrl);
|
||||
if (is_string($jsonContent) === false) {
|
||||
throw new \Exception('Could not receive data.', 1639495835);
|
||||
}
|
||||
$jsonResponse = json_decode($jsonContent, true);
|
||||
if (is_array($jsonResponse) === false) {
|
||||
throw new \Exception('Could not receive data.', 1639495835);
|
||||
}
|
||||
|
||||
$this->logger->info('Received data with ' . count($jsonResponse['items']) . ' items');
|
||||
return $jsonResponse;
|
||||
return $this->processData($data);
|
||||
}
|
||||
|
||||
public function processData(array $data): int
|
||||
|
@ -290,8 +208,8 @@ class DestinationDataImportService
|
|||
|
||||
// Get selected region
|
||||
$selectedRegion = null;
|
||||
if (is_int($this->regionUid)) {
|
||||
$selectedRegion = $this->regionRepository->findByUid($this->regionUid);
|
||||
if (is_int($this->import->getRegionUid())) {
|
||||
$selectedRegion = $this->regionRepository->findByUid($this->import->getRegionUid());
|
||||
}
|
||||
|
||||
foreach ($data['items'] as $event) {
|
||||
|
@ -665,7 +583,7 @@ class DestinationDataImportService
|
|||
$this->logger->info('File attached:' . $fileUrl);
|
||||
$this->logger->info('File attached sanitized:' . $orgFileNameSanitized);
|
||||
|
||||
$targetFilePath = $this->environment->getPublicPath() . '/fileadmin/' . $this->filesFolder
|
||||
$targetFilePath = $this->environment->getPublicPath() . '/fileadmin/' . $this->import->getFilesFolder()
|
||||
. $orgFileNameSanitized;
|
||||
// Check if file already exists
|
||||
|
||||
|
@ -679,9 +597,9 @@ class DestinationDataImportService
|
|||
$this->logger->info('Adding file ' . $filename);
|
||||
|
||||
try {
|
||||
$targetFolder = $storage->getFolder($this->filesFolder);
|
||||
$targetFolder = $storage->getFolder($this->import->getFilesFolder());
|
||||
} catch (FolderDoesNotExistException $e) {
|
||||
$targetFolder = $storage->createFolder($this->filesFolder);
|
||||
$targetFolder = $storage->createFolder($this->import->getFilesFolder());
|
||||
}
|
||||
|
||||
$storage->addFile($filename, $targetFolder, basename($fileUrl));
|
||||
|
@ -696,7 +614,7 @@ class DestinationDataImportService
|
|||
// TODO: How to delete file references?
|
||||
} else {
|
||||
$this->logger->info('No relation found');
|
||||
$fileIdentifier = $this->filesFolder . $orgFileNameSanitized;
|
||||
$fileIdentifier = $this->import->getFilesFolder() . $orgFileNameSanitized;
|
||||
$file = $storage->getFile($fileIdentifier);
|
||||
if (!$file instanceof File) {
|
||||
$this->logger->warning('Could not find file.', [$fileIdentifier]);
|
||||
|
@ -715,7 +633,7 @@ class DestinationDataImportService
|
|||
'tx_events_domain_model_event',
|
||||
$this->tmpCurrentEvent->getUid(),
|
||||
'images',
|
||||
$this->storagePid
|
||||
$this->import->getStoragePid()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,9 @@ use GuzzleHttp\ClientInterface as GuzzleClientInterface;
|
|||
use Psr\Http\Client\ClientInterface;
|
||||
use Psr\Http\Message\RequestFactoryInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use TYPO3\CMS\Core\Log\Logger;
|
||||
use TYPO3\CMS\Core\Log\LogManager;
|
||||
use Wrm\Events\Domain\DestinationData\Import;
|
||||
|
||||
/**
|
||||
* Provides API to fetch data from remote.
|
||||
|
@ -15,6 +18,11 @@ use Psr\Http\Message\ResponseInterface;
|
|||
*/
|
||||
class DataFetcher
|
||||
{
|
||||
/**
|
||||
* @var UrlFactory
|
||||
*/
|
||||
private $urlFactory;
|
||||
|
||||
/**
|
||||
* @var RequestFactoryInterface
|
||||
*/
|
||||
|
@ -25,12 +33,57 @@ class DataFetcher
|
|||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @var Logger
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
public function __construct(
|
||||
UrlFactory $urlFactory,
|
||||
LogManager $logManager,
|
||||
RequestFactoryInterface $requestFactory,
|
||||
GuzzleClientInterface $client
|
||||
) {
|
||||
$this->urlFactory = $urlFactory;
|
||||
$this->requestFactory = $requestFactory;
|
||||
$this->client = $client;
|
||||
|
||||
$this->logger = $logManager->getLogger(__CLASS__);
|
||||
}
|
||||
|
||||
public function fetchSearchResult(Import $import): array
|
||||
{
|
||||
$url = $this->urlFactory->createSearchResultUrl($import);
|
||||
|
||||
$this->logger->info('Try to get data from ' . $url);
|
||||
|
||||
if ($this->client instanceof ClientInterface) {
|
||||
// Keep after TYPO3 10 was dropped
|
||||
$response = $this->client->sendRequest(
|
||||
$this->requestFactory->createRequest(
|
||||
'GET',
|
||||
$url
|
||||
)
|
||||
);
|
||||
} else {
|
||||
// Drop once TYPO3 10 support was dropped
|
||||
$response = $this->client->request(
|
||||
'GET',
|
||||
$url,
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
$jsonContent = $response->getBody()->__toString();
|
||||
|
||||
$jsonResponse = json_decode($jsonContent, true);
|
||||
if (is_array($jsonResponse) === false) {
|
||||
throw new \Exception('No valid JSON fetched, got: "' . $jsonContent . '".', 1639495835);
|
||||
}
|
||||
|
||||
$this->logger->info('Received data with ' . count($jsonResponse['items']) . ' items');
|
||||
|
||||
return $jsonResponse;
|
||||
}
|
||||
|
||||
public function fetchImage(string $url): ResponseInterface
|
||||
|
|
51
Classes/Service/DestinationDataImportService/UrlFactory.php
Normal file
51
Classes/Service/DestinationDataImportService/UrlFactory.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Wrm\Events\Service\DestinationDataImportService;
|
||||
|
||||
use TYPO3\CMS\Core\Http\Uri;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
||||
use Wrm\Events\Domain\DestinationData\Import;
|
||||
|
||||
/**
|
||||
* Factory to create URLs used during import of Destination Data.
|
||||
*/
|
||||
class UrlFactory
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $settings = [];
|
||||
|
||||
public function __construct(
|
||||
ConfigurationManager $configurationManager
|
||||
) {
|
||||
$this->settings = $configurationManager->getConfiguration(
|
||||
ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS,
|
||||
'Events',
|
||||
'Pi1'
|
||||
)['destinationData'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* URL used to fetch initial set of data.
|
||||
*/
|
||||
public function createSearchResultUrl(
|
||||
Import $import
|
||||
): string {
|
||||
$parameter = [
|
||||
'experience' => $import->getRestExperience(),
|
||||
'licensekey' => $this->settings['license'] ?? '',
|
||||
'type' => $this->settings['restType'] ?? '',
|
||||
'mode' => $this->settings['restMode'] ?? '',
|
||||
'limit' => $this->settings['restLimit'] ?? '',
|
||||
'template' => $this->settings['restTemplate'] ?? '',
|
||||
];
|
||||
|
||||
$parameter = array_filter($parameter);
|
||||
|
||||
$url = new Uri($this->settings['restUrl']);
|
||||
$url = $url->withQuery(http_build_query($parameter));
|
||||
return (string) $url;
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ class ImportCleansTransientFilesTest extends AbstractTest
|
|||
{
|
||||
$fileImportPath = 'staedte/beispielstadt/events/';
|
||||
$this->setUpConfiguration([
|
||||
'restUrl = ' . $this->getInstancePath() . '/typo3conf/ext/events/Tests/Functional/Import/DestinationDataTest/Fixtures/Response.json',
|
||||
'restUrl = https://example.com/some-path/',
|
||||
'license = example-license',
|
||||
'restType = Event',
|
||||
'restLimit = 3',
|
||||
|
@ -29,6 +29,7 @@ class ImportCleansTransientFilesTest extends AbstractTest
|
|||
]);
|
||||
|
||||
$requests = &$this->setUpResponses([
|
||||
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/Response.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') ?: ''),
|
||||
|
@ -42,10 +43,11 @@ class ImportCleansTransientFilesTest extends AbstractTest
|
|||
|
||||
self::assertSame(0, $tester->getStatusCode());
|
||||
|
||||
self::assertCount(3, $requests, 'Unexpected number of requests were made.');
|
||||
self::assertSame('https://dam.destination.one/849917/279ac45b3fc701a7197131f627164fffd9f8cc77bc75165e2fc2b864ed606920/theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg', (string)$requests[0]['request']->getUri());
|
||||
self::assertSame('https://dam.destination.one/828118/f13bbf5602ffc406ebae2faa3527654dea84194666bce4925a1ca8bd3f50c5e9/tueftlerzeit-sfz-rudolstadt-jpg.jpg', (string)$requests[1]['request']->getUri());
|
||||
self::assertSame('https://dam.destination.one/853436/109ac1cf87913e21b5e2b0ef0cc63d223a14374364952a855746a8e7c3fcfc36/lutherkirche-jpg.jpg', (string)$requests[2]['request']->getUri());
|
||||
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());
|
||||
|
||||
$importedFiles = GeneralUtility::getFilesInDir($this->getInstancePath() . '/fileadmin/' . $fileImportPath);
|
||||
self::assertIsArray($importedFiles, 'Failed to retrieve imported files from filesystem.');
|
||||
|
|
|
@ -19,7 +19,7 @@ class ImportDoesNotUseUploadsFolderTest extends AbstractTest
|
|||
$fileImportPath = 'staedte/beispielstadt/events/';
|
||||
|
||||
$this->setUpConfiguration([
|
||||
'restUrl = ' . $this->getInstancePath() . '/typo3conf/ext/events/Tests/Functional/Import/DestinationDataTest/Fixtures/Response.json',
|
||||
'restUrl = https://example.com/some-path/',
|
||||
'license = example-license',
|
||||
'restType = Event',
|
||||
'restLimit = 3',
|
||||
|
@ -30,6 +30,7 @@ class ImportDoesNotUseUploadsFolderTest extends AbstractTest
|
|||
]);
|
||||
|
||||
$requests = &$this->setUpResponses([
|
||||
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/Response.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') ?: ''),
|
||||
|
@ -42,10 +43,11 @@ class ImportDoesNotUseUploadsFolderTest extends AbstractTest
|
|||
]);
|
||||
self::assertSame(0, $tester->getStatusCode());
|
||||
|
||||
self::assertCount(3, $requests, 'Unexpected number of requests were made.');
|
||||
self::assertSame('https://dam.destination.one/849917/279ac45b3fc701a7197131f627164fffd9f8cc77bc75165e2fc2b864ed606920/theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg', (string)$requests[0]['request']->getUri());
|
||||
self::assertSame('https://dam.destination.one/828118/f13bbf5602ffc406ebae2faa3527654dea84194666bce4925a1ca8bd3f50c5e9/tueftlerzeit-sfz-rudolstadt-jpg.jpg', (string)$requests[1]['request']->getUri());
|
||||
self::assertSame('https://dam.destination.one/853436/109ac1cf87913e21b5e2b0ef0cc63d223a14374364952a855746a8e7c3fcfc36/lutherkirche-jpg.jpg', (string)$requests[2]['request']->getUri());
|
||||
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());
|
||||
|
||||
$importedFiles = GeneralUtility::getFilesInDir($this->getInstancePath() . '/fileadmin/' . $fileImportPath);
|
||||
self::assertIsArray($importedFiles, 'Failed to retrieve imported files from filesystem.');
|
||||
|
|
|
@ -20,7 +20,7 @@ class ImportsExampleAsExpectedTest extends AbstractTest
|
|||
$this->importDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Fixtures/SingleRegion.xml');
|
||||
$this->importDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Fixtures/SingleCategory.xml');
|
||||
$this->setUpConfiguration([
|
||||
'restUrl = ' . $this->getInstancePath() . '/typo3conf/ext/events/Tests/Functional/Import/DestinationDataTest/Fixtures/Response.json',
|
||||
'restUrl = https://example.com/some-path/',
|
||||
'license = example-license',
|
||||
'restType = Event',
|
||||
'restLimit = 3',
|
||||
|
@ -31,6 +31,7 @@ class ImportsExampleAsExpectedTest extends AbstractTest
|
|||
]);
|
||||
|
||||
$requests = &$this->setUpResponses([
|
||||
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/Response.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') ?: ''),
|
||||
|
@ -45,10 +46,11 @@ class ImportsExampleAsExpectedTest extends AbstractTest
|
|||
|
||||
self::assertSame(0, $tester->getStatusCode());
|
||||
|
||||
self::assertCount(3, $requests, 'Unexpected number of requests were made.');
|
||||
self::assertSame('https://dam.destination.one/849917/279ac45b3fc701a7197131f627164fffd9f8cc77bc75165e2fc2b864ed606920/theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg', (string)$requests[0]['request']->getUri());
|
||||
self::assertSame('https://dam.destination.one/828118/f13bbf5602ffc406ebae2faa3527654dea84194666bce4925a1ca8bd3f50c5e9/tueftlerzeit-sfz-rudolstadt-jpg.jpg', (string)$requests[1]['request']->getUri());
|
||||
self::assertSame('https://dam.destination.one/853436/109ac1cf87913e21b5e2b0ef0cc63d223a14374364952a855746a8e7c3fcfc36/lutherkirche-jpg.jpg', (string)$requests[2]['request']->getUri());
|
||||
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());
|
||||
|
||||
self::assertCount(
|
||||
0,
|
||||
|
|
|
@ -19,7 +19,7 @@ class ImportsWithoutCategoryIfNotProvidedTest extends AbstractTest
|
|||
|
||||
$this->importDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Fixtures/SingleRegion.xml');
|
||||
$this->setUpConfiguration([
|
||||
'restUrl = ' . $this->getInstancePath() . '/typo3conf/ext/events/Tests/Functional/Import/DestinationDataTest/Fixtures/Response.json',
|
||||
'restUrl = https://example.com/some-path/',
|
||||
'license = example-license',
|
||||
'restType = Event',
|
||||
'restLimit = 3',
|
||||
|
@ -30,6 +30,7 @@ class ImportsWithoutCategoryIfNotProvidedTest extends AbstractTest
|
|||
]);
|
||||
|
||||
$requests = &$this->setUpResponses([
|
||||
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/Response.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') ?: ''),
|
||||
|
@ -44,10 +45,11 @@ class ImportsWithoutCategoryIfNotProvidedTest extends AbstractTest
|
|||
|
||||
self::assertSame(0, $tester->getStatusCode());
|
||||
|
||||
self::assertCount(3, $requests, 'Unexpected number of requests were made.');
|
||||
self::assertSame('https://dam.destination.one/849917/279ac45b3fc701a7197131f627164fffd9f8cc77bc75165e2fc2b864ed606920/theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg', (string)$requests[0]['request']->getUri());
|
||||
self::assertSame('https://dam.destination.one/828118/f13bbf5602ffc406ebae2faa3527654dea84194666bce4925a1ca8bd3f50c5e9/tueftlerzeit-sfz-rudolstadt-jpg.jpg', (string)$requests[1]['request']->getUri());
|
||||
self::assertSame('https://dam.destination.one/853436/109ac1cf87913e21b5e2b0ef0cc63d223a14374364952a855746a8e7c3fcfc36/lutherkirche-jpg.jpg', (string)$requests[2]['request']->getUri());
|
||||
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());
|
||||
|
||||
self::assertCount(
|
||||
0,
|
||||
|
|
|
@ -18,7 +18,7 @@ class ImportsWithoutRegionIfNotProvidedTest extends AbstractTest
|
|||
$fileImportPath = 'staedte/beispielstadt/events/';
|
||||
$this->importDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Fixtures/SingleCategory.xml');
|
||||
$this->setUpConfiguration([
|
||||
'restUrl = ' . $this->getInstancePath() . '/typo3conf/ext/events/Tests/Functional/Import/DestinationDataTest/Fixtures/Response.json',
|
||||
'restUrl = https://example.com/some-path/',
|
||||
'license = example-license',
|
||||
'restType = Event',
|
||||
'restLimit = 3',
|
||||
|
@ -29,6 +29,7 @@ class ImportsWithoutRegionIfNotProvidedTest extends AbstractTest
|
|||
]);
|
||||
|
||||
$requests = &$this->setUpResponses([
|
||||
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/Response.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') ?: ''),
|
||||
|
@ -42,10 +43,11 @@ class ImportsWithoutRegionIfNotProvidedTest extends AbstractTest
|
|||
|
||||
self::assertSame(0, $tester->getStatusCode());
|
||||
|
||||
self::assertCount(3, $requests, 'Unexpected number of requests were made.');
|
||||
self::assertSame('https://dam.destination.one/849917/279ac45b3fc701a7197131f627164fffd9f8cc77bc75165e2fc2b864ed606920/theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg', (string)$requests[0]['request']->getUri());
|
||||
self::assertSame('https://dam.destination.one/828118/f13bbf5602ffc406ebae2faa3527654dea84194666bce4925a1ca8bd3f50c5e9/tueftlerzeit-sfz-rudolstadt-jpg.jpg', (string)$requests[1]['request']->getUri());
|
||||
self::assertSame('https://dam.destination.one/853436/109ac1cf87913e21b5e2b0ef0cc63d223a14374364952a855746a8e7c3fcfc36/lutherkirche-jpg.jpg', (string)$requests[2]['request']->getUri());
|
||||
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());
|
||||
|
||||
self::assertCount(
|
||||
0,
|
||||
|
|
102
Tests/Unit/Domain/DestinationData/ImportTest.php
Normal file
102
Tests/Unit/Domain/DestinationData/ImportTest.php
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
namespace Wrm\Events\Tests\Unit\Domain\DestinationData;
|
||||
|
||||
use Wrm\Events\Domain\DestinationData\Import;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \Wrm\Events\Domain\DestinationData\Import
|
||||
*/
|
||||
class ImportTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function canBeCreated(): void
|
||||
{
|
||||
$subject = new Import(
|
||||
'',
|
||||
0,
|
||||
null,
|
||||
''
|
||||
);
|
||||
|
||||
self::assertInstanceOf(
|
||||
Import::class,
|
||||
$subject
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function returnsRestExperience(): void
|
||||
{
|
||||
$subject = new Import(
|
||||
'experience',
|
||||
0,
|
||||
null,
|
||||
''
|
||||
);
|
||||
|
||||
self::assertSame(
|
||||
'experience',
|
||||
$subject->getRestExperience()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function returnsStoragePid(): void
|
||||
{
|
||||
$subject = new Import(
|
||||
'',
|
||||
20,
|
||||
null,
|
||||
''
|
||||
);
|
||||
|
||||
self::assertSame(
|
||||
20,
|
||||
$subject->getStoragePid()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function returnsRegionUid(): void
|
||||
{
|
||||
$subject = new Import(
|
||||
'',
|
||||
0,
|
||||
30,
|
||||
''
|
||||
);
|
||||
|
||||
self::assertSame(
|
||||
30,
|
||||
$subject->getRegionUid()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function returnsFilesFolder(): void
|
||||
{
|
||||
$subject = new Import(
|
||||
'',
|
||||
0,
|
||||
null,
|
||||
'test/folder'
|
||||
);
|
||||
|
||||
self::assertSame(
|
||||
'test/folder',
|
||||
$subject->getFilesFolder()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace Wrm\Events\Tests\Unit\Service\DestinationDataImportService;
|
||||
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
||||
use Wrm\Events\Domain\DestinationData\Import;
|
||||
use Wrm\Events\Service\DestinationDataImportService\UrlFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \Wrm\Events\Service\DestinationDataImportService\UrlFactory
|
||||
*/
|
||||
class UrlFactoryTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function canBeCreated(): void
|
||||
{
|
||||
$configurationManager = $this->prophesize(ConfigurationManager::class);
|
||||
$configurationManager->getConfiguration(
|
||||
ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS,
|
||||
'Events',
|
||||
'Pi1'
|
||||
)->willReturn([]);
|
||||
|
||||
$subject = new UrlFactory(
|
||||
$configurationManager->reveal()
|
||||
);
|
||||
|
||||
self::assertInstanceOf(
|
||||
UrlFactory::class,
|
||||
$subject
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider possibleImports
|
||||
*/
|
||||
public function createSearchResultUrl(
|
||||
ObjectProphecy $import,
|
||||
array $settings,
|
||||
string $expectedResult
|
||||
): void {
|
||||
$configurationManager = $this->prophesize(ConfigurationManager::class);
|
||||
$configurationManager->getConfiguration(
|
||||
ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS,
|
||||
'Events',
|
||||
'Pi1'
|
||||
)->willReturn(['destinationData' => $settings]);
|
||||
|
||||
$subject = new UrlFactory(
|
||||
$configurationManager->reveal()
|
||||
);
|
||||
|
||||
$result = $subject->createSearchResultUrl($import->reveal());
|
||||
|
||||
self::assertSame(
|
||||
$result,
|
||||
$expectedResult
|
||||
);
|
||||
}
|
||||
|
||||
public function possibleImports(): array
|
||||
{
|
||||
return [
|
||||
'All provided' => [
|
||||
'import' => (function () {
|
||||
$import = $this->prophesize(Import::class);
|
||||
$import->getRestExperience()->willReturn('experience');
|
||||
|
||||
return $import;
|
||||
})(),
|
||||
'settings' => [
|
||||
'restUrl' => 'https://example.com/path',
|
||||
'license' => 'licenseKey',
|
||||
'restType' => 'restType',
|
||||
'restMode' => 'restMode',
|
||||
'restLimit' => 'restLimit',
|
||||
'restTemplate' => 'restTemplate',
|
||||
],
|
||||
'expectedResult' => 'https://example.com/path?experience=experience&licensekey=licenseKey&type=restType&mode=restMode&limit=restLimit&template=restTemplate',
|
||||
],
|
||||
'All missing' => [
|
||||
'import' => (function () {
|
||||
$import = $this->prophesize(Import::class);
|
||||
$import->getRestExperience()->willReturn('');
|
||||
|
||||
return $import;
|
||||
})(),
|
||||
'settings' => [
|
||||
'restUrl' => 'https://example.com/path',
|
||||
],
|
||||
'expectedResult' => 'https://example.com/path',
|
||||
],
|
||||
'Some missing' => [
|
||||
'import' => (function () {
|
||||
$import = $this->prophesize(Import::class);
|
||||
$import->getRestExperience()->willReturn('experience');
|
||||
|
||||
return $import;
|
||||
})(),
|
||||
'settings' => [
|
||||
'restUrl' => 'https://example.com/path',
|
||||
'license' => 'licenseKey',
|
||||
'restLimit' => 'restLimit',
|
||||
'restTemplate' => 'restTemplate',
|
||||
],
|
||||
'expectedResult' => 'https://example.com/path?experience=experience&licensekey=licenseKey&limit=restLimit&template=restTemplate',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -54,7 +54,8 @@
|
|||
"typo3/testing-framework": "^6.14",
|
||||
"jangregor/phpstan-prophecy": "^1.0",
|
||||
"phpstan/phpstan-phpunit": "^1.0",
|
||||
"guzzlehttp/guzzle": "^6.3 || ^7.3"
|
||||
"guzzlehttp/guzzle": "^6.3 || ^7.3",
|
||||
"phpspec/prophecy-phpunit": "^1.0"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
|
|
|
@ -1,22 +1,17 @@
|
|||
parameters:
|
||||
ignoreErrors:
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$restExperience of method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:import\\(\\) expects string, mixed given\\.$#"
|
||||
message: "#^Parameter \\#1 \\$restExperience of class Wrm\\\\Events\\\\Domain\\\\DestinationData\\\\Import constructor expects string, mixed given\\.$#"
|
||||
count: 1
|
||||
path: Classes/Command/DestinationDataImportCommand.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$storagePid of method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:import\\(\\) expects int, mixed given\\.$#"
|
||||
message: "#^Parameter \\#2 \\$storagePid of class Wrm\\\\Events\\\\Domain\\\\DestinationData\\\\Import constructor expects int, mixed given\\.$#"
|
||||
count: 1
|
||||
path: Classes/Command/DestinationDataImportCommand.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#3 \\$regionUid of method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:import\\(\\) expects int\\|null, mixed given\\.$#"
|
||||
count: 1
|
||||
path: Classes/Command/DestinationDataImportCommand.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#4 \\$filesFolder of method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:import\\(\\) expects string, mixed given\\.$#"
|
||||
message: "#^Parameter \\#4 \\$filesFolder of class Wrm\\\\Events\\\\Domain\\\\DestinationData\\\\Import constructor expects string, mixed given\\.$#"
|
||||
count: 1
|
||||
path: Classes/Command/DestinationDataImportCommand.php
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="unit">
|
||||
<directory>Tests/Unit/</directory>
|
||||
</testsuite>
|
||||
<testsuite name="functional">
|
||||
<directory>Tests/Functional/</directory>
|
||||
</testsuite>
|
||||
|
|
Loading…
Reference in a new issue