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-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
|
|
|
|
{
|
2024-11-04 14:30:18 +01:00
|
|
|
$subject = new UrlFactory();
|
2022-01-26 14:16:12 +01:00
|
|
|
|
|
|
|
self::assertInstanceOf(
|
|
|
|
UrlFactory::class,
|
|
|
|
$subject
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
#[DataProvider('possibleImports')]
|
|
|
|
#[Test]
|
2024-11-04 14:30:18 +01:00
|
|
|
/**
|
|
|
|
* @param Stub&Import $import
|
|
|
|
*/
|
2022-01-26 14:16:12 +01:00
|
|
|
public function createSearchResultUrl(
|
2024-11-04 14:30:18 +01:00
|
|
|
Import $import,
|
2022-01-26 14:16:12 +01:00
|
|
|
string $expectedResult
|
|
|
|
): void {
|
2024-11-04 14:30:18 +01:00
|
|
|
$subject = new UrlFactory();
|
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);
|
2024-11-04 14:30:18 +01:00
|
|
|
$import->method('getRestLicenseKey')->willReturn('licenseKey');
|
2023-11-27 10:04:42 +01:00
|
|
|
$import->method('getRestExperience')->willReturn('experience');
|
2024-11-04 14:30:18 +01:00
|
|
|
$import->method('getRestMode')->willReturn('restMode');
|
|
|
|
$import->method('getRestLimit')->willReturn(500);
|
|
|
|
$import->method('getRestSearchQuery')->willReturn('');
|
2022-01-26 14:16:12 +01:00
|
|
|
|
|
|
|
return $import;
|
|
|
|
})(),
|
2024-11-04 14:30:18 +01:00
|
|
|
'expectedResult' => 'http://meta.et4.de/rest.ashx/search/?experience=experience&licensekey=licenseKey&type=Event&mode=restMode&limit=500&template=ET2014A.json',
|
2022-01-26 14:16:12 +01:00
|
|
|
],
|
|
|
|
'All missing' => [
|
|
|
|
'import' => (function () {
|
2024-11-04 14:30:18 +01:00
|
|
|
return self::createStub(Import::class);
|
2022-01-26 14:16:12 +01:00
|
|
|
})(),
|
2024-11-04 14:30:18 +01:00
|
|
|
'expectedResult' => 'http://meta.et4.de/rest.ashx/search/?type=Event&template=ET2014A.json',
|
2022-01-26 14:16:12 +01:00
|
|
|
],
|
|
|
|
'Some missing' => [
|
|
|
|
'import' => (function () {
|
2023-11-27 10:04:42 +01:00
|
|
|
$import = self::createStub(Import::class);
|
2024-11-04 14:30:18 +01:00
|
|
|
$import->method('getRestLicenseKey')->willReturn('licenseKey');
|
2023-11-27 10:04:42 +01:00
|
|
|
$import->method('getRestExperience')->willReturn('experience');
|
2024-11-04 14:30:18 +01:00
|
|
|
$import->method('getRestLimit')->willReturn(500);
|
2022-01-26 14:16:12 +01:00
|
|
|
|
|
|
|
return $import;
|
|
|
|
})(),
|
2024-11-04 14:30:18 +01:00
|
|
|
'expectedResult' => 'http://meta.et4.de/rest.ashx/search/?experience=experience&licensekey=licenseKey&type=Event&limit=500&template=ET2014A.json',
|
2022-01-26 14:16:12 +01:00
|
|
|
],
|
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');
|
2024-11-04 14:30:18 +01:00
|
|
|
$import->method('getRestSearchQuery')->willReturn('name:"Test Something"');
|
2022-01-26 14:43:14 +01:00
|
|
|
|
|
|
|
return $import;
|
|
|
|
})(),
|
2024-11-04 14:30:18 +01:00
|
|
|
'expectedResult' => 'http://meta.et4.de/rest.ashx/search/?experience=experience&type=Event&template=ET2014A.json&q=name%3A%22Test+Something%22',
|
2022-01-26 14:43:14 +01:00
|
|
|
],
|
2022-01-26 14:16:12 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|