Remove the hard-coded talk count
This commit is contained in:
parent
cdd7a466d2
commit
0db961b741
|
@ -1,4 +1,5 @@
|
|||
services:
|
||||
Drupal\opdavies_talks\Controller\TalksPageController:
|
||||
autowire: true
|
||||
Drupal\opdavies_talks\Repository\TalkNodeRepository: []
|
||||
Drupal\opdavies_talks\Repository\TalkNodeRepository:
|
||||
autowire: true
|
||||
|
|
|
@ -4,10 +4,17 @@ 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 {
|
||||
return 2;
|
||||
$talks = $this->entityTypeManager->getStorage('node')->loadByProperties();
|
||||
|
||||
return count($talks);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@ class TalksPageTest extends BrowserTestBase {
|
|||
}
|
||||
|
||||
public function test_it_displays_the_talk_count(): void {
|
||||
$this->createNode(['type' => 'talk']);
|
||||
$this->createNode(['type' => 'talk']);
|
||||
|
||||
$this->drupalGet('/talks');
|
||||
|
||||
$session = $this->assertSession();
|
||||
|
|
|
@ -3,13 +3,19 @@
|
|||
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 = ['opdavies_talks'];
|
||||
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…
Reference in a new issue