From 678263c75cd5485abf7804a36e49a92d1e757700 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 15 Jun 2025 09:43:43 +0100 Subject: [PATCH] Revert "Add `PresentationBuilder`" This reverts commit 9148ec5a65befd8defd7c94645a3262b07c32607. --- .../src/PresentationBuilder.php | 40 ----------- .../Functional/PresentationCounterTest.php | 66 ++++++++----------- .../src/Traits/PresentationCreationTrait.php | 18 +++++ 3 files changed, 47 insertions(+), 77 deletions(-) delete mode 100644 modules/opd_presentations/src/PresentationBuilder.php diff --git a/modules/opd_presentations/src/PresentationBuilder.php b/modules/opd_presentations/src/PresentationBuilder.php deleted file mode 100644 index 8a9495bb9..000000000 --- a/modules/opd_presentations/src/PresentationBuilder.php +++ /dev/null @@ -1,40 +0,0 @@ - $this->events, - 'status' => $this->isPublished, - 'title' => $this->title, - ]); - } - - public function setEvents(array $events): self { - $this->events = $events; - - return $this; - } - - public function setPublished(bool $isPublished = TRUE): self { - $this->isPublished = $isPublished; - - return $this; - } - - public static function create(string $title): self { - return new self($title); - } - -} diff --git a/modules/opd_presentations/tests/src/Functional/PresentationCounterTest.php b/modules/opd_presentations/tests/src/Functional/PresentationCounterTest.php index 506c48bcc..27e1e28d4 100644 --- a/modules/opd_presentations/tests/src/Functional/PresentationCounterTest.php +++ b/modules/opd_presentations/tests/src/Functional/PresentationCounterTest.php @@ -7,7 +7,6 @@ namespace Drupal\Tests\opd_presentations; use Drupal\Tests\RandomGeneratorTrait; use Drupal\Tests\opd_presentations\Traits\PresentationCreationTrait; use Drupal\opd_presentations\Date; -use Drupal\opd_presentations\PresentationBuilder; use Drupal\opd_presentations\PresentationCounter; use weitzman\DrupalTestTraits\ExistingSiteBase; @@ -20,16 +19,14 @@ final class PresentationCounterTest extends ExistingSiteBase { $counter = $this->container->get(PresentationCounter::class); assert($counter instanceof PresentationCounter); - $events = [ - $this->createEvent( - eventDate: Date::fromString('yesterday'), - eventName: $this->randomString(), - ), - ]; - - PresentationBuilder::create('') - ->setEvents($events) - ->build(); + $this->createPresentation( + events: [ + $this->createEvent( + eventDate: Date::fromString('yesterday'), + eventName: $this->randomString(), + ), + ], + ); $this->assertGreaterThanOrEqual( actual: $counter->getPastCount(), @@ -43,17 +40,15 @@ final class PresentationCounterTest extends ExistingSiteBase { $count = $counter->getPastCount(); - $events = [ - $this->createEvent( - eventDate: Date::fromString('yesterday'), - eventName: $this->randomString(), - ), - ]; - - $presentation = PresentationBuilder::create('') - ->setEvents($events) - ->setPublished(FALSE) - ->build(); + $this->createPresentation( + events: [ + $this->createEvent( + eventDate: Date::fromString('yesterday'), + eventName: $this->randomString(), + ), + ], + isPublished: FALSE, + ); $this->assertSame( actual: $counter->getPastCount(), @@ -73,22 +68,19 @@ final class PresentationCounterTest extends ExistingSiteBase { expected: 0, ); - $events = [ - $this->createEvent( - eventDate: Date::fromString('tomorrow'), - eventName: $this->randomString(), - ), + $this->createPresentation( + events: [ + $this->createEvent( + eventDate: Date::fromString('tomorrow'), + eventName: $this->randomString(), + ), - $this->createEvent( - eventDate: Date::fromString('yesterday'), - eventName: $this->randomString(), - ), - ]; - - $presentation = PresentationBuilder::create($this->randomString()) - ->setEvents($events) - ->build(); - $presentation->save(); + $this->createEvent( + eventDate: Date::fromString('yesterday'), + eventName: $this->randomString(), + ), + ], + ); $counter = $this->container->get(PresentationCounter::class); diff --git a/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php b/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php index 2a5baa791..d165fe6e5 100644 --- a/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php +++ b/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php @@ -4,14 +4,32 @@ declare(strict_types=1); namespace Drupal\Tests\opd_presentations\Traits; +use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Tests\node\Traits\NodeCreationTrait; use Drupal\ctools\Testing\EntityCreationTrait; use Drupal\opd_presentations\Date; use Drupal\opd_presentations\Event; +use Drupal\opd_presentations\Presentation; trait PresentationCreationTrait { use EntityCreationTrait; + use NodeCreationTrait; + + /** + * @param Event[] $events + */ + private function createPresentation(array $events, bool $isPublished = TRUE): Presentation { + $presentation = $this->createNode([ + 'field_events' => $events, + 'status' => $isPublished, + 'type' => Presentation::NODE_TYPE, + ]); + + assert($presentation instanceof Presentation); + + return $presentation; + } private function createEvent(string $eventName, Date $eventDate): Event { $event = $this->createEntity(