Extract a PresentationCreationTrait

This commit is contained in:
Oliver Davies 2025-06-10 22:03:15 +01:00
parent f2a27cab78
commit d010b12667
2 changed files with 44 additions and 27 deletions

View file

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\opd_presentations\Traits;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\opd_presentations\Entity\Presentation;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\paragraphs\ParagraphInterface;
trait PresentationCreationTrait {
use NodeCreationTrait;
/**
* @param ParagraphInterface[] $events
*/
private function createPresentation(array $events): Presentation {
$presentation = $this->createNode([
'field_events' => $events,
'type' => 'presentation',
]);
assert($presentation instanceof Presentation);
return $presentation;
}
/**
* @param array<non-empty-string, mixed> $values
*/
private function createEvent(array $values = []): ParagraphInterface {
return Paragraph::create(array_merge(
['type' => 'event'],
$values,
));
}
}