Skip to content

Commit

Permalink
[FEATURE] Add Event.registrationPossibleByDate (#4031)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverklee authored Jan 7, 2025
1 parent 56e51ba commit 066aa40
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Classes/Domain/Model/Event/EventDateInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public function getRegistrationDeadline(): ?\DateTime;

public function isRegistrationRequired(): bool;

public function isRegistrationPossibleByDate(): bool;

public function setRegistrationPossibleByDate(bool $possible): void;

public function hasWaitingList(): bool;

/**
Expand Down
25 changes: 25 additions & 0 deletions Classes/Domain/Model/Event/EventDateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ trait EventDateTrait

protected bool $registrationRequired = false;

/**
* This property is expected to be set from the outside by the `RegistationGuard`.
*
* @Transient
*/
protected ?bool $registrationPossibleByDate = null;

protected bool $waitingList = false;

/**
Expand Down Expand Up @@ -196,6 +203,24 @@ public function setRegistrationRequired(bool $registrationRequired): void
$this->registrationRequired = $registrationRequired;
}

/**
* @throws \BadMethodCallException if registrationPossibleByDate has not been set yet
*/
public function isRegistrationPossibleByDate(): bool
{
$possible = $this->registrationPossibleByDate;
if (!\is_bool($possible)) {
throw new \BadMethodCallException('registrationPossibleByDate has not been set set.', 1736269500);
}

return $possible;
}

public function setRegistrationPossibleByDate(bool $possible): void
{
$this->registrationPossibleByDate = $possible;
}

public function hasWaitingList(): bool
{
return $this->waitingList;
Expand Down
5 changes: 5 additions & 0 deletions Classes/Domain/Model/Event/EventTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public function getStatistics(): ?EventStatistics
{
return null;
}

public function isRegistrationPossibleByDate(): bool
{
return false;
}
}
10 changes: 10 additions & 0 deletions Classes/Service/RegistrationGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ public function isRegistrationPossibleByDate(EventDateInterface $event): bool
return $registrationIsEarlyEnough && $registrationIsLateEnough;
}

/**
* @param array<EventDateInterface> $events
*/
public function setRegistrationPossibleByDateForEvents(array $events): void
{
foreach ($events as $event) {
$event->setRegistrationPossibleByDate($this->isRegistrationPossibleByDate($event));
}
}

private function getRegistrationDeadlineForEvent(EventDateInterface $event): ?\DateTime
{
if ($event->getStart() === null && $event->getRegistrationDeadline() === null) {
Expand Down
34 changes: 34 additions & 0 deletions Tests/Unit/Domain/Model/Event/EventDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1382,4 +1382,38 @@ public function getCityNamesSortsCityNames(): void

self::assertSame([$cityName2, $cityName1], $result);
}

/**
* @test
*/
public function isRegistrationPossibleByDateInitiallyThrowsException(): void
{
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('registrationPossibleByDate has not been set set.');
$this->expectExceptionCode(1736269500);

$this->subject->isRegistrationPossibleByDate();
}

/**
* @return array<string, array{0: bool}>
*/
public static function booleanDataProvider(): array
{
return [
'true' => [true],
'false' => [false],
];
}

/**
* @test
* @dataProvider booleanDataProvider
*/
public function setRegistrationPossibleByDateSetsRegistrationPossibleByDate(bool $value): void
{
$this->subject->setRegistrationPossibleByDate($value);

self::assertSame($value, $this->subject->isRegistrationPossibleByDate());
}
}
8 changes: 8 additions & 0 deletions Tests/Unit/Domain/Model/Event/EventTopicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,4 +581,12 @@ public function getStatisticsReturnsNull(): void
{
self::assertNull($this->subject->getStatistics());
}

/**
* @test
*/
public function isRegistrationPossibleByDateAlwaysReturnsFalse(): void
{
self::assertFalse($this->subject->isRegistrationPossibleByDate());
}
}
34 changes: 34 additions & 0 deletions Tests/Unit/Domain/Model/Event/SingleEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1503,4 +1503,38 @@ public function getCityNamesSortsCityNames(): void

self::assertSame([$cityName2, $cityName1], $result);
}

/**
* @test
*/
public function isRegistrationPossibleByDateInitiallyThrowsException(): void
{
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('registrationPossibleByDate has not been set set.');
$this->expectExceptionCode(1736269500);

$this->subject->isRegistrationPossibleByDate();
}

/**
* @return array<string, array{0: bool}>
*/
public static function booleanDataProvider(): array
{
return [
'true' => [true],
'false' => [false],
];
}

/**
* @test
* @dataProvider booleanDataProvider
*/
public function setRegistrationPossibleByDateSetsRegistrationPossibleByDate(bool $value): void
{
$this->subject->setRegistrationPossibleByDate($value);

self::assertSame($value, $this->subject->isRegistrationPossibleByDate());
}
}
44 changes: 44 additions & 0 deletions Tests/Unit/Service/RegistrationGuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,50 @@ public function isRegistrationPossibleByDateForSingleEventWithRegistrationNotPos
self::assertFalse($this->subject->isRegistrationPossibleByDate($event));
}

/**
* @test
*
* @dataProvider registrationPossibleDataProvider
*/
public function setRegistrationPossibleByDateForEventsCanSetTruePossibilityForGivenEvents(
?\DateTime $start,
?\DateTime $registrationStart,
?\DateTime $registrationDeadline
): void {
$this->contextMock->method('getPropertyFromAspect')->with('date', 'full')->willReturn($this->now());

$event = new SingleEvent();
$event->setStart($start);
$event->setRegistrationStart($registrationStart);
$event->setRegistrationDeadline($registrationDeadline);

$this->subject->setRegistrationPossibleByDateForEvents([$event]);

self::assertTrue($event->isRegistrationPossibleByDate());
}

/**
* @test
*
* @dataProvider registrationNotPossibleDataProvider
*/
public function setRegistrationPossibleByDateForEventsCanSetFalsePossibilityForGivenEvents(
?\DateTime $start,
?\DateTime $registrationStart,
?\DateTime $registrationDeadline
): void {
$this->contextMock->method('getPropertyFromAspect')->with('date', 'full')->willReturn($this->now());

$event = new SingleEvent();
$event->setStart($start);
$event->setRegistrationStart($registrationStart);
$event->setRegistrationDeadline($registrationDeadline);

$this->subject->setRegistrationPossibleByDateForEvents([$event]);

self::assertFalse($event->isRegistrationPossibleByDate());
}

/**
* @test
*/
Expand Down

0 comments on commit 066aa40

Please sign in to comment.