function SqlTest::testGetCacheTags
@covers ::getCacheTags
@covers ::getAllEntities
File
-
core/
modules/ views/ tests/ src/ Unit/ Plugin/ query/ SqlTest.php, line 31
Class
- SqlTest
- @coversDefaultClass \Drupal\views\Plugin\views\query\Sql[[api-linebreak]]
Namespace
Drupal\Tests\views\Unit\Plugin\queryCode
public function testGetCacheTags() {
$view = $this->prophesize('Drupal\\views\\ViewExecutable')
->reveal();
$entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
$date_sql = $this->prophesize(DateSqlInterface::class);
$messenger = $this->prophesize(MessengerInterface::class);
$query = new Sql([], 'sql', [], $entity_type_manager->reveal(), $date_sql->reveal(), $messenger->reveal());
$query->view = $view;
$result = [];
$view->result = $result;
// Add a row with an entity.
$row = new ResultRow();
$prophecy = $this->prophesize('Drupal\\Core\\Entity\\EntityInterface');
$prophecy->getCacheTags()
->willReturn([
'entity_test:123',
]);
$entity = $prophecy->reveal();
$row->_entity = $entity;
$result[] = $row;
$view->result = $result;
// Add a row with an entity and a relationship entity.
$row = new ResultRow();
$prophecy = $this->prophesize('Drupal\\Core\\Entity\\EntityInterface');
$prophecy->getCacheTags()
->willReturn([
'entity_test:124',
]);
$entity = $prophecy->reveal();
$row->_entity = $entity;
$prophecy = $this->prophesize('Drupal\\Core\\Entity\\EntityInterface');
$prophecy->getCacheTags()
->willReturn([
'entity_test:125',
]);
$entity = $prophecy->reveal();
$row->_relationship_entities[] = $entity;
$prophecy = $this->prophesize('Drupal\\Core\\Entity\\EntityInterface');
$prophecy->getCacheTags()
->willReturn([
'entity_test:126',
]);
$entity = $prophecy->reveal();
$row->_relationship_entities[] = $entity;
$result[] = $row;
$view->result = $result;
$this->assertEqualsCanonicalizing([
'entity_test:123',
'entity_test:124',
'entity_test:125',
'entity_test:126',
], $query->getCacheTags());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.