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
|
@ -0,0 +1,28 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.node.field_podcast_guests
|
||||
- node.type.podcast_episode
|
||||
- taxonomy.vocabulary.podcast_guest
|
||||
id: node.podcast_episode.field_podcast_guests
|
||||
field_name: field_podcast_guests
|
||||
entity_type: node
|
||||
bundle: podcast_episode
|
||||
label: Guests
|
||||
description: ''
|
||||
required: false
|
||||
translatable: false
|
||||
default_value: { }
|
||||
default_value_callback: ''
|
||||
settings:
|
||||
handler: 'default:taxonomy_term'
|
||||
handler_settings:
|
||||
target_bundles:
|
||||
podcast_guest: podcast_guest
|
||||
sort:
|
||||
field: name
|
||||
direction: asc
|
||||
auto_create: true
|
||||
auto_create_bundle: ''
|
||||
field_type: entity_reference
|
|
@ -0,0 +1,19 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- node
|
||||
- taxonomy
|
||||
id: node.field_podcast_guests
|
||||
field_name: field_podcast_guests
|
||||
entity_type: node
|
||||
type: entity_reference
|
||||
settings:
|
||||
target_type: taxonomy_term
|
||||
module: core
|
||||
locked: false
|
||||
cardinality: -1
|
||||
translatable: true
|
||||
indexes: { }
|
||||
persist_with_no_fields: false
|
||||
custom_storage: false
|
|
@ -0,0 +1,11 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
third_party_settings: { }
|
||||
name: 'Podcast episode'
|
||||
type: podcast_episode
|
||||
description: null
|
||||
help: null
|
||||
new_revision: true
|
||||
preview_mode: 1
|
||||
display_submitted: true
|
|
@ -0,0 +1,8 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
name: 'Podcast guest'
|
||||
vid: podcast_guest
|
||||
description: null
|
||||
weight: 0
|
||||
new_revision: false
|
|
@ -0,0 +1,8 @@
|
|||
name: Podcast Test
|
||||
description: A test module for podcasts.
|
||||
core_version_requirement: ^11
|
||||
type: module
|
||||
package: oliverdavies.uk
|
||||
hidden: true
|
||||
dependencies:
|
||||
- drupal:node
|
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