Move all files to test-driven-drupal/demo/drupal-london/
This commit is contained in:
parent
0db961b741
commit
695d8b0299
44 changed files with 0 additions and 0 deletions
2
test-driven-drupal/demo/drupal-london/web/modules/custom/example/.gitignore
vendored
Normal file
2
test-driven-drupal/demo/drupal-london/web/modules/custom/example/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/composer.lock
|
||||
/vendor/
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"require": {
|
||||
"symfony/config": "^6.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
name: Example module
|
||||
description: TODO
|
||||
type: module
|
||||
core_version_requirement: ^9 || ^10 || ^11
|
||||
package: Example
|
|
@ -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
|
|
@ -0,0 +1,7 @@
|
|||
services:
|
||||
Drupal\Core\Logger\LoggerChannelFactoryInterface:
|
||||
alias: logger.factory
|
||||
private: true
|
||||
|
||||
Drupal\example\Controller\ExamplePageController:
|
||||
autowire: true
|
|
@ -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,32 @@
|
|||
<?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,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
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,0 +1,3 @@
|
|||
name: Talks
|
||||
type: module
|
||||
core_version_requirement: ^10
|
|
@ -0,0 +1,6 @@
|
|||
opdavies_talks.page:
|
||||
path: /talks
|
||||
defaults:
|
||||
_controller: Drupal\opdavies_talks\Controller\TalksPageController
|
||||
requirements:
|
||||
_permission: access content
|
|
@ -0,0 +1,5 @@
|
|||
services:
|
||||
Drupal\opdavies_talks\Controller\TalksPageController:
|
||||
autowire: true
|
||||
Drupal\opdavies_talks\Repository\TalkNodeRepository:
|
||||
autowire: true
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opdavies_talks\Controller;
|
||||
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\opdavies_talks\Repository\TalkNodeRepository;
|
||||
|
||||
final class TalksPageController {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
public function __construct(private TalkNodeRepository $talkRepository) {
|
||||
}
|
||||
|
||||
public function __invoke(): array {
|
||||
$talkCount = $this->talkRepository->getCount();
|
||||
|
||||
return ['#markup' => $this->t('<span data-talk-count>:count talks</span>', [':count' => $talkCount])];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opdavies_talks\Repository;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
|
||||
final class TalkNodeRepository {
|
||||
|
||||
public function __construct(private EntityTypeManagerInterface $entityTypeManager) {
|
||||
}
|
||||
|
||||
public function getCount(): int {
|
||||
$talks = $this->entityTypeManager->getStorage('node')->loadByProperties();
|
||||
|
||||
return count($talks);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\opdavies_talks\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class TalksPageTest extends BrowserTestBase {
|
||||
|
||||
public $defaultTheme = 'stark';
|
||||
|
||||
public static $modules = ['node', 'opdavies_talks'];
|
||||
|
||||
public function test_it_returns_a_200_response_code(): void {
|
||||
$this->drupalGet('/talks');
|
||||
|
||||
$session = $this->assertSession();
|
||||
$session->statusCodeEquals(Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function test_it_displays_the_talk_count(): void {
|
||||
$this->createNode(['type' => 'talk']);
|
||||
$this->createNode(['type' => 'talk']);
|
||||
|
||||
$this->drupalGet('/talks');
|
||||
|
||||
$session = $this->assertSession();
|
||||
$session->responseContains('<span data-talk-count>2 talks</span>');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\opdavies_talks\Kernel\Repository;
|
||||
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||
use Drupal\opdavies_talks\Repository\TalkNodeRepository;
|
||||
|
||||
final class TalkNodeRepositoryTest extends EntityKernelTestBase {
|
||||
|
||||
protected static $modules = ['node', 'opdavies_talks'];
|
||||
|
||||
use NodeCreationTrait;
|
||||
|
||||
public function test_it_returns_a_count(): void {
|
||||
$this->createNode(['type' => 'talk']);
|
||||
$this->createNode(['type' => 'talk']);
|
||||
|
||||
$talkRepository = $this->container->get(TalkNodeRepository::class);
|
||||
|
||||
self::assertSame(2, $talkRepository->getCount());
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue