Add lesson 3

- Add failing blog page test.
- Add custom routing, need to create Controller.
- Add BlogPageController.
- Test posts are visible.
This commit is contained in:
Oliver Davies 2024-01-08 23:38:01 +00:00
parent e931656b68
commit 99204d78df
4 changed files with 65 additions and 0 deletions

View file

@ -0,0 +1,33 @@
<?php
namespace Drupal\Tests\example\Functional;
use Drupal\Tests\BrowserTestBase;
use Symfony\Component\HttpFoundation\Response;
class BlogPageTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = ['node', 'example'];
public function testBlogPage(): void {
$this->drupalGet('/blog');
$this->assertSession()->statusCodeEquals(Response::HTTP_OK);
}
public function testPostsAreVisible(): void {
$this->createNode(['type' => 'post', 'title' => 'First post']);
$this->createNode(['type' => 'post', 'title' => 'Second post']);
$this->createNode(['type' => 'post', 'title' => 'Third post']);
$this->drupalGet('/blog');
$assert = $this->assertSession();
$assert->pageTextContains('First post');
$assert->pageTextContains('Second post');
$assert->pageTextContains('Third post');
}
}