2022-01-26 14:16:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wrm\Events\Tests\Unit\Service\DestinationDataImportService;
|
|
|
|
|
2022-01-26 15:56:28 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2022-01-26 14:16:12 +01:00
|
|
|
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;
|
2022-01-26 15:56:28 +01:00
|
|
|
use Wrm\Events\Tests\ProphecyTrait;
|
2022-01-26 14:16:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|