/**
  * @cover replacePlaceHolders
  */
 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());
 }
示例#2
0
 /**
  * @cover fetchDataByPropertyPath
  */
 public function testBubbleableMetadata()
 {
     $this->node->field_integer->setValue([]);
     // Save the node, so that it gets an ID and it has a cache tag.
     $this->node->save();
     // Also add a user for testing cache tags of references.
     $user = $this->entityTypeManager->getStorage('user')->create(['name' => 'test', 'type' => 'user']);
     $user->save();
     $this->node->uid->entity = $user;
     $bubbleable_metadata = new BubbleableMetadata();
     $this->dataFetcher->fetchDataByPropertyPath($this->node->getTypedData(), 'title.value', $bubbleable_metadata)->getValue();
     $expected = ['node:' . $this->node->id()];
     $this->assertEquals($expected, $bubbleable_metadata->getCacheTags());
     // Test cache tags of references are added correctly.
     $this->dataFetcher->fetchDataByPropertyPath($this->node->getTypedData(), 'uid.entity.name', $bubbleable_metadata)->getValue();
     $expected = ['node:' . $this->node->id(), 'user:' . $user->id()];
     $this->assertEquals($expected, $bubbleable_metadata->getCacheTags());
 }