Move all files to tome/
This commit is contained in:
parent
5675bcfc36
commit
674daab35b
2874 changed files with 0 additions and 0 deletions
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\opd_presentations\Action;
|
||||
|
||||
use Drupal\Tests\opd_presentations\Traits\PresentationCreationTrait;
|
||||
use Drupal\opd_presentations\Action\CountGivenPresentations;
|
||||
use Drupal\opd_presentations\Events;
|
||||
use weitzman\DrupalTestTraits\ExistingSiteBase;
|
||||
|
||||
final class CountGivenPresentationsTest extends ExistingSiteBase {
|
||||
|
||||
use PresentationCreationTrait;
|
||||
|
||||
public function test_it_counts_events(): void {
|
||||
$action = $this->container->get(CountGivenPresentations::class);
|
||||
assert($action instanceof CountGivenPresentations);
|
||||
|
||||
$this->createPresentation(
|
||||
Events::fromDateStrings('yesterday'),
|
||||
);
|
||||
|
||||
$this->assertGreaterThanOrEqual(
|
||||
actual: $action(),
|
||||
expected: 1,
|
||||
);
|
||||
}
|
||||
|
||||
public function test_it_only_counts_published_events(): void {
|
||||
$action = $this->container->get(CountGivenPresentations::class);
|
||||
assert($action instanceof CountGivenPresentations);
|
||||
|
||||
// Get the existing presentation count (including existing nodes).
|
||||
$originalCount = $action();
|
||||
|
||||
$this->createPresentation(
|
||||
events: Events::fromDateStrings('yesterday'),
|
||||
isPublished: FALSE,
|
||||
);
|
||||
|
||||
// Ensure the count has only increased by one, even though an unpublished
|
||||
// presentation was created.
|
||||
$this->assertSame(
|
||||
actual: $action(),
|
||||
expected: $originalCount,
|
||||
);
|
||||
}
|
||||
|
||||
public function test_it_only_counts_past_events(): void {
|
||||
$action = $this->container->get(CountGivenPresentations::class);
|
||||
assert($action instanceof CountGivenPresentations);
|
||||
|
||||
// Get the existing presentation count (including existing nodes).
|
||||
$originalCount = $action();
|
||||
|
||||
$this->assertGreaterThanOrEqual(
|
||||
actual: $originalCount,
|
||||
expected: 0,
|
||||
);
|
||||
|
||||
$this->createPresentation(
|
||||
Events::fromDateStrings('tomorrow', 'yesterday'),
|
||||
);
|
||||
|
||||
// Ensure the count has only increased by one, even though a future and past event were created.
|
||||
$this->assertSame(
|
||||
actual: $action(),
|
||||
expected: $originalCount + 1,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_presentations\Functional;
|
||||
|
||||
use Drupal\Tests\opd_presentations\Traits\PresentationCreationTrait;
|
||||
use Drupal\opd_presentations\Events;
|
||||
use weitzman\DrupalTestTraits\ExistingSiteBase;
|
||||
|
||||
final class PresentationTest extends ExistingSiteBase {
|
||||
|
||||
use PresentationCreationTrait;
|
||||
|
||||
public function test_only_past_events_are_returned(): void {
|
||||
$presentation = $this->createPresentation(
|
||||
events: Events::fromDateStrings('now', 'yesterday', 'tomorrow'),
|
||||
);
|
||||
|
||||
$events = $presentation->getEvents()->getPast();
|
||||
|
||||
$this->assertCount(
|
||||
expectedCount: 1,
|
||||
haystack: $events,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\opd_presentations\Traits;
|
||||
|
||||
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\Events;
|
||||
use Drupal\opd_presentations\Presentation;
|
||||
|
||||
trait PresentationCreationTrait {
|
||||
|
||||
use EntityCreationTrait;
|
||||
use NodeCreationTrait;
|
||||
|
||||
private function createPresentation(Events $events, bool $isPublished = TRUE): Presentation {
|
||||
$presentation = $this->createNode([
|
||||
'field_events' => $events->toEvents(),
|
||||
'status' => $isPublished,
|
||||
'type' => Presentation::NODE_TYPE,
|
||||
]);
|
||||
|
||||
assert($presentation instanceof Presentation);
|
||||
|
||||
return $presentation;
|
||||
}
|
||||
|
||||
private function createEvent(string $eventName, Date $eventDate): Event {
|
||||
$event = $this->createEntity(
|
||||
entity_type: 'paragraph',
|
||||
values: [
|
||||
'field_date' => $eventDate->toTimestamp(),
|
||||
'field_event_name' => $eventName,
|
||||
'type' => Event::PARAGRAPH_TYPE,
|
||||
],
|
||||
);
|
||||
|
||||
assert($event instanceof Event);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue