feat: add an example module with custom tests
Add a custom module based on my Drupal module template: https://github.com/opdavies/drupal-module-template
This commit is contained in:
parent
ea60b27438
commit
67a9f556c4
2
web/modules/custom/example/.gitignore
vendored
Normal file
2
web/modules/custom/example/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/composer.lock
|
||||||
|
/vendor/
|
5
web/modules/custom/example/composer.json
Normal file
5
web/modules/custom/example/composer.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"symfony/config": "^6.1"
|
||||||
|
}
|
||||||
|
}
|
5
web/modules/custom/example/example.info.yml
Normal file
5
web/modules/custom/example/example.info.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
name: Example module
|
||||||
|
description: TODO
|
||||||
|
type: module
|
||||||
|
core_version_requirement: ^9||^10
|
||||||
|
package: Example
|
7
web/modules/custom/example/example.routing.yml
Normal file
7
web/modules/custom/example/example.routing.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
drupal-module-template.example:
|
||||||
|
path: /@opdavies/drupal-module-template
|
||||||
|
defaults:
|
||||||
|
_controller: Drupal\example\Controller\ExamplePageController
|
||||||
|
_title: Example page
|
||||||
|
requirements:
|
||||||
|
_permission: access content
|
7
web/modules/custom/example/example.services.yml
Normal file
7
web/modules/custom/example/example.services.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
services:
|
||||||
|
Drupal\Core\Logger\LoggerChannelFactoryInterface:
|
||||||
|
alias: logger.factory
|
||||||
|
private: true
|
||||||
|
|
||||||
|
Drupal\example\Controller\ExamplePageController:
|
||||||
|
autowire: true
|
31
web/modules/custom/example/phpcs.xml.dist
Normal file
31
web/modules/custom/example/phpcs.xml.dist
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ruleset name="phpcs-standard">
|
||||||
|
<description>Codestyle ruleset for Drupal</description>
|
||||||
|
|
||||||
|
<rule ref="Drupal"/>
|
||||||
|
<rule ref="DrupalPractice"/>
|
||||||
|
|
||||||
|
<arg name="ignore" value="*.css,*.md,*.txt"/>
|
||||||
|
|
||||||
|
<arg name="colors"/>
|
||||||
|
<arg value="np"/>
|
||||||
|
|
||||||
|
<file>./src</file>
|
||||||
|
|
||||||
|
<rule ref="Drupal">
|
||||||
|
<exclude name="Drupal.Commenting.ClassComment.Missing"/>
|
||||||
|
<exclude name="Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps"/>
|
||||||
|
<exclude name="Drupal.Commenting.DataTypeNamespace.DataTypeNamespace"/>
|
||||||
|
<exclude name="Drupal.Commenting.DocComment.MissingShort"/>
|
||||||
|
<exclude name="Drupal.Commenting.FunctionComment.IncorrectParamVarName"/>
|
||||||
|
<exclude name="Drupal.Commenting.FunctionComment.IncorrectTypeHint"/>
|
||||||
|
<exclude name="Drupal.Commenting.FunctionComment.InvalidReturn"/>
|
||||||
|
<exclude name="Drupal.Commenting.FunctionComment.Missing"/>
|
||||||
|
<exclude name="Drupal.Commenting.FunctionComment.MissingParamComment"/>
|
||||||
|
<exclude name="Drupal.Commenting.FunctionComment.MissingReturnComment"/>
|
||||||
|
<exclude name="Drupal.Commenting.FunctionComment.ParamTypeSpaces"/>
|
||||||
|
<exclude name="Drupal.Commenting.InlineComment.DocBlock"/>
|
||||||
|
<exclude name="Drupal.Commenting.VariableComment.Missing"/>
|
||||||
|
<exclude name="DrupalPractice.Objects.StrictSchemaDisabled.StrictConfigSchema"/>
|
||||||
|
</rule>
|
||||||
|
</ruleset>
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Drupal\example\Controller;
|
||||||
|
|
||||||
|
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
|
||||||
|
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||||
|
|
||||||
|
final class ExamplePageController {
|
||||||
|
|
||||||
|
use StringTranslationTrait;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private LoggerChannelFactoryInterface $logger
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function __invoke(): array {
|
||||||
|
$this->logger->get('example')->info('Example page viewed.');
|
||||||
|
|
||||||
|
return [
|
||||||
|
'#markup' => $this->t(
|
||||||
|
'This is an example page from the <a href="@url">Drupal Module Template</a>.',
|
||||||
|
['@url' => 'https://github.com/opdavies/drupal-module-template']
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\Tests\example\Functional;
|
||||||
|
|
||||||
|
use Drupal\Tests\BrowserTestBase;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
final class ExamplePageTest extends BrowserTestBase {
|
||||||
|
|
||||||
|
public $defaultTheme = 'stark';
|
||||||
|
|
||||||
|
protected static $modules = [
|
||||||
|
// Core.
|
||||||
|
'node',
|
||||||
|
|
||||||
|
// Custom.
|
||||||
|
"example"
|
||||||
|
];
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function should_load_the_example_page_for_anonymous_users(): void {
|
||||||
|
// Arrange.
|
||||||
|
|
||||||
|
// Act.
|
||||||
|
$this->drupalGet('/@opdavies/drupal-module-template');
|
||||||
|
|
||||||
|
// Assert.
|
||||||
|
$this->assertSession()->statusCodeEquals(Response::HTTP_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
0
web/modules/custom/example/tests/src/Kernel/.keep
Normal file
0
web/modules/custom/example/tests/src/Kernel/.keep
Normal file
0
web/modules/custom/example/tests/src/Unit/.keep
Normal file
0
web/modules/custom/example/tests/src/Unit/.keep
Normal file
Loading…
Reference in a new issue