You are here

public function LocalActionsAndTasksConvertedIntoBlocksUpdateTest::testUpdateHookN in Drupal 8

Tests that local actions/tasks are being converted into blocks.

File

core/modules/system/tests/src/Functional/Update/LocalActionsAndTasksConvertedIntoBlocksUpdateTest.php, line 46

Class

LocalActionsAndTasksConvertedIntoBlocksUpdateTest
Tests the upgrade path for local actions/tasks being converted into blocks.

Namespace

Drupal\Tests\system\Functional\Update

Code

public function testUpdateHookN() {
  $this
    ->runUpdates();

  /** @var \Drupal\block\BlockInterface $block_storage */
  $block_storage = \Drupal::entityTypeManager()
    ->getStorage('block');

  /* @var \Drupal\block\BlockInterface[] $help_blocks */
  $help_blocks = $block_storage
    ->loadByProperties([
    'theme' => 'bartik',
    'region' => 'help',
  ]);
  $this
    ->assertRaw('Because your site has custom theme(s) installed, we had to set local actions and tasks blocks into the content region. Please manually review the block configurations and remove the removed variables from your templates.');

  // Disable maintenance mode.
  // @todo Can be removed once maintenance mode is automatically turned off
  // after updates in https://www.drupal.org/node/2435135.
  \Drupal::state()
    ->set('system.maintenance_mode', FALSE);

  // We finished updating so we can log in the user now.
  $this
    ->drupalLogin($this->rootUser);
  $page = Node::create([
    'type' => 'page',
    'title' => 'Page node',
  ]);
  $page
    ->save();

  // Ensures that blocks inside help region has been moved to content region.
  foreach ($help_blocks as $block) {
    $new_block = $block_storage
      ->load($block
      ->id());
    $this
      ->assertEqual($new_block
      ->getRegion(), 'content');
  }

  // Local tasks are visible on the node page.
  $this
    ->drupalGet('node/' . $page
    ->id());
  $this
    ->assertText(t('Edit'));

  // Local actions are visible on the content listing page.
  $this
    ->drupalGet('admin/content');
  $action_link = $this
    ->cssSelect('.action-links');
  $this
    ->assertNotEmpty($action_link);
  $this
    ->drupalGet('admin/structure/block/list/seven');

  /** @var \Drupal\Core\Config\StorageInterface $config_storage */
  $config_storage = \Drupal::service('config.storage');
  $this
    ->assertTrue($config_storage
    ->exists('block.block.test_theme_local_tasks'), 'Local task block has been created for the custom theme.');
  $this
    ->assertTrue($config_storage
    ->exists('block.block.test_theme_local_actions'), 'Local action block has been created for the custom theme.');
}