2025-06-10 22:03:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Drupal\Tests\opd_presentations\Traits;
|
|
|
|
|
|
|
|
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
2025-06-12 02:10:08 +01:00
|
|
|
use Drupal\ctools\Testing\EntityCreationTrait;
|
2025-06-12 23:27:58 +01:00
|
|
|
use Drupal\opd_presentations\Date;
|
2025-06-12 02:10:08 +01:00
|
|
|
use Drupal\opd_presentations\Event;
|
2025-06-15 09:58:14 +01:00
|
|
|
use Drupal\opd_presentations\Events;
|
2025-06-15 09:43:43 +01:00
|
|
|
use Drupal\opd_presentations\Presentation;
|
2025-06-10 22:03:15 +01:00
|
|
|
|
|
|
|
trait PresentationCreationTrait {
|
|
|
|
|
2025-06-12 02:10:08 +01:00
|
|
|
use EntityCreationTrait;
|
2025-06-15 09:43:43 +01:00
|
|
|
use NodeCreationTrait;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Event[] $events
|
2025-06-15 16:31:51 +01:00
|
|
|
* @param bool $isPublished
|
2025-06-15 09:43:43 +01:00
|
|
|
*/
|
2025-06-15 09:58:14 +01:00
|
|
|
private function createPresentation(Events $events, bool $isPublished = TRUE): Presentation {
|
2025-06-15 09:43:43 +01:00
|
|
|
$presentation = $this->createNode([
|
2025-06-15 09:58:14 +01:00
|
|
|
'field_events' => $events->toEvents(),
|
2025-06-15 09:43:43 +01:00
|
|
|
'status' => $isPublished,
|
|
|
|
'type' => Presentation::NODE_TYPE,
|
|
|
|
]);
|
|
|
|
|
|
|
|
assert($presentation instanceof Presentation);
|
|
|
|
|
|
|
|
return $presentation;
|
|
|
|
}
|
2025-06-10 22:03:15 +01:00
|
|
|
|
2025-06-12 23:27:58 +01:00
|
|
|
private function createEvent(string $eventName, Date $eventDate): Event {
|
2025-06-12 02:10:08 +01:00
|
|
|
$event = $this->createEntity(
|
|
|
|
entity_type: 'paragraph',
|
|
|
|
values: [
|
2025-06-12 23:27:58 +01:00
|
|
|
'field_date' => $eventDate->toTimestamp(),
|
2025-06-11 09:54:18 +01:00
|
|
|
'field_event_name' => $eventName,
|
2025-06-12 02:10:08 +01:00
|
|
|
'type' => Event::PARAGRAPH_TYPE,
|
2025-06-11 09:46:17 +01:00
|
|
|
],
|
|
|
|
);
|
2025-06-12 02:10:08 +01:00
|
|
|
|
|
|
|
assert($event instanceof Event);
|
|
|
|
|
|
|
|
return $event;
|
2025-06-10 22:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|