You are here

public function SqlTest::testGetCacheMaxAge 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::testGetCacheMaxAge()

@covers ::getCacheTags @covers ::getAllEntities

File

core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php, line 70
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 testGetCacheMaxAge() {
  $view = $this
    ->prophesize('Drupal\\views\\ViewExecutable')
    ->reveal();
  $query = new Sql([], 'sql', []);
  $query->view = $view;
  $view->result = [];

  // Add a row with an entity.
  $row = new ResultRow();
  $prophecy = $this
    ->prophesize('Drupal\\Core\\Entity\\EntityInterface');
  $prophecy
    ->getCacheMaxAge()
    ->willReturn(10);
  $entity = $prophecy
    ->reveal();
  $row->_entity = $entity;
  $view->result[] = $row;

  // Add a row with an entity and a relationship entity.
  $row = new ResultRow();
  $prophecy = $this
    ->prophesize('Drupal\\Core\\Entity\\EntityInterface');
  $prophecy
    ->getCacheMaxAge()
    ->willReturn(20);
  $entity = $prophecy
    ->reveal();
  $row->_entity = $entity;
  $prophecy = $this
    ->prophesize('Drupal\\Core\\Entity\\EntityInterface');
  $prophecy
    ->getCacheMaxAge()
    ->willReturn(30);
  $entity = $prophecy
    ->reveal();
  $row->_relationship_entities[] = $entity;
  $prophecy = $this
    ->prophesize('Drupal\\Core\\Entity\\EntityInterface');
  $prophecy
    ->getCacheMaxAge()
    ->willReturn(40);
  $entity = $prophecy
    ->reveal();
  $row->_relationship_entities[] = $entity;
  $this
    ->assertEquals(10, $query
    ->getCacheMaxAge());
}