4i: Ensure published articles are returned
Add a test to ensure that only published articles are returned from the article repository. Currently there is no filter on the published status, so too many nodes are returned.
This commit is contained in:
parent
76a19ff21b
commit
02c732b60b
1 changed files with 15 additions and 0 deletions
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\my_module\Kernel;
|
|||
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
use Drupal\my_module\Repository\ArticleRepository;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||
|
||||
class ArticleRepositoryTest extends EntityKernelTestBase {
|
||||
|
@ -39,5 +40,19 @@ 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue