Add PodcastNodeRepositoryTest
This commit is contained in:
parent
dafc7430b9
commit
76197f02cc
2 changed files with 69 additions and 0 deletions
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\Tests\opd_podcast\Functional;
|
||||||
|
|
||||||
|
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||||
|
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||||
|
use Drupal\node\NodeInterface;
|
||||||
|
use Drupal\opd_podcast\Episode;
|
||||||
|
use Drupal\opd_podcast\Repository\PodcastNodeRepository;
|
||||||
|
|
||||||
|
class PodcastNodeRepositoryTest extends EntityKernelTestBase {
|
||||||
|
|
||||||
|
use NodeCreationTrait;
|
||||||
|
|
||||||
|
protected static $modules = [
|
||||||
|
'node',
|
||||||
|
'opd_podcast',
|
||||||
|
'taxonomy',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function test_it_returns_published_podcast_episodes(): void {
|
||||||
|
$this->createEpisode([
|
||||||
|
'title' => 'Episode A',
|
||||||
|
'status' => NodeInterface::PUBLISHED,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->createEpisode([
|
||||||
|
'title' => 'Episode B',
|
||||||
|
'status' => NodeInterface::NOT_PUBLISHED,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->createEpisode([
|
||||||
|
'title' => 'Episode C',
|
||||||
|
'status' => NodeInterface::PUBLISHED,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->createEpisode([
|
||||||
|
'title' => 'Episode D',
|
||||||
|
'status' => NodeInterface::PUBLISHED,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$repository = $this->container->get(PodcastNodeRepository::class);
|
||||||
|
|
||||||
|
$episodes = $repository->getPublished();
|
||||||
|
|
||||||
|
$this->assertCount(expectedCount: 3, haystack: $episodes);
|
||||||
|
|
||||||
|
$titles = array_map(
|
||||||
|
array: $episodes,
|
||||||
|
callback: fn (NodeInterface $episode): string => (string) $episode->getTitle(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
actual: array_values($titles),
|
||||||
|
expected: ['Episode A', 'Episode C', 'Episode D'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<non-empty-string, mixed> $values
|
||||||
|
*/
|
||||||
|
private function createEpisode(array $values): NodeInterface {
|
||||||
|
return $this->createNode([
|
||||||
|
'type' => Episode::NODE_TYPE,
|
||||||
|
...$values,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue