2022-01-26 14:16:12 +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\Unit\Service\DestinationDataImportService;
|
2022-01-26 14:16:12 +01:00
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
|
|
use PHPUnit\Framework\MockObject\Stub;
|
2022-01-26 15:56:28 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2023-11-27 10:04:42 +01:00
|
|
|
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
|
2023-11-09 10:27:43 +01:00
|
|
|
use WerkraumMedia\Events\Domain\Model\Import;
|
|
|
|
use WerkraumMedia\Events\Service\DestinationDataImportService\UrlFactory;
|
2022-01-26 14:16:12 +01:00
|
|
|
|
|
|
|
class UrlFactoryTest extends TestCase
|
|
|
|
{
|
2023-11-27 10:04:42 +01:00
|
|
|
#[Test]
|
2022-01-26 14:16:12 +01:00
|
|
|
public function canBeCreated(): void
|
|
|
|
{
|
2023-11-27 10:04:42 +01:00
|
|
|
$configurationManager = $this->createStub(BackendConfigurationManager::class);
|
|
|
|
$configurationManager->method('getConfiguration')->willReturn([]);
|
2022-01-26 14:16:12 +01:00
|
|
|
|
|
|
|
$subject = new UrlFactory(
|
2023-11-27 10:04:42 +01:00
|
|
|
$configurationManager
|
2022-01-26 14:16:12 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
self::assertInstanceOf(
|
|
|
|
UrlFactory::class,
|
|
|
|
$subject
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
#[DataProvider('possibleImports')]
|
|
|
|
#[Test]
|
2022-01-26 14:16:12 +01:00
|
|
|
public function createSearchResultUrl(
|
2023-11-27 10:04:42 +01:00
|
|
|
Stub $import,
|
2022-01-26 14:16:12 +01:00
|
|
|
array $settings,
|
|
|
|
string $expectedResult
|
|
|
|
): void {
|
2023-11-27 10:04:42 +01:00
|
|
|
$configurationManager = $this->createStub(BackendConfigurationManager::class);
|
|
|
|
$configurationManager->method('getConfiguration')->willReturn(['settings' => ['destinationData' => $settings]]);
|
2022-01-26 14:16:12 +01:00
|
|
|
|
|
|
|
$subject = new UrlFactory(
|
2023-11-27 10:04:42 +01:00
|
|
|
$configurationManager
|
2022-01-26 14:16:12 +01:00
|
|
|
);
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
$result = $subject->createSearchResultUrl($import);
|
2022-01-26 14:16:12 +01:00
|
|
|
|
|
|
|
self::assertSame(
|
|
|
|
$result,
|
|
|
|
$expectedResult
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
public static function possibleImports(): array
|
2022-01-26 14:16:12 +01:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'All provided' => [
|
|
|
|
'import' => (function () {
|
2023-11-27 10:04:42 +01:00
|
|
|
$import = self::createStub(Import::class);
|
|
|
|
$import->method('getRestExperience')->willReturn('experience');
|
|
|
|
$import->method('getSearchQuery')->willReturn('');
|
2022-01-26 14:16:12 +01:00
|
|
|
|
|
|
|
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 () {
|
2023-11-27 10:04:42 +01:00
|
|
|
$import = self::createStub(Import::class);
|
|
|
|
$import->method('getRestExperience')->willReturn('');
|
|
|
|
$import->method('getSearchQuery')->willReturn('');
|
2022-01-26 14:16:12 +01:00
|
|
|
|
|
|
|
return $import;
|
|
|
|
})(),
|
|
|
|
'settings' => [
|
|
|
|
'restUrl' => 'https://example.com/path',
|
|
|
|
],
|
|
|
|
'expectedResult' => 'https://example.com/path',
|
|
|
|
],
|
|
|
|
'Some missing' => [
|
|
|
|
'import' => (function () {
|
2023-11-27 10:04:42 +01:00
|
|
|
$import = self::createStub(Import::class);
|
|
|
|
$import->method('getRestExperience')->willReturn('experience');
|
|
|
|
$import->method('getSearchQuery')->willReturn('');
|
2022-01-26 14:16:12 +01:00
|
|
|
|
|
|
|
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',
|
|
|
|
],
|
2022-01-26 14:43:14 +01:00
|
|
|
'With search query' => [
|
|
|
|
'import' => (function () {
|
2023-11-27 10:04:42 +01:00
|
|
|
$import = self::createStub(Import::class);
|
|
|
|
$import->method('getRestExperience')->willReturn('experience');
|
|
|
|
$import->method('getSearchQuery')->willReturn('name:"Test Something"');
|
2022-01-26 14:43:14 +01:00
|
|
|
|
|
|
|
return $import;
|
|
|
|
})(),
|
|
|
|
'settings' => [
|
|
|
|
'restUrl' => 'https://example.com/path',
|
|
|
|
],
|
|
|
|
'expectedResult' => 'https://example.com/path?experience=experience&q=name%3A%22Test+Something%22',
|
|
|
|
],
|
2022-01-26 14:16:12 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|