function SqlTest::testGetCacheMaxAge

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest::testGetCacheMaxAge()
  2. 8.9.x core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest::testGetCacheMaxAge()
  3. 10 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 81

Class

SqlTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21views%21src%21Plugin%21views%21query%21Sql.php/class/Sql/11.x" title="Views query plugin for an SQL query." class="local">\Drupal\views\Plugin\views\query\Sql</a>

Namespace

Drupal\Tests\views\Unit\Plugin\query

Code

public function testGetCacheMaxAge() : void {
    $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;
    $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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.