feat: edit selected accommodation of bookings in draft
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Form\Admin\Groups;
|
||||
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Form\Admin\Groups\AccommodationBookingChangeAccommodationType;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class AccommodationBookingChangeAccommodationTypeTest extends TestCase
|
||||
{
|
||||
public function testTheHouseIsTheOnlyThingOnOffer(): void
|
||||
{
|
||||
self::assertSame(['accommodation'], array_keys($this->builtFields()));
|
||||
}
|
||||
|
||||
public function testTheFieldIsUnmapped(): void
|
||||
{
|
||||
// Swapping the house drops the booked services with it, so the change has to go
|
||||
// through AccommodationBookingService::changeAccommodation() as one transition — the
|
||||
// form must not write it onto the booking on its own, least of all on a failed submit.
|
||||
self::assertFalse($this->builtFields()['accommodation']['mapped']);
|
||||
}
|
||||
|
||||
public function testTheCurrentHouseIsPreselected(): void
|
||||
{
|
||||
$accommodation = (new Accommodation())->setName('Seehaus');
|
||||
|
||||
$fields = $this->builtFields(['current_accommodation' => $accommodation]);
|
||||
|
||||
self::assertSame($accommodation, $fields['accommodation']['data']);
|
||||
}
|
||||
|
||||
public function testADraftIsValidatedAsAScratchRecord(): void
|
||||
{
|
||||
// The action is limited to Entwurf, whose contact data is deliberately still incomplete.
|
||||
$resolver = new OptionsResolver();
|
||||
(new AccommodationBookingChangeAccommodationType())->configureOptions($resolver);
|
||||
|
||||
self::assertSame(['Default'], $resolver->resolve()['validation_groups']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*
|
||||
* @return array<string, array<string, mixed>>
|
||||
*/
|
||||
private function builtFields(array $options = []): array
|
||||
{
|
||||
$fields = [];
|
||||
|
||||
$builder = $this->createMock(FormBuilderInterface::class);
|
||||
$builder->method('add')->willReturnCallback(
|
||||
static function (string $name, ?string $type = null, array $fieldOptions = []) use (&$fields, $builder) {
|
||||
$fields[$name] = $fieldOptions;
|
||||
|
||||
return $builder;
|
||||
},
|
||||
);
|
||||
|
||||
$resolver = new OptionsResolver();
|
||||
$type = new AccommodationBookingChangeAccommodationType();
|
||||
$type->configureOptions($resolver);
|
||||
$type->buildForm($builder, $resolver->resolve($options));
|
||||
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user