parent
8016f96b97
commit
678263c75c
3 changed files with 47 additions and 77 deletions
|
@ -1,40 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Drupal\opd_presentations;
|
|
||||||
|
|
||||||
final class PresentationBuilder {
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
private string $title,
|
|
||||||
private array $events = [],
|
|
||||||
private bool $isPublished = TRUE,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public function build(): Presentation {
|
|
||||||
return Presentation::create([
|
|
||||||
'field_events' => $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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -7,7 +7,6 @@ namespace Drupal\Tests\opd_presentations;
|
||||||
use Drupal\Tests\RandomGeneratorTrait;
|
use Drupal\Tests\RandomGeneratorTrait;
|
||||||
use Drupal\Tests\opd_presentations\Traits\PresentationCreationTrait;
|
use Drupal\Tests\opd_presentations\Traits\PresentationCreationTrait;
|
||||||
use Drupal\opd_presentations\Date;
|
use Drupal\opd_presentations\Date;
|
||||||
use Drupal\opd_presentations\PresentationBuilder;
|
|
||||||
use Drupal\opd_presentations\PresentationCounter;
|
use Drupal\opd_presentations\PresentationCounter;
|
||||||
use weitzman\DrupalTestTraits\ExistingSiteBase;
|
use weitzman\DrupalTestTraits\ExistingSiteBase;
|
||||||
|
|
||||||
|
@ -20,16 +19,14 @@ final class PresentationCounterTest extends ExistingSiteBase {
|
||||||
$counter = $this->container->get(PresentationCounter::class);
|
$counter = $this->container->get(PresentationCounter::class);
|
||||||
assert($counter instanceof PresentationCounter);
|
assert($counter instanceof PresentationCounter);
|
||||||
|
|
||||||
$events = [
|
$this->createPresentation(
|
||||||
$this->createEvent(
|
events: [
|
||||||
eventDate: Date::fromString('yesterday'),
|
$this->createEvent(
|
||||||
eventName: $this->randomString(),
|
eventDate: Date::fromString('yesterday'),
|
||||||
),
|
eventName: $this->randomString(),
|
||||||
];
|
),
|
||||||
|
],
|
||||||
PresentationBuilder::create('')
|
);
|
||||||
->setEvents($events)
|
|
||||||
->build();
|
|
||||||
|
|
||||||
$this->assertGreaterThanOrEqual(
|
$this->assertGreaterThanOrEqual(
|
||||||
actual: $counter->getPastCount(),
|
actual: $counter->getPastCount(),
|
||||||
|
@ -43,17 +40,15 @@ final class PresentationCounterTest extends ExistingSiteBase {
|
||||||
|
|
||||||
$count = $counter->getPastCount();
|
$count = $counter->getPastCount();
|
||||||
|
|
||||||
$events = [
|
$this->createPresentation(
|
||||||
$this->createEvent(
|
events: [
|
||||||
eventDate: Date::fromString('yesterday'),
|
$this->createEvent(
|
||||||
eventName: $this->randomString(),
|
eventDate: Date::fromString('yesterday'),
|
||||||
),
|
eventName: $this->randomString(),
|
||||||
];
|
),
|
||||||
|
],
|
||||||
$presentation = PresentationBuilder::create('')
|
isPublished: FALSE,
|
||||||
->setEvents($events)
|
);
|
||||||
->setPublished(FALSE)
|
|
||||||
->build();
|
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
actual: $counter->getPastCount(),
|
actual: $counter->getPastCount(),
|
||||||
|
@ -73,22 +68,19 @@ final class PresentationCounterTest extends ExistingSiteBase {
|
||||||
expected: 0,
|
expected: 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
$events = [
|
$this->createPresentation(
|
||||||
$this->createEvent(
|
events: [
|
||||||
eventDate: Date::fromString('tomorrow'),
|
$this->createEvent(
|
||||||
eventName: $this->randomString(),
|
eventDate: Date::fromString('tomorrow'),
|
||||||
),
|
eventName: $this->randomString(),
|
||||||
|
),
|
||||||
|
|
||||||
$this->createEvent(
|
$this->createEvent(
|
||||||
eventDate: Date::fromString('yesterday'),
|
eventDate: Date::fromString('yesterday'),
|
||||||
eventName: $this->randomString(),
|
eventName: $this->randomString(),
|
||||||
),
|
),
|
||||||
];
|
],
|
||||||
|
);
|
||||||
$presentation = PresentationBuilder::create($this->randomString())
|
|
||||||
->setEvents($events)
|
|
||||||
->build();
|
|
||||||
$presentation->save();
|
|
||||||
|
|
||||||
$counter = $this->container->get(PresentationCounter::class);
|
$counter = $this->container->get(PresentationCounter::class);
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,32 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Drupal\Tests\opd_presentations\Traits;
|
namespace Drupal\Tests\opd_presentations\Traits;
|
||||||
|
|
||||||
|
use Drupal\Core\Datetime\DrupalDateTime;
|
||||||
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||||
use Drupal\ctools\Testing\EntityCreationTrait;
|
use Drupal\ctools\Testing\EntityCreationTrait;
|
||||||
use Drupal\opd_presentations\Date;
|
use Drupal\opd_presentations\Date;
|
||||||
use Drupal\opd_presentations\Event;
|
use Drupal\opd_presentations\Event;
|
||||||
|
use Drupal\opd_presentations\Presentation;
|
||||||
|
|
||||||
trait PresentationCreationTrait {
|
trait PresentationCreationTrait {
|
||||||
|
|
||||||
use EntityCreationTrait;
|
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 {
|
private function createEvent(string $eventName, Date $eventDate): Event {
|
||||||
$event = $this->createEntity(
|
$event = $this->createEntity(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue