Extract a PresentationCreationTrait
This commit is contained in:
parent
f2a27cab78
commit
d010b12667
2 changed files with 44 additions and 27 deletions
|
@ -5,13 +5,13 @@ declare(strict_types=1);
|
|||
namespace Drupal\opd_presentations\DrupalTestTraits\Entity;
|
||||
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\opd_presentations\Entity\Presentation;
|
||||
use Drupal\paragraphs\Entity\Paragraph;
|
||||
use Drupal\paragraphs\ParagraphInterface;
|
||||
use Drupal\Tests\opd_presentations\Traits\PresentationCreationTrait;
|
||||
use weitzman\DrupalTestTraits\ExistingSiteBase;
|
||||
|
||||
final class PresentationTest extends ExistingSiteBase {
|
||||
|
||||
use PresentationCreationTrait;
|
||||
|
||||
public function test_getting_past_events(): void {
|
||||
$presentation = $this->createPresentation(
|
||||
events: [
|
||||
|
@ -27,28 +27,4 @@ final class PresentationTest extends ExistingSiteBase {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue