89 lines
3.2 KiB
PHP
89 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Entity\Groups;
|
|
|
|
use App\Entity\Groups\AccommodationBooking;
|
|
use App\Enum\Groups\AccommodationBookingOrigin;
|
|
use App\Enum\Groups\AccommodationBookingStatus;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class AccommodationBookingTest extends TestCase
|
|
{
|
|
/**
|
|
* The label is what the backoffice prints next to the status, so it must never
|
|
* contradict it — "Angebot · Bestätigt" is the shape of mistake this replaces.
|
|
*
|
|
* @dataProvider statusesBeforeTheCustomerCommits
|
|
*/
|
|
public function testARecordIsCalledAnOfferUntilTheCustomerCommits(AccommodationBookingStatus $status): void
|
|
{
|
|
$booking = new AccommodationBooking();
|
|
$booking->setStatus($status);
|
|
|
|
self::assertNull($booking->getAcceptedAt());
|
|
self::assertSame('Angebot', $booking->recordLabel());
|
|
}
|
|
|
|
/**
|
|
* @return iterable<string, array{AccommodationBookingStatus}>
|
|
*/
|
|
public static function statusesBeforeTheCustomerCommits(): iterable
|
|
{
|
|
yield 'draft' => [AccommodationBookingStatus::Draft];
|
|
yield 'requested' => [AccommodationBookingStatus::Requested];
|
|
yield 'open' => [AccommodationBookingStatus::Open];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider statusesAfterTheCustomerCommits
|
|
*/
|
|
public function testARecordIsCalledABookingOnceTheCustomerHasCommitted(AccommodationBookingStatus $status): void
|
|
{
|
|
$booking = new AccommodationBooking();
|
|
$booking->setStatus($status);
|
|
$booking->setAcceptedAt(new \DateTimeImmutable());
|
|
|
|
self::assertSame('Buchung', $booking->recordLabel());
|
|
}
|
|
|
|
/**
|
|
* @return iterable<string, array{AccommodationBookingStatus}>
|
|
*/
|
|
public static function statusesAfterTheCustomerCommits(): iterable
|
|
{
|
|
yield 'received' => [AccommodationBookingStatus::Received];
|
|
yield 'confirmed' => [AccommodationBookingStatus::Confirmed];
|
|
}
|
|
|
|
public function testADiscardedRecordKeepsWhicheverItHadBecome(): void
|
|
{
|
|
// An Absage can close either an offer nobody accepted or a booking that fell
|
|
// through, so the label follows the commitment rather than the status.
|
|
$unaccepted = new AccommodationBooking();
|
|
$unaccepted->setStatus(AccommodationBookingStatus::Discarded);
|
|
|
|
$accepted = new AccommodationBooking();
|
|
$accepted->setStatus(AccommodationBookingStatus::Discarded);
|
|
$accepted->setAcceptedAt(new \DateTimeImmutable());
|
|
|
|
self::assertSame('Angebot', $unaccepted->recordLabel());
|
|
self::assertSame('Buchung', $accepted->recordLabel());
|
|
}
|
|
|
|
public function testTheLabelIsIndependentOfWhereTheBookingCameFrom(): void
|
|
{
|
|
// Origin answers "how did this come about" and is deliberately not the same
|
|
// question — a confirmed booking that started as an offer is still a Buchung.
|
|
foreach (AccommodationBookingOrigin::cases() as $origin) {
|
|
$booking = new AccommodationBooking();
|
|
$booking->setOrigin($origin);
|
|
$booking->setStatus(AccommodationBookingStatus::Confirmed);
|
|
$booking->setAcceptedAt(new \DateTimeImmutable());
|
|
|
|
self::assertSame('Buchung', $booking->recordLabel(), $origin->value);
|
|
}
|
|
}
|
|
}
|