Skip to content
Snippets Groups Projects
Commit eac02c74 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2570541 by mikeryan, phenaproxima: Track simple configuration...

Issue #2570541 by mikeryan, phenaproxima: Track simple configuration migrations like normal migrations
parent ede86717
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
<?php <?php
/** /**
* @file * @file
* Contains \Drupal\migrate\Plugin\migrate\destination\Config. * Contains \Drupal\migrate\Plugin\migrate\destination\Config.
...@@ -78,7 +79,7 @@ public function import(Row $row, array $old_destination_id_values = array()) { ...@@ -78,7 +79,7 @@ public function import(Row $row, array $old_destination_id_values = array()) {
} }
} }
$this->config->save(); $this->config->save();
return TRUE; return [$this->config->getName()];
} }
/** /**
...@@ -92,7 +93,8 @@ public function fields(MigrationInterface $migration = NULL) { ...@@ -92,7 +93,8 @@ public function fields(MigrationInterface $migration = NULL) {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getIds() { public function getIds() {
return array(); $ids['config_name']['type'] = 'string';
return $ids;
} }
/** /**
......
...@@ -121,6 +121,13 @@ public function testSourceCount() { ...@@ -121,6 +121,13 @@ public function testSourceCount() {
$this->assertEquals($this->source->count(), $this->expectedCount); $this->assertEquals($this->source->count(), $this->expectedCount);
} }
/**
* Test the source defines a valid ID.
*/
public function testSourceId() {
$this->assertNotEmpty($this->source->getIds());
}
/** /**
* @param \Drupal\migrate\Row $row * @param \Drupal\migrate\Row $row
* @param string $key * @param string $key
......
...@@ -37,6 +37,9 @@ public function testImport() { ...@@ -37,6 +37,9 @@ public function testImport() {
} }
$config->expects($this->once()) $config->expects($this->once())
->method('save'); ->method('save');
$config->expects($this->once())
->method('getName')
->willReturn('d8_config');
$config_factory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface'); $config_factory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface');
$config_factory->expects($this->once()) $config_factory->expects($this->once())
->method('getEditable') ->method('getEditable')
...@@ -49,7 +52,8 @@ public function testImport() { ...@@ -49,7 +52,8 @@ public function testImport() {
->method('getRawDestination') ->method('getRawDestination')
->will($this->returnValue($source)); ->will($this->returnValue($source));
$destination = new Config(array('config_name' => 'd8_config'), 'd8_config', array('pluginId' => 'd8_config'), $migration, $config_factory); $destination = new Config(array('config_name' => 'd8_config'), 'd8_config', array('pluginId' => 'd8_config'), $migration, $config_factory);
$destination->import($row); $destination_id = $destination->import($row);
$this->assertEquals($destination_id, ['d8_config']);
} }
} }
...@@ -53,7 +53,10 @@ protected function initializeIterator() { ...@@ -53,7 +53,10 @@ protected function initializeIterator() {
* Only those values are returned that are actually in the database. * Only those values are returned that are actually in the database.
*/ */
protected function values() { protected function values() {
return array_map('unserialize', $this->prepareQuery()->execute()->fetchAllKeyed()); // Create an ID field so we can record migration in the map table.
// Arbitrarily, use the first variable name.
$values['id'] = reset($this->variables);
return $values + array_map('unserialize', $this->prepareQuery()->execute()->fetchAllKeyed());
} }
/** /**
...@@ -84,7 +87,8 @@ public function query() { ...@@ -84,7 +87,8 @@ public function query() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getIds() { public function getIds() {
return array(); $ids['id']['type'] = 'string';
return $ids;
} }
} }
...@@ -32,6 +32,7 @@ class VariableTest extends MigrateSqlSourceTestCase { ...@@ -32,6 +32,7 @@ class VariableTest extends MigrateSqlSourceTestCase {
protected $expectedResults = array( protected $expectedResults = array(
array( array(
'id' => 'foo',
'foo' => 1, 'foo' => 1,
'bar' => FALSE, 'bar' => FALSE,
), ),
......
...@@ -55,13 +55,15 @@ public function testSearchPage() { ...@@ -55,13 +55,15 @@ public function testSearchPage() {
->condition('name', 'node_rank_comments') ->condition('name', 'node_rank_comments')
->execute(); ->execute();
/** @var \Drupal\migrate\Entity\MigrationInterface $migration */
$migration = \Drupal::entityManager() $migration = \Drupal::entityManager()
->getStorage('migration') ->getStorage('migration')
->loadUnchanged('d6_search_page'); ->loadUnchanged('d6_search_page');
// Indicate we're rerunning a migration that's already run.
$migration->getIdMap()->prepareUpdate();
$this->executeMigration($migration); $this->executeMigration($migration);
$search_page = SearchPage::load($id); $configuration = SearchPage::load($id)->getPlugin()->getConfiguration();
$configuration = $search_page->getPlugin()->getConfiguration();
$this->assertIdentical(4, $configuration['rankings']['comments']); $this->assertIdentical(4, $configuration['rankings']['comments']);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment