You are here

public function RecalculatedDependencyTest::testUpdate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Update/RecalculatedDependencyTest.php \Drupal\system\Tests\Update\RecalculatedDependencyTest::testUpdate()

Ensures that the entities are resaved so they have the new dependency.

File

core/modules/system/src/Tests/Update/RecalculatedDependencyTest.php, line 29
Contains \Drupal\system\Tests\Update\RecalculatedDependencyTest.

Class

RecalculatedDependencyTest
Tests system_post_update_recalculate_dependencies_for_installed_config_entities().

Namespace

Drupal\system\Tests\Update

Code

public function testUpdate() {

  // Test the configuration pre update.
  $data = \Drupal::config('field.field.node.article.field_tags')
    ->get();
  $this
    ->assertEqual([
    'entity_reference',
  ], $data['dependencies']['module']);
  $this
    ->assertEqual([
    'field.storage.node.field_tags',
    'node.type.article',
  ], $data['dependencies']['config']);
  $data = \Drupal::config('field.field.user.user.user_picture')
    ->get();
  $this
    ->assertFalse(isset($data['dependencies']['module']));
  $data = \Drupal::config('field.storage.node.field_image')
    ->get();
  $this
    ->assertEqual([
    'node',
    'image',
  ], $data['dependencies']['module']);

  // Explicitly break an optional configuration dependencies to ensure it is
  // recalculated. Use active configuration storage directly so that no events
  // are fired.
  $config_storage = \Drupal::service('config.storage');
  $data = $config_storage
    ->read('search.page.node_search');
  unset($data['dependencies']);
  $config_storage
    ->write('search.page.node_search', $data);

  // Ensure the update is successful.
  $data = \Drupal::config('search.page.node_search')
    ->get();
  $this
    ->assertFalse(isset($data['dependencies']['module']));

  // Run the updates.
  $this
    ->runUpdates();

  // Test the configuration post update.
  $data = \Drupal::config('field.field.node.article.field_tags')
    ->get();
  $this
    ->assertFalse(isset($data['dependencies']['module']));
  $this
    ->assertEqual([
    'field.storage.node.field_tags',
    'node.type.article',
    'taxonomy.vocabulary.tags',
  ], $data['dependencies']['config']);
  $data = \Drupal::config('field.field.user.user.user_picture')
    ->get();
  $this
    ->assertEqual([
    'image',
    'user',
  ], $data['dependencies']['module']);
  $data = \Drupal::config('field.storage.node.field_image')
    ->get();
  $this
    ->assertEqual([
    'file',
    'image',
    'node',
  ], $data['dependencies']['module']);
  $data = \Drupal::config('search.page.node_search')
    ->get();
  $this
    ->assertEqual([
    'node',
  ], $data['dependencies']['module']);
}