You are here

public function SqlTest::testGetCacheTags in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest::testGetCacheTags()

@covers ::getCacheTags @covers ::getAllEntities

File

core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php, line 25
Contains \Drupal\Tests\views\Unit\Plugin\query\SqlTest.

Class

SqlTest
@coversDefaultClass \Drupal\views\Plugin\views\query\Sql

Namespace

Drupal\Tests\views\Unit\Plugin\query

Code

public function testGetCacheTags() {
  $view = $this
    ->prophesize('Drupal\\views\\ViewExecutable')
    ->reveal();
  $query = new Sql([], 'sql', []);
  $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
    ->assertEquals([
    'entity_test:123',
    'entity_test:124',
    'entity_test:125',
    'entity_test:126',
  ], $query
    ->getCacheTags());
}