Refactor
This commit is contained in:
parent
08a0f18995
commit
460f6cfbe0
3 changed files with 5 additions and 4 deletions
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\opd_presentations\Action;
|
||||
|
||||
use Drupal\Tests\RandomGeneratorTrait;
|
||||
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;
|
||||
use RandomGeneratorTrait;
|
||||
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue