Return a token with the name of a single guest
This commit is contained in:
parent
52c5eda4a5
commit
487190cb12
7 changed files with 215 additions and 0 deletions
75
modules/opd_podcast/tests/src/Kernel/PodcastTokenTest.php
Normal file
75
modules/opd_podcast/tests/src/Kernel/PodcastTokenTest.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\opd_podcast\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||
use Drupal\Tests\token\Functional\TokenTestTrait;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\taxonomy\TermInterface;
|
||||
|
||||
class PodcastTokenTest extends BrowserTestBase {
|
||||
|
||||
use NodeCreationTrait;
|
||||
use TokenTestTrait;
|
||||
|
||||
public $defaultTheme = 'stark';
|
||||
|
||||
protected static $modules = [
|
||||
'opd_podcast',
|
||||
'opd_podcast_test',
|
||||
'taxonomy',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param non-empty-string[] $guestNames
|
||||
* @param non-empty-string $expected
|
||||
*
|
||||
* @dataProvider podcastNodeProvider
|
||||
*/
|
||||
public function test_guest_name_token(array $guestNames, string $expected): void {
|
||||
$node = $this->createPodcastNode(
|
||||
guestNames: $guestNames,
|
||||
);
|
||||
|
||||
$this->assertToken(
|
||||
data: ['node' => $node],
|
||||
expected: $expected,
|
||||
token: 'guest-names',
|
||||
type: 'opd-podcast',
|
||||
);
|
||||
}
|
||||
|
||||
public function podcastNodeProvider(): \Generator {
|
||||
return [
|
||||
yield 'Single guest' => [['Matt Glaman'], 'Matt Glaman'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, non-empty-string> $guestNames
|
||||
*
|
||||
* @return list<TermInterface>
|
||||
*/
|
||||
private function createGuestTerms(array $guestNames): array {
|
||||
return array_map(
|
||||
array: $guestNames,
|
||||
callback: fn (string $guestName): TermInterface => Term::create([
|
||||
'name' => $guestName,
|
||||
'vid' => 'podcast_guest',
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param non-empty-string[] $guestNames
|
||||
*/
|
||||
private function createPodcastNode(array $guestNames): NodeInterface {
|
||||
return $this->createNode([
|
||||
'field_podcast_guests' => $this->createGuestTerms($guestNames),
|
||||
'title' => '::title::',
|
||||
'type' => 'podcast_episode',
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue