2022-04-21 08:07:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Wrm\Events\Tests\Unit\Service\DestinationDataImportService;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2022-07-07 09:03:31 +02:00
|
|
|
use TYPO3\CMS\Core\Context\Context;
|
2022-04-21 08:07:25 +02:00
|
|
|
use Wrm\Events\Domain\Model\Date;
|
|
|
|
use Wrm\Events\Service\DestinationDataImportService\DatesFactory;
|
2022-07-07 09:03:31 +02:00
|
|
|
use Wrm\Events\Tests\ProphecyTrait;
|
2022-04-21 08:07:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Wrm\Events\Service\DestinationDataImportService\DatesFactory
|
|
|
|
*/
|
|
|
|
class DatesFactoryTest extends TestCase
|
|
|
|
{
|
2022-07-07 09:03:31 +02:00
|
|
|
use ProphecyTrait;
|
|
|
|
|
2022-04-21 08:07:25 +02:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function canBeCreated(): void
|
|
|
|
{
|
2022-07-07 09:03:31 +02:00
|
|
|
$context = $this->prophesize(Context::class);
|
|
|
|
|
|
|
|
$subject = new DatesFactory(
|
|
|
|
$context->reveal()
|
|
|
|
);
|
2022-04-21 08:07:25 +02:00
|
|
|
|
|
|
|
self::assertInstanceOf(
|
|
|
|
DatesFactory::class,
|
|
|
|
$subject
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider possibleUnkownInput
|
|
|
|
*/
|
|
|
|
public function returnsNoResultOnUnkownInput(array $unkownInput): void
|
|
|
|
{
|
2022-07-07 09:03:31 +02:00
|
|
|
$context = $this->prophesize(Context::class);
|
|
|
|
|
|
|
|
$subject = new DatesFactory(
|
|
|
|
$context->reveal()
|
|
|
|
);
|
2022-04-21 08:07:25 +02:00
|
|
|
|
|
|
|
$result = $subject->createDates($unkownInput, false);
|
|
|
|
|
|
|
|
self::assertInstanceOf(\Generator::class, $result);
|
|
|
|
self::assertCount(0, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function possibleUnkownInput(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'Empty Intervals' => [
|
|
|
|
'unkownInput' => [],
|
|
|
|
],
|
2022-04-25 07:47:47 +02:00
|
|
|
'Single interval without values' => [
|
2022-04-21 08:07:25 +02:00
|
|
|
'unkownInput' => [
|
|
|
|
[
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnsSingleNotCanceledDate(): void
|
|
|
|
{
|
2022-07-07 09:03:31 +02:00
|
|
|
$context = $this->prophesize(Context::class);
|
|
|
|
|
|
|
|
$subject = new DatesFactory(
|
|
|
|
$context->reveal()
|
|
|
|
);
|
2022-04-21 08:07:25 +02:00
|
|
|
|
|
|
|
$result = $subject->createDates([[
|
|
|
|
'start' => '2099-06-21T16:00:00+02:00',
|
|
|
|
'end' => '2099-06-21T22:00:00+02:00',
|
|
|
|
'tz' => 'Europe/Berlin',
|
2022-04-25 07:47:47 +02:00
|
|
|
'interval' => 1,
|
2022-04-21 08:07:25 +02:00
|
|
|
]], false);
|
|
|
|
|
|
|
|
self::assertInstanceOf(\Generator::class, $result);
|
|
|
|
|
|
|
|
$firstEntry = $result->current();
|
|
|
|
|
|
|
|
self::assertCount(1, $result);
|
|
|
|
|
|
|
|
self::assertInstanceOf(Date::class, $firstEntry);
|
|
|
|
self::assertSame('4085733600', $firstEntry->getStart()->format('U'));
|
|
|
|
self::assertSame('4085755200', $firstEntry->getEnd()->format('U'));
|
|
|
|
self::assertSame('no', $firstEntry->getCanceled());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnsSingleCanceledDate(): void
|
|
|
|
{
|
2022-07-07 09:03:31 +02:00
|
|
|
$context = $this->prophesize(Context::class);
|
|
|
|
|
|
|
|
$subject = new DatesFactory(
|
|
|
|
$context->reveal()
|
|
|
|
);
|
2022-04-21 08:07:25 +02:00
|
|
|
|
|
|
|
$result = $subject->createDates([[
|
|
|
|
'start' => '2099-06-21T16:00:00+02:00',
|
|
|
|
'end' => '2099-06-21T22:00:00+02:00',
|
|
|
|
'tz' => 'Europe/Berlin',
|
2022-04-25 07:47:47 +02:00
|
|
|
'interval' => 1,
|
2022-04-21 08:07:25 +02:00
|
|
|
]], true);
|
|
|
|
|
|
|
|
self::assertInstanceOf(\Generator::class, $result);
|
|
|
|
$result = iterator_to_array($result);
|
|
|
|
|
|
|
|
self::assertCount(1, $result);
|
|
|
|
|
|
|
|
self::assertInstanceOf(Date::class, $result[0]);
|
|
|
|
self::assertSame('4085733600', $result[0]->getStart()->format('U'));
|
|
|
|
self::assertSame('4085755200', $result[0]->getEnd()->format('U'));
|
|
|
|
self::assertSame('canceled', $result[0]->getCanceled());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnsCanceledDatesOnDailyBasis(): void
|
|
|
|
{
|
2022-07-07 09:03:31 +02:00
|
|
|
$context = $this->prophesize(Context::class);
|
|
|
|
|
|
|
|
$subject = new DatesFactory(
|
|
|
|
$context->reveal()
|
|
|
|
);
|
2022-04-21 08:07:25 +02:00
|
|
|
|
|
|
|
$result = $subject->createDates([[
|
|
|
|
'start' => '2099-04-01T16:00:00+02:00',
|
|
|
|
'end' => '2099-04-01T17:00:00+02:00',
|
|
|
|
'repeatUntil' => '2099-04-03T18:00:00+02:00',
|
|
|
|
'tz' => 'Europe/Berlin',
|
|
|
|
'freq' => 'Daily',
|
|
|
|
'interval' => 1,
|
|
|
|
]], true);
|
|
|
|
|
|
|
|
self::assertInstanceOf(\Generator::class, $result);
|
|
|
|
$result = iterator_to_array($result);
|
|
|
|
|
|
|
|
self::assertCount(3, $result);
|
|
|
|
|
|
|
|
self::assertInstanceOf(Date::class, $result[0]);
|
2022-07-13 15:58:05 +02:00
|
|
|
self::assertSame('4078735200', $result[0]->getStart()->format('U'));
|
|
|
|
self::assertSame('4078738800', $result[0]->getEnd()->format('U'));
|
2022-04-21 08:07:25 +02:00
|
|
|
self::assertSame('canceled', $result[0]->getCanceled());
|
|
|
|
|
2022-07-13 15:58:05 +02:00
|
|
|
self::assertSame('4078908000', $result[2]->getStart()->format('U'));
|
|
|
|
self::assertSame('4078911600', $result[2]->getEnd()->format('U'));
|
2022-04-21 08:07:25 +02:00
|
|
|
self::assertSame('canceled', $result[2]->getCanceled());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnsNotCanceledDatesOnDailyBasis(): void
|
|
|
|
{
|
2022-07-07 09:03:31 +02:00
|
|
|
$context = $this->prophesize(Context::class);
|
2022-04-21 08:07:25 +02:00
|
|
|
|
2022-07-07 09:03:31 +02:00
|
|
|
$subject = new DatesFactory(
|
|
|
|
$context->reveal()
|
|
|
|
);
|
2022-04-21 08:07:25 +02:00
|
|
|
|
|
|
|
$result = $subject->createDates([[
|
|
|
|
'start' => '2099-04-01T16:00:00+02:00',
|
|
|
|
'end' => '2099-04-01T17:00:00+02:00',
|
|
|
|
'repeatUntil' => '2099-04-03T18:00:00+02:00',
|
|
|
|
'tz' => 'Europe/Berlin',
|
|
|
|
'freq' => 'Daily',
|
|
|
|
'interval' => 1,
|
|
|
|
]], false);
|
|
|
|
|
|
|
|
self::assertInstanceOf(\Generator::class, $result);
|
|
|
|
$result = iterator_to_array($result);
|
|
|
|
|
|
|
|
self::assertCount(3, $result);
|
|
|
|
|
|
|
|
self::assertInstanceOf(Date::class, $result[0]);
|
2022-07-13 15:58:05 +02:00
|
|
|
self::assertSame('4078735200', $result[0]->getStart()->format('U'));
|
|
|
|
self::assertSame('4078738800', $result[0]->getEnd()->format('U'));
|
2022-04-21 08:07:25 +02:00
|
|
|
self::assertSame('no', $result[0]->getCanceled());
|
|
|
|
|
2022-07-13 15:58:05 +02:00
|
|
|
self::assertSame('4078908000', $result[2]->getStart()->format('U'));
|
|
|
|
self::assertSame('4078911600', $result[2]->getEnd()->format('U'));
|
2022-04-21 08:07:25 +02:00
|
|
|
self::assertSame('no', $result[2]->getCanceled());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnsCanceledDatesOnWeeklyBasis(): void
|
|
|
|
{
|
2022-07-07 09:03:31 +02:00
|
|
|
$context = $this->prophesize(Context::class);
|
|
|
|
|
|
|
|
$subject = new DatesFactory(
|
|
|
|
$context->reveal()
|
|
|
|
);
|
2022-04-21 08:07:25 +02:00
|
|
|
|
|
|
|
$result = $subject->createDates([[
|
|
|
|
'weekdays' => [
|
|
|
|
'Saturday',
|
|
|
|
'Sunday',
|
|
|
|
],
|
|
|
|
'start' => '2099-03-02T11:00:00+01:00',
|
|
|
|
'end' => '2099-03-02T13:00:00+01:00',
|
|
|
|
'repeatUntil' => '2099-03-15T13:00:00+02:00',
|
|
|
|
'tz' => 'Europe/Berlin',
|
|
|
|
'freq' => 'Weekly',
|
|
|
|
'interval' => 1,
|
|
|
|
]], true);
|
|
|
|
|
|
|
|
self::assertInstanceOf(\Generator::class, $result);
|
|
|
|
$result = iterator_to_array($result);
|
|
|
|
|
|
|
|
self::assertCount(4, $result);
|
|
|
|
|
|
|
|
self::assertInstanceOf(Date::class, $result[0]);
|
2022-07-07 14:10:49 +02:00
|
|
|
self::assertSame('4076560800', $result[0]->getStart()->format('U'));
|
|
|
|
self::assertSame('4076568000', $result[0]->getEnd()->format('U'));
|
2022-04-21 08:07:25 +02:00
|
|
|
self::assertSame('canceled', $result[0]->getCanceled());
|
|
|
|
|
2022-07-07 14:10:49 +02:00
|
|
|
self::assertSame('4077252000', $result[3]->getStart()->format('U'));
|
|
|
|
self::assertSame('4077259200', $result[3]->getEnd()->format('U'));
|
2022-04-21 08:07:25 +02:00
|
|
|
self::assertSame('canceled', $result[3]->getCanceled());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnsNotCanceledDatesOnWeeklyBasis(): void
|
|
|
|
{
|
2022-07-07 09:03:31 +02:00
|
|
|
$context = $this->prophesize(Context::class);
|
|
|
|
|
|
|
|
$subject = new DatesFactory(
|
|
|
|
$context->reveal()
|
|
|
|
);
|
2022-04-21 08:07:25 +02:00
|
|
|
|
|
|
|
$result = $subject->createDates([[
|
|
|
|
'weekdays' => [
|
|
|
|
'Saturday',
|
|
|
|
'Sunday',
|
|
|
|
],
|
|
|
|
'start' => '2099-03-02T11:00:00+01:00',
|
|
|
|
'end' => '2099-03-02T13:00:00+01:00',
|
|
|
|
'repeatUntil' => '2099-03-15T13:00:00+02:00',
|
|
|
|
'tz' => 'Europe/Berlin',
|
|
|
|
'freq' => 'Weekly',
|
|
|
|
'interval' => 1,
|
|
|
|
]], false);
|
|
|
|
|
|
|
|
self::assertInstanceOf(\Generator::class, $result);
|
|
|
|
$result = iterator_to_array($result);
|
|
|
|
|
|
|
|
self::assertCount(4, $result);
|
|
|
|
|
|
|
|
self::assertInstanceOf(Date::class, $result[0]);
|
2022-07-07 14:10:49 +02:00
|
|
|
self::assertSame('4076560800', $result[0]->getStart()->format('U'));
|
|
|
|
self::assertSame('4076568000', $result[0]->getEnd()->format('U'));
|
2022-04-21 08:07:25 +02:00
|
|
|
self::assertSame('no', $result[0]->getCanceled());
|
|
|
|
|
2022-07-07 14:10:49 +02:00
|
|
|
self::assertSame('4077252000', $result[3]->getStart()->format('U'));
|
|
|
|
self::assertSame('4077259200', $result[3]->getEnd()->format('U'));
|
2022-04-21 08:07:25 +02:00
|
|
|
self::assertSame('no', $result[3]->getCanceled());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnsCanceledDatesOnMixedIntervals(): void
|
|
|
|
{
|
2022-07-07 09:03:31 +02:00
|
|
|
$context = $this->prophesize(Context::class);
|
|
|
|
|
|
|
|
$subject = new DatesFactory(
|
|
|
|
$context->reveal()
|
|
|
|
);
|
2022-04-21 08:07:25 +02:00
|
|
|
|
|
|
|
$result = $subject->createDates([
|
|
|
|
[
|
|
|
|
'start' => '2099-06-21T16:00:00+02:00',
|
|
|
|
'end' => '2099-06-21T22:00:00+02:00',
|
|
|
|
'tz' => 'Europe/Berlin',
|
2022-04-25 07:47:47 +02:00
|
|
|
'interval' => 1,
|
2022-04-21 08:07:25 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'start' => '2099-04-01T16:00:00+02:00',
|
|
|
|
'end' => '2099-04-01T17:00:00+02:00',
|
|
|
|
'repeatUntil' => '2099-04-03T18:00:00+02:00',
|
|
|
|
'tz' => 'Europe/Berlin',
|
|
|
|
'freq' => 'Daily',
|
|
|
|
'interval' => 1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'weekdays' => [
|
|
|
|
'Saturday',
|
|
|
|
'Sunday',
|
|
|
|
],
|
|
|
|
'start' => '2099-03-02T11:00:00+01:00',
|
|
|
|
'end' => '2099-03-02T13:00:00+01:00',
|
|
|
|
'repeatUntil' => '2099-03-15T13:00:00+02:00',
|
|
|
|
'tz' => 'Europe/Berlin',
|
|
|
|
'freq' => 'Weekly',
|
|
|
|
'interval' => 1,
|
|
|
|
],
|
|
|
|
], true);
|
|
|
|
|
|
|
|
self::assertInstanceOf(\Generator::class, $result);
|
|
|
|
$result = iterator_to_array($result);
|
|
|
|
|
|
|
|
self::assertCount(8, $result);
|
|
|
|
|
|
|
|
foreach ($result as $date) {
|
|
|
|
self::assertInstanceOf(Date::class, $date);
|
|
|
|
self::assertSame('canceled', $date->getCanceled());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnsNotCanceledDatesOnMixedIntervals(): void
|
|
|
|
{
|
2022-07-07 09:03:31 +02:00
|
|
|
$context = $this->prophesize(Context::class);
|
|
|
|
|
|
|
|
$subject = new DatesFactory(
|
|
|
|
$context->reveal()
|
|
|
|
);
|
2022-04-21 08:07:25 +02:00
|
|
|
|
|
|
|
$result = $subject->createDates([
|
|
|
|
[
|
|
|
|
'start' => '2099-06-21T16:00:00+02:00',
|
|
|
|
'end' => '2099-06-21T22:00:00+02:00',
|
|
|
|
'tz' => 'Europe/Berlin',
|
2022-04-25 07:47:47 +02:00
|
|
|
'interval' => 1,
|
2022-04-21 08:07:25 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'start' => '2099-04-01T16:00:00+02:00',
|
|
|
|
'end' => '2099-04-01T17:00:00+02:00',
|
|
|
|
'repeatUntil' => '2099-04-03T18:00:00+02:00',
|
|
|
|
'tz' => 'Europe/Berlin',
|
|
|
|
'freq' => 'Daily',
|
|
|
|
'interval' => 1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'weekdays' => [
|
|
|
|
'Saturday',
|
|
|
|
'Sunday',
|
|
|
|
],
|
|
|
|
'start' => '2099-03-02T11:00:00+01:00',
|
|
|
|
'end' => '2099-03-02T13:00:00+01:00',
|
|
|
|
'repeatUntil' => '2099-03-15T13:00:00+02:00',
|
|
|
|
'tz' => 'Europe/Berlin',
|
|
|
|
'freq' => 'Weekly',
|
|
|
|
'interval' => 1,
|
|
|
|
],
|
|
|
|
], false);
|
|
|
|
|
|
|
|
self::assertInstanceOf(\Generator::class, $result);
|
|
|
|
$result = iterator_to_array($result);
|
|
|
|
|
|
|
|
self::assertCount(8, $result);
|
|
|
|
|
|
|
|
foreach ($result as $date) {
|
|
|
|
self::assertInstanceOf(Date::class, $date);
|
|
|
|
self::assertSame('no', $date->getCanceled());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|