Add initial PresentationCounter logic

This commit is contained in:
Oliver Davies 2025-06-09 00:51:41 +01:00
parent bf8017c477
commit 1fe63e7326
4 changed files with 69 additions and 0 deletions

View file

@ -0,0 +1,5 @@
name: Presentations
description: Custom functionality for presentations.
core_version_requirement: ^11
type: module
package: Custom

View file

@ -0,0 +1,2 @@
services:
Drupal\opd_presentations\PresentationCounter: {}

View file

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace Drupal\opd_presentations;
final class PresentationCounter {
public function getCount(): int {
return 1;
}
}

View file

@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace Drupal\opd_presentations\Kernel;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\node\NodeInterface;
use Drupal\opd_presentations\PresentationCounter;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\paragraphs\ParagraphInterface;
class PresentationCounterTest extends EntityKernelTestBase {
use NodeCreationTrait;
protected static $modules = [
'node',
'opd_presentations',
'paragraphs',
];
public function test_count_presentation(): void {
$this->createPresentation(
events: [
Paragraph::create(['type' => 'event']),
],
);
$counter = $this->container->get(PresentationCounter::class);
$this->assertSame(
actual: $counter->getCount(),
expected: 1,
);
}
/**
* @param ParagraphInterface[] $events
*/
private function createPresentation(array $events): NodeInterface {
return $this->createNode([
'field_events' => $events,
'type' => 'presentation',
]);
}
}