You are here

public function BrokenCacheUpdateTest::testUpdate in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/UpdateSystem/BrokenCacheUpdateTest.php \Drupal\Tests\system\Functional\UpdateSystem\BrokenCacheUpdateTest::testUpdate()

Ensures that a broken or out-of-date element info cache is not used.

File

core/modules/system/tests/src/Functional/UpdateSystem/BrokenCacheUpdateTest.php, line 33

Class

BrokenCacheUpdateTest
Ensures that a broken or out-of-date element info cache is not used.

Namespace

Drupal\Tests\system\Functional\UpdateSystem

Code

public function testUpdate() {
  $connection = Database::getConnection();

  // Create broken element info caches entries.
  $insert = $connection
    ->upsert('cache_discovery');
  $insert
    ->key('cid');
  $fields = [
    'cid' => 'element_info',
    'data' => 'BROKEN',
    'expire' => -1,
    'created' => '1549505157.144',
    'serialized' => 1,
    'tags' => '',
    'checksum' => 0,
  ];
  $insert
    ->fields($fields);
  $fields['cid'] = 'element_info_build:seven';
  $fields['tags'] = 'element_info_build';
  $insert
    ->values(array_values($fields));
  $fields['cid'] = 'element_info_build:stark';
  $insert
    ->values(array_values($fields));
  $insert
    ->execute();
  $this
    ->runUpdates();

  // Caches should have been cleared at this point.
  $count = (int) $connection
    ->select('cache_discovery')
    ->condition('cid', [
    'element_info',
    'element_info_build:seven',
    'element_info_build:stark',
  ], 'IN')
    ->countQuery()
    ->execute()
    ->fetchField();
  $this
    ->assertSame(0, $count);
}