From ffe6fe9b68f0663e05d3ca1e863435c1165238e6 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 28 Aug 2020 10:15:14 +0100 Subject: [PATCH] Add tests for the TalkRepository Fixes #203 --- .../tests/src/Kernel/TalkRepositoryTest.php | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 web/modules/custom/opdavies_talks/tests/src/Kernel/TalkRepositoryTest.php diff --git a/web/modules/custom/opdavies_talks/tests/src/Kernel/TalkRepositoryTest.php b/web/modules/custom/opdavies_talks/tests/src/Kernel/TalkRepositoryTest.php new file mode 100644 index 0000000..13c5647 --- /dev/null +++ b/web/modules/custom/opdavies_talks/tests/src/Kernel/TalkRepositoryTest.php @@ -0,0 +1,70 @@ +createTalk(['title' => 'TDD - Test Driven Drupal']); + $this->createTalk(['title' => 'Taking Flight with Tailwind CSS']); + $this->createTalk(['title' => 'Upgrading to Drupal 9']); + + $talks = $this->talkRepository->getAll(); + + $this->assertCount(3, $talks); + $this->assertSame( + [ + 1 => 'TDD - Test Driven Drupal', + 2 => 'Taking Flight with Tailwind CSS', + 3 => 'Upgrading to Drupal 9', + ], + $talks->map(fn(Talk $talk) => $talk->label())->toArray() + ); + } + + /** @test */ + public function get_all_published_talks() { + $this->createTalk([ + 'title' => 'TDD - Test Driven Drupal', + 'status' => NodeInterface::PUBLISHED, + ]); + + $this->createTalk([ + 'title' => 'Taking Flight with Tailwind CSS', + 'status' => NodeInterface::NOT_PUBLISHED, + ]); + + $talks = $this->talkRepository->getAll(TRUE); + + $this->assertCount(1, $talks); + $this->assertSame('TDD - Test Driven Drupal', $talks->first()->label()); + } + + /** @test */ + public function it_only_returns_talk_nodes() { + $this->createNode(['type' => 'page']); + + $talks = $this->talkRepository->getAll(); + + $this->assertEmpty($talks); + } + + protected function setUp() { + parent::setUp(); + + $this->installConfig(['filter']); + + $this->talkRepository = $this->container->get(TalkRepository::class); + } + +}