feat(blog): add the initial blog page
This commit is contained in:
parent
c78f3d0435
commit
09d4c662be
3
web/modules/custom/my_module/my_module.info.yml
Normal file
3
web/modules/custom/my_module/my_module.info.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
name: My Module
|
||||||
|
type: module
|
||||||
|
core_version_requirement: ^10
|
7
web/modules/custom/my_module/my_module.routing.yml
Normal file
7
web/modules/custom/my_module/my_module.routing.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
blog.page:
|
||||||
|
path: /blog
|
||||||
|
defaults:
|
||||||
|
_controller: Drupal\my_module\Controller\BlogPageController
|
||||||
|
_title: Blog
|
||||||
|
requirements:
|
||||||
|
_permission: access content
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Drupal\my_module\Controller;
|
||||||
|
|
||||||
|
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||||
|
|
||||||
|
final class BlogPageController {
|
||||||
|
|
||||||
|
use StringTranslationTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function __invoke(): array {
|
||||||
|
return [
|
||||||
|
'#markup' => $this->t('Welcome to my blog!'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Drupal\Tests\my_module\Functional;
|
||||||
|
|
||||||
|
use Drupal\Tests\BrowserTestBase;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
final class BlogPageTest extends BrowserTestBase {
|
||||||
|
|
||||||
|
public $defaultTheme = 'stark';
|
||||||
|
|
||||||
|
protected static $modules = [
|
||||||
|
// Core.
|
||||||
|
'node',
|
||||||
|
|
||||||
|
// Custom.
|
||||||
|
'my_module',
|
||||||
|
];
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function the_blog_page_loads_for_anonymous_users_and_contains_the_right_text(): void {
|
||||||
|
$this->drupalGet('/blog');
|
||||||
|
|
||||||
|
$assert = $this->assertSession();
|
||||||
|
|
||||||
|
$assert->statusCodeEquals(Response::HTTP_OK);
|
||||||
|
$assert->responseContains('<h1>Blog</h1>');
|
||||||
|
$assert->pageTextContains('Welcome to my blog!');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in a new issue