Refactor
This commit is contained in:
parent
b8c3f6d9a7
commit
8c354f2754
3 changed files with 20 additions and 21 deletions
|
|
@ -1,76 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\opd_presentations;
|
||||
|
||||
use Drupal\Tests\RandomGeneratorTrait;
|
||||
use Drupal\Tests\opd_presentations\Traits\PresentationCreationTrait;
|
||||
use Drupal\opd_presentations\Date;
|
||||
use Drupal\opd_presentations\Events;
|
||||
use Drupal\opd_presentations\PresentationCounter;
|
||||
use Drupal\opd_presentations\Repository\PresentationRepositoryInterface;
|
||||
use weitzman\DrupalTestTraits\ExistingSiteBase;
|
||||
|
||||
final class PresentationCounterTest extends ExistingSiteBase {
|
||||
|
||||
use PresentationCreationTrait;
|
||||
use RandomGeneratorTrait;
|
||||
|
||||
public function test_it_counts_events(): void {
|
||||
$counter = $this->container->get(PresentationCounter::class);
|
||||
assert($counter instanceof PresentationCounter);
|
||||
|
||||
$this->createPresentation(
|
||||
Events::fromDateStrings('yesterday'),
|
||||
);
|
||||
|
||||
$this->assertGreaterThanOrEqual(
|
||||
actual: $counter->getPastCount(),
|
||||
expected: 1,
|
||||
);
|
||||
}
|
||||
|
||||
public function test_it_only_counts_published_events(): void {
|
||||
$counter = $this->container->get(PresentationCounter::class);
|
||||
assert($counter instanceof PresentationCounter);
|
||||
|
||||
$count = $counter->getPastCount();
|
||||
|
||||
$this->createPresentation(
|
||||
events: Events::fromDateStrings('yesterday'),
|
||||
isPublished: FALSE,
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
actual: $counter->getPastCount(),
|
||||
expected: $count,
|
||||
);
|
||||
}
|
||||
|
||||
public function test_it_only_counts_past_events(): void {
|
||||
$counter = $this->container->get(PresentationCounter::class);
|
||||
assert($counter instanceof PresentationCounter);
|
||||
|
||||
// Get the existing presentation count (including existing nodes).
|
||||
$originalCount = $counter->getPastCount();
|
||||
|
||||
$this->assertGreaterThanOrEqual(
|
||||
actual: $originalCount,
|
||||
expected: 0,
|
||||
);
|
||||
|
||||
$this->createPresentation(
|
||||
Events::fromDateStrings('tomorrow', 'yesterday'),
|
||||
);
|
||||
|
||||
$counter = $this->container->get(PresentationCounter::class);
|
||||
|
||||
// Ensure the count has only increased by one, even though a future and past event were created.
|
||||
$this->assertSame(
|
||||
actual: $counter->getPastCount(),
|
||||
expected: $originalCount + 1,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue