From a540f4ad3257db01660109dbdc632f19a0f8df55 Mon Sep 17 00:00:00 2001 From: Oliver Davies <oliver@oliverdavies.uk> Date: Sat, 14 Nov 2020 09:38:57 +0000 Subject: [PATCH] 4j: Only published articles are returned --- .../tests/src/Kernel/ArticleRepositoryTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/web/modules/custom/my_module/tests/src/Kernel/ArticleRepositoryTest.php b/web/modules/custom/my_module/tests/src/Kernel/ArticleRepositoryTest.php index 3a5408d..2d3468b 100644 --- a/web/modules/custom/my_module/tests/src/Kernel/ArticleRepositoryTest.php +++ b/web/modules/custom/my_module/tests/src/Kernel/ArticleRepositoryTest.php @@ -41,6 +41,20 @@ class ArticleRepositoryTest extends EntityKernelTestBase { $this->assertCount(3, $articles); } + /** @test */ + public function only_published_articles_are_returned() { + $this->createNode(['type' => 'article', 'status' => NodeInterface::PUBLISHED])->save(); + $this->createNode(['type' => 'article', 'status' => NodeInterface::NOT_PUBLISHED])->save(); + $this->createNode(['type' => 'article', 'status' => NodeInterface::PUBLISHED])->save(); + $this->createNode(['type' => 'article', 'status' => NodeInterface::NOT_PUBLISHED])->save(); + $this->createNode(['type' => 'article', 'status' => NodeInterface::PUBLISHED])->save(); + + $repository = $this->container->get(ArticleRepository::class); + $articles = $repository->getAll(); + + $this->assertCount(3, $articles); + } + protected function setUp() { parent::setUp();