function BlockWeightUpdateTest::testRunUpdates

Tests update path for blocks' `weight` property.

File

core/modules/block/tests/src/Functional/BlockWeightUpdateTest.php, line 33

Class

BlockWeightUpdateTest
Tests Block Weight Update.

Namespace

Drupal\Tests\block\Functional

Code

public function testRunUpdates() {
  // Find a block and change it to have a null weight.
  /** @var \Drupal\Core\Database\Connection $database */
  $database = $this->container
    ->get('database');
  $block = $database->select('config', 'c')
    ->fields('c', [
    'data',
  ])
    ->condition('name', 'block.block.claro_content')
    ->execute()
    ->fetchField();
  $block = unserialize($block);
  $block['weight'] = NULL;
  $database->update('config')
    ->fields([
    'data' => serialize($block),
  ])
    ->condition('name', 'block.block.claro_content')
    ->execute();
  $this->assertNull(Block::load('claro_content')->get('weight'));
  $this->runUpdates();
  $this->assertSame(0, Block::load('claro_content')->get('weight'));
}

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