Move all files to test-driven-drupal/demo/drupal-london/

This commit is contained in:
Oliver Davies 2025-10-02 12:31:37 +01:00
parent 0db961b741
commit 695d8b0299
44 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,3 @@
name: Talks
type: module
core_version_requirement: ^10

View file

@ -0,0 +1,6 @@
opdavies_talks.page:
path: /talks
defaults:
_controller: Drupal\opdavies_talks\Controller\TalksPageController
requirements:
_permission: access content

View file

@ -0,0 +1,5 @@
services:
Drupal\opdavies_talks\Controller\TalksPageController:
autowire: true
Drupal\opdavies_talks\Repository\TalkNodeRepository:
autowire: true

View file

@ -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])];
}
}

View file

@ -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);
}
}

View file

@ -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>');
}
}

View file

@ -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());
}
}