You are here

MigrateBlockTest.php in Style Switcher 8.2

Same filename and directory in other branches
  1. 3.0.x tests/src/Kernel/Migrate/d7/MigrateBlockTest.php

File

tests/src/Kernel/Migrate/d7/MigrateBlockTest.php
View source
<?php

namespace Drupal\Tests\styleswitcher\Kernel\Migrate\d7;

use Drupal\block\Entity\Block;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;

/**
 * Tests migration of the Style Switcher block to a configuration entity.
 *
 * @group styleswitcher
 */
class MigrateBlockTest extends MigrateDrupal7TestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'styleswitcher',
    'block',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this
      ->loadFixture(__DIR__ . '/../../../../fixtures/migrate/drupal7.styleswitcher.php');

    // Install the themes used for this test.
    $this->container
      ->get('theme_installer')
      ->install([
      'bartik',
      'seven',
    ]);
    $this
      ->installConfig(static::$modules);

    // Set Bartik and Seven as the default public and admin theme.
    $config = $this
      ->config('system.theme');
    $config
      ->set('default', 'bartik');
    $config
      ->set('admin', 'seven');
    $config
      ->save();
    $this
      ->executeMigrations([
      'd7_styleswitcher_block',
    ]);
    block_rebuild();
  }

  /**
   * Tests the block migration.
   */
  public function testBlockMigration() {
    $block = Block::load('bartik_styleswitcher_styleswitcher');
    $this
      ->assertTrue($block instanceof Block);

    /** @var \Drupal\block\BlockInterface $block */
    $this
      ->assertSame('styleswitcher_styleswitcher', $block
      ->getPluginId());
    $this
      ->assertSame('sidebar_first', $block
      ->getRegion());
    $this
      ->assertSame('bartik', $block
      ->getTheme());
    $this
      ->assertSame(TRUE, $block
      ->status());
    $config = $this
      ->config('block.block.bartik_styleswitcher_styleswitcher');
    $this
      ->assertSame('Switch Styles', $config
      ->get('settings.label'));
    $this
      ->assertSame('visible', $config
      ->get('settings.label_display'));

    // Assert that disabled blocks did not migrate.
    $non_existent_blocks = [
      'seven_styleswitcher_styleswitcher',
    ];
    $this
      ->assertTrue(empty(Block::loadMultiple($non_existent_blocks)));
  }

}

Classes

Namesort descending Description
MigrateBlockTest Tests migration of the Style Switcher block to a configuration entity.