Add published nodes test

This commit is contained in:
Oliver Davies 2024-01-17 10:38:59 +00:00
parent 71e70a56c5
commit 8c3b9438c7

View file

@ -2,6 +2,7 @@
namespace Drupal\Tests\example\Functional; namespace Drupal\Tests\example\Functional;
use Drupal\example\Builder\PostBuilder;
use Drupal\Tests\BrowserTestBase; use Drupal\Tests\BrowserTestBase;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@ -33,4 +34,28 @@ class BlogPageTest extends BrowserTestBase {
$assert->pageTextContains('Third post'); $assert->pageTextContains('Third post');
} }
public function testOnlyPublishedNodesAreShown(): void {
PostBuilder::create()
->setTitle('Post one')
->isPublished()
->getPost();
PostBuilder::create()
->setTitle('Post two')
->isNotPublished()
->getPost();
PostBuilder::create()
->setTitle('Post three')
->isPublished()
->getPost();
$this->drupalGet('/blog');
$assert = $this->assertSession();
$assert->pageTextContains('Post one');
$assert->pageTextNotContains('Post two');
$assert->pageTextContains('Post three');
}
} }