Update to Drupal 8.2.6. For more information, see https://www.drupal.org/project/drupal/releases/8.2.6
This commit is contained in:
parent
db56c09587
commit
f1e72395cb
588 changed files with 26857 additions and 2777 deletions
|
|
@ -0,0 +1,170 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
|
||||
/**
|
||||
* Tests rolling back of configuration objects.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrateConfigRollbackTest extends MigrateTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['system', 'language', 'config_translation'];
|
||||
|
||||
/**
|
||||
* Tests rolling back configuration.
|
||||
*/
|
||||
public function testConfigRollback() {
|
||||
// Use system.site configuration to demonstrate importing and rolling back
|
||||
// configuration.
|
||||
$variable = [
|
||||
[
|
||||
'id' => 'site_name',
|
||||
'site_name' => 'Some site',
|
||||
'site_slogan' => 'Awesome slogan',
|
||||
],
|
||||
];
|
||||
$ids = [
|
||||
'id' =>
|
||||
[
|
||||
'type' => 'string'
|
||||
],
|
||||
];
|
||||
$definition = [
|
||||
'id' => 'config',
|
||||
'migration_tags' => ['Import and rollback test'],
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => $variable,
|
||||
'ids' => $ids,
|
||||
],
|
||||
'process' => [
|
||||
'name' => 'site_name',
|
||||
'slogan' => 'site_slogan',
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'config',
|
||||
'config_name' => 'system.site',
|
||||
],
|
||||
];
|
||||
|
||||
/** @var \Drupal\migrate\Plugin\Migration $config_migration */
|
||||
$config_migration = \Drupal::service('plugin.manager.migration')
|
||||
->createStubMigration($definition);
|
||||
$config_id_map = $config_migration->getIdMap();
|
||||
|
||||
// Rollback is not enabled for configuration translations.
|
||||
$this->assertFalse($config_migration->getDestinationPlugin()->supportsRollback());
|
||||
|
||||
// Import and validate config entities were created.
|
||||
$config_executable = new MigrateExecutable($config_migration, $this);
|
||||
$config_executable->import();
|
||||
$config = $this->config('system.site');
|
||||
$this->assertSame('Some site', $config->get('name'));
|
||||
$this->assertSame('Awesome slogan', $config->get('slogan'));
|
||||
$map_row = $config_id_map->getRowBySource(['id' => $variable[0]['id']]);
|
||||
$this->assertNotNull($map_row['destid1']);
|
||||
|
||||
// Rollback and verify the configuration changes are still there.
|
||||
$config_executable->rollback();
|
||||
$config = $this->config('system.site');
|
||||
$this->assertSame('Some site', $config->get('name'));
|
||||
$this->assertSame('Awesome slogan', $config->get('slogan'));
|
||||
// Confirm the map row is deleted.
|
||||
$map_row = $config_id_map->getRowBySource(['id' => $variable[0]['id']]);
|
||||
$this->assertNull($map_row['destid1']);
|
||||
|
||||
// We use system configuration to demonstrate importing and rolling back
|
||||
// configuration translations.
|
||||
$i18n_variable = [
|
||||
[
|
||||
'id' => 'site_name',
|
||||
'language' => 'fr',
|
||||
'site_name' => 'fr - Some site',
|
||||
'site_slogan' => 'fr - Awesome slogan',
|
||||
],
|
||||
[
|
||||
'id' => 'site_name',
|
||||
'language' => 'is',
|
||||
'site_name' => 'is - Some site',
|
||||
'site_slogan' => 'is - Awesome slogan',
|
||||
],
|
||||
];
|
||||
$ids = [
|
||||
'id' =>
|
||||
[
|
||||
'type' => 'string'
|
||||
],
|
||||
'language' =>
|
||||
[
|
||||
'type' => 'string'
|
||||
]
|
||||
];
|
||||
$definition = [
|
||||
'id' => 'i18n_config',
|
||||
'migration_tags' => ['Import and rollback test'],
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => $i18n_variable,
|
||||
'ids' => $ids,
|
||||
],
|
||||
'process' => [
|
||||
'langcode' => 'language',
|
||||
'name' => 'site_name',
|
||||
'slogan' => 'site_slogan',
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'config',
|
||||
'config_name' => 'system.site',
|
||||
'translations' => 'true',
|
||||
],
|
||||
];
|
||||
|
||||
$config_migration = \Drupal::service('plugin.manager.migration')
|
||||
->createStubMigration($definition);
|
||||
$config_id_map = $config_migration->getIdMap();
|
||||
|
||||
// Rollback is enabled for configuration translations.
|
||||
$this->assertTrue($config_migration->getDestinationPlugin()->supportsRollback());
|
||||
|
||||
// Import and validate config entities were created.
|
||||
$config_executable = new MigrateExecutable($config_migration, $this);
|
||||
$config_executable->import();
|
||||
|
||||
$language_manager = \Drupal::service('language_manager');
|
||||
foreach ($i18n_variable as $row) {
|
||||
$langcode = $row['language'];
|
||||
/** @var \Drupal\language\Config\LanguageConfigOverride $config_translation */
|
||||
$config_translation = $language_manager->getLanguageConfigOverride($langcode, 'system.site');
|
||||
$this->assertSame($row['site_name'], $config_translation->get('name'));
|
||||
$this->assertSame($row['site_slogan'], $config_translation->get('slogan'));
|
||||
$map_row = $config_id_map->getRowBySource(['id' => $row['id'], 'language' => $row['language']]);
|
||||
$this->assertNotNull($map_row['destid1']);
|
||||
}
|
||||
|
||||
// Rollback and verify the translation have been removed.
|
||||
$config_executable->rollback();
|
||||
foreach ($i18n_variable as $row) {
|
||||
$langcode = $row['language'];
|
||||
$config_translation = $language_manager->getLanguageConfigOverride($langcode, 'system.site');
|
||||
$this->assertNull($config_translation->get('name'));
|
||||
$this->assertNull($config_translation->get('slogan'));
|
||||
// Confirm the map row is deleted.
|
||||
$map_row = $config_id_map->getRowBySource(['id' => $row['id'], 'language' => $langcode]);
|
||||
$this->assertFalse($map_row);
|
||||
}
|
||||
|
||||
// Test that the configuration is still present.
|
||||
$config = $this->config('system.site');
|
||||
$this->assertSame('Some site', $config->get('name'));
|
||||
$this->assertSame('Awesome slogan', $config->get('slogan'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
namespace Drupal\Tests\migrate\Kernel\process;
|
||||
|
||||
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
|
||||
use Drupal\KernelTests\Core\File\FileTestBase;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\Plugin\migrate\process\FileCopy;
|
||||
use Drupal\migrate\Row;
|
||||
|
|
@ -13,7 +13,7 @@ use Drupal\migrate\Row;
|
|||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class CopyFileTest extends FileTestBase {
|
||||
class CopyFileTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
@ -180,4 +180,39 @@ class CopyFileTest extends FileTestBase {
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a file and return the URI of it.
|
||||
*
|
||||
* @param $filepath
|
||||
* Optional string specifying the file path. If none is provided then a
|
||||
* randomly named file will be created in the site's files directory.
|
||||
* @param $contents
|
||||
* Optional contents to save into the file. If a NULL value is provided an
|
||||
* arbitrary string will be used.
|
||||
* @param $scheme
|
||||
* Optional string indicating the stream scheme to use. Drupal core includes
|
||||
* public, private, and temporary. The public wrapper is the default.
|
||||
* @return
|
||||
* File URI.
|
||||
*/
|
||||
protected function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) {
|
||||
if (!isset($filepath)) {
|
||||
// Prefix with non-latin characters to ensure that all file-related
|
||||
// tests work with international filenames.
|
||||
$filepath = 'Файл для тестирования ' . $this->randomMachineName();
|
||||
}
|
||||
if (empty($scheme)) {
|
||||
$scheme = file_default_scheme();
|
||||
}
|
||||
$filepath = $scheme . '://' . $filepath;
|
||||
|
||||
if (empty($contents)) {
|
||||
$contents = "file_put_contents() doesn't seem to appreciate empty strings so let's put in some data.";
|
||||
}
|
||||
|
||||
file_put_contents($filepath, $contents);
|
||||
$this->assertFileExists($filepath, t('The test file exists on the disk.'));
|
||||
return $filepath;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,9 +44,6 @@ class ConfigTest extends UnitTestCase {
|
|||
$row = $this->getMockBuilder('Drupal\migrate\Row')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$row->expects($this->once())
|
||||
->method('hasDestinationProperty')
|
||||
->will($this->returnValue(FALSE));
|
||||
$row->expects($this->any())
|
||||
->method('getRawDestination')
|
||||
->will($this->returnValue($source));
|
||||
|
|
@ -94,9 +91,6 @@ class ConfigTest extends UnitTestCase {
|
|||
$row = $this->getMockBuilder('Drupal\migrate\Row')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$row->expects($this->once())
|
||||
->method('hasDestinationProperty')
|
||||
->will($this->returnValue($source));
|
||||
$row->expects($this->any())
|
||||
->method('getRawDestination')
|
||||
->will($this->returnValue($source));
|
||||
|
|
@ -110,9 +104,9 @@ class ConfigTest extends UnitTestCase {
|
|||
->method('getLanguageConfigOverride')
|
||||
->with('mi', 'd8_config')
|
||||
->will($this->returnValue($config));
|
||||
$destination = new Config(array('config_name' => 'd8_config'), 'd8_config', array('pluginId' => 'd8_config'), $migration, $config_factory, $language_manager);
|
||||
$destination = new Config(array('config_name' => 'd8_config', 'translations' => 'true'), 'd8_config', array('pluginId' => 'd8_config'), $migration, $config_factory, $language_manager);
|
||||
$destination_id = $destination->import($row);
|
||||
$this->assertEquals($destination_id, ['d8_config']);
|
||||
$this->assertEquals($destination_id, ['d8_config', 'mi']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue