oliverdavies.uk/modules/opd_presentations/tests/src/Functional/Action/CountGivenPresentationsTest.php

74 lines
2 KiB
PHP
Raw Normal View History

2025-06-14 22:10:24 +01:00
<?php
declare(strict_types=1);
2025-06-23 21:17:10 +01:00
namespace Drupal\Tests\opd_presentations\Action;
2025-06-14 22:10:24 +01:00
use Drupal\Tests\opd_presentations\Traits\PresentationCreationTrait;
2025-06-23 21:17:10 +01:00
use Drupal\opd_presentations\Action\CountGivenPresentations;
2025-06-15 09:58:14 +01:00
use Drupal\opd_presentations\Events;
2025-06-14 22:10:24 +01:00
use weitzman\DrupalTestTraits\ExistingSiteBase;
2025-06-21 12:52:11 +01:00
final class CountGivenPresentationsTest extends ExistingSiteBase {
2025-06-14 22:10:24 +01:00
use PresentationCreationTrait;
public function test_it_counts_events(): void {
2025-06-21 12:52:11 +01:00
$action = $this->container->get(CountGivenPresentations::class);
assert($action instanceof CountGivenPresentations);
2025-06-14 22:10:24 +01:00
$this->createPresentation(
2025-06-15 09:58:14 +01:00
Events::fromDateStrings('yesterday'),
);
2025-06-14 22:10:24 +01:00
$this->assertGreaterThanOrEqual(
2025-06-21 12:52:11 +01:00
actual: $action(),
2025-06-14 22:10:24 +01:00
expected: 1,
);
}
public function test_it_only_counts_published_events(): void {
2025-06-21 12:52:11 +01:00
$action = $this->container->get(CountGivenPresentations::class);
assert($action instanceof CountGivenPresentations);
2025-06-14 22:10:24 +01:00
2025-06-21 12:52:11 +01:00
// Get the existing presentation count (including existing nodes).
$originalCount = $action();
2025-06-14 22:10:24 +01:00
$this->createPresentation(
2025-06-15 09:58:14 +01:00
events: Events::fromDateStrings('yesterday'),
isPublished: FALSE,
);
2025-06-14 22:10:24 +01:00
2025-06-21 12:52:11 +01:00
// Ensure the count has only increased by one, even though an unpublished
// presentation was created.
2025-06-14 22:10:24 +01:00
$this->assertSame(
2025-06-21 12:52:11 +01:00
actual: $action(),
expected: $originalCount,
2025-06-14 22:10:24 +01:00
);
}
public function test_it_only_counts_past_events(): void {
2025-06-21 12:52:11 +01:00
$action = $this->container->get(CountGivenPresentations::class);
assert($action instanceof CountGivenPresentations);
2025-06-14 22:10:24 +01:00
// Get the existing presentation count (including existing nodes).
2025-06-21 12:52:11 +01:00
$originalCount = $action();
2025-06-14 22:10:24 +01:00
$this->assertGreaterThanOrEqual(
actual: $originalCount,
expected: 0,
);
$this->createPresentation(
2025-06-15 09:58:14 +01:00
Events::fromDateStrings('tomorrow', 'yesterday'),
);
2025-06-14 22:10:24 +01:00
// Ensure the count has only increased by one, even though a future and past event were created.
$this->assertSame(
2025-06-21 12:52:11 +01:00
actual: $action(),
2025-06-14 22:10:24 +01:00
expected: $originalCount + 1,
);
}
}