73 lines
2 KiB
PHP
73 lines
2 KiB
PHP
<?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,
|
|
);
|
|
}
|
|
|
|
}
|