function EntityConverterLatestRevisionTest::testOptimizedConvert

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/ParamConverter/EntityConverterLatestRevisionTest.php \Drupal\KernelTests\Core\ParamConverter\EntityConverterLatestRevisionTest::testOptimizedConvert()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/ParamConverter/EntityConverterLatestRevisionTest.php \Drupal\KernelTests\Core\ParamConverter\EntityConverterLatestRevisionTest::testOptimizedConvert()
  3. 10 core/tests/Drupal/KernelTests/Core/ParamConverter/EntityConverterLatestRevisionTest.php \Drupal\KernelTests\Core\ParamConverter\EntityConverterLatestRevisionTest::testOptimizedConvert()

Tests that pending revisions are loaded only when needed.

File

core/tests/Drupal/KernelTests/Core/ParamConverter/EntityConverterLatestRevisionTest.php, line 152

Class

EntityConverterLatestRevisionTest
Tests the entity converter when the "load_latest_revision" flag is set.

Namespace

Drupal\KernelTests\Core\ParamConverter

Code

public function testOptimizedConvert() : void {
    $entity = EntityTestMulRev::create();
    $entity->save();
    // Populate static cache for the current entity.
    $entity = EntityTestMulRev::load($entity->id());
    // Delete the base table entry for the current entity, however, since the
    // storage will query the revision table to get the latest revision, the
    // logic handling pending revisions will work correctly anyway.
    
    /** @var \Drupal\Core\Database\Connection $database */
    $database = $this->container
        ->get('database');
    $database->delete('entity_test_mulrev')
        ->condition('id', $entity->id())
        ->execute();
    // If optimization works, converting a default revision should not trigger
    // a storage load, thus making the following assertion pass.
    $converted = $this->converter
        ->convert(1, [
        'load_latest_revision' => TRUE,
        'type' => 'entity:entity_test_mulrev',
    ], 'foo', []);
    $this->assertEquals($entity->getLoadedRevisionId(), $converted->getLoadedRevisionId());
}

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