MigrateVariablesTest.php in Style Switcher 3.0.x
File
tests/src/Kernel/Migrate/d7/MigrateVariablesTest.php
View source
<?php
namespace Drupal\Tests\styleswitcher\Kernel\Migrate\d7;
use Drupal\Core\Serialization\Yaml;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
class MigrateVariablesTest extends MigrateDrupal7TestBase {
public static $modules = [
'styleswitcher',
];
protected function setUp() {
parent::setUp();
$this
->loadFixture(__DIR__ . '/../../../../fixtures/migrate/drupal7.styleswitcher.php');
$this
->installConfig(static::$modules);
}
public function testVariablesMigration() {
$this
->executeMigrations([
'd7_styleswitcher_settings',
'd7_styleswitcher_custom_styles',
'd7_styleswitcher_styles_settings',
]);
$settings = $this
->config('styleswitcher.settings');
$this
->assertFalse($settings
->get('enable_overlay'));
$this
->assertSame('a_theme_name', $settings
->get('7206_theme_default'));
$config_names = [
'styleswitcher.custom_styles',
'styleswitcher.styles_settings',
];
foreach ($config_names as $name) {
$actual = $this
->config($name)
->getRawData();
unset($actual['_core']);
$expected = Yaml::decode(file_get_contents(__DIR__ . '/../../../../fixtures/migrate/' . $name . '.after.yml'));
$this
->assertSame($expected, $actual);
}
}
public function testMigrationWithUnsetVariables() {
$variables = [
'styleswitcher_enable_overlay',
'styleswitcher_7206_theme_default',
'styleswitcher_styles_settings',
];
$this->sourceDatabase
->delete('variable')
->condition('name', $variables, 'IN')
->execute();
$this
->startCollectingMessages();
$this
->executeMigrations([
'd7_styleswitcher_settings',
'd7_styleswitcher_styles_settings',
]);
$migrate_id_map = $this->migration
->getIdMap();
$messages = floatval(\Drupal::VERSION) >= 8.800000000000001 ? $migrate_id_map
->getMessages() : $migrate_id_map
->getMessageIterator();
$this
->assertEmpty($messages
->fetchAll());
$settings = $this
->config('styleswitcher.settings');
$this
->assertTrue($settings
->get('enable_overlay'));
$this
->assertNull($settings
->get('7206_theme_default'));
$this
->assertSame([], $this
->config('styleswitcher.styles_settings')
->get('settings'));
}
}