76 lines
1.8 KiB
PHP
76 lines
1.8 KiB
PHP
<?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'],
|
|
yield 'Two guests' => [['Emma Horrell', 'Luke McCormick'], 'Emma Horrell and Luke McCormick'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @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',
|
|
]);
|
|
}
|
|
}
|