You are here

public function PlaceholderResolverTest::testBubbleableMetadata in Typed Data API enhancements 8

@covers ::replacePlaceHolders

File

tests/src/Kernel/PlaceholderResolverTest.php, line 389

Class

PlaceholderResolverTest
Tests the placeholder resolver.

Namespace

Drupal\Tests\typed_data\Kernel

Code

public function testBubbleableMetadata() {

  // Make sure the bubbleable metadata added by the fetcher is properly passed
  // though.
  $bubbleable_metadata = new BubbleableMetadata();

  // Save the node, so it gets a cache tag.
  $this->node
    ->save();
  $this->placeholderResolver
    ->replacePlaceHolders('test {{node.field_integer}}', [
    'node' => $this->node
      ->getTypedData(),
  ], $bubbleable_metadata);
  $expected = [
    'node:' . $this->node
      ->id(),
  ];
  $this
    ->assertEquals($expected, $bubbleable_metadata
    ->getCacheTags());

  // Ensure cache tags of filters are added in.
  $bubbleable_metadata = new BubbleableMetadata();
  $this->placeholderResolver
    ->replacePlaceHolders("test {{ node.created.value | format_date('medium') }}", [
    'node' => $this->node
      ->getTypedData(),
  ], $bubbleable_metadata);
  $expected = Cache::mergeTags([
    'node:' . $this->node
      ->id(),
  ], DateFormat::load('medium')
    ->getCacheTags());
  $this
    ->assertEquals($expected, $bubbleable_metadata
    ->getCacheTags());
}