Issue #2587063 by quietone, Jo Fitzgerald, jhodgdon, phenaproxima, alexpott, mikeryan: Variable to config: search_active_modules [d7]
parent
e08ac28213
commit
f054e6060b
|
@ -44169,7 +44169,7 @@ $connection->insert('variable')
|
||||||
))
|
))
|
||||||
->values(array(
|
->values(array(
|
||||||
'name' => 'search_active_modules',
|
'name' => 'search_active_modules',
|
||||||
'value' => 'a:2:{s:4:"node";s:4:"node";s:4:"user";s:4:"user";}',
|
'value' => 'a:2:{s:4:"node";s:4:"node";s:4:"user";i:0;}',
|
||||||
))
|
))
|
||||||
->values(array(
|
->values(array(
|
||||||
'name' => 'search_and_or_limit',
|
'name' => 'search_and_or_limit',
|
||||||
|
|
|
@ -394,7 +394,7 @@ class MigrateUpgradeForm extends ConfirmFormBase {
|
||||||
'source_module' => 'path',
|
'source_module' => 'path',
|
||||||
'destination_module' => 'path',
|
'destination_module' => 'path',
|
||||||
],
|
],
|
||||||
'search_page' => [
|
'd6_search_page' => [
|
||||||
'source_module' => 'search',
|
'source_module' => 'search',
|
||||||
'destination_module' => 'search',
|
'destination_module' => 'search',
|
||||||
],
|
],
|
||||||
|
@ -402,6 +402,10 @@ class MigrateUpgradeForm extends ConfirmFormBase {
|
||||||
'source_module' => 'search',
|
'source_module' => 'search',
|
||||||
'destination_module' => 'search',
|
'destination_module' => 'search',
|
||||||
],
|
],
|
||||||
|
'd7_search_page' => [
|
||||||
|
'source_module' => 'search',
|
||||||
|
'destination_module' => 'search',
|
||||||
|
],
|
||||||
'd7_search_settings' => [
|
'd7_search_settings' => [
|
||||||
'source_module' => 'search',
|
'source_module' => 'search',
|
||||||
'destination_module' => 'search',
|
'destination_module' => 'search',
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
id: search_page
|
id: d6_search_page
|
||||||
label: Search page configuration
|
label: Search page configuration
|
||||||
migration_tags:
|
migration_tags:
|
||||||
- Drupal 6
|
- Drupal 6
|
||||||
- Drupal 7
|
|
||||||
source:
|
source:
|
||||||
plugin: variable
|
plugin: d6_search_page
|
||||||
variables:
|
variables:
|
||||||
- node_rank_comments
|
- node_rank_comments
|
||||||
- node_rank_promote
|
- node_rank_promote
|
||||||
|
@ -17,6 +16,7 @@ source:
|
||||||
path: node
|
path: node
|
||||||
plugin: node_search
|
plugin: node_search
|
||||||
process:
|
process:
|
||||||
|
module: module
|
||||||
id: 'constants/id'
|
id: 'constants/id'
|
||||||
path: 'constants/path'
|
path: 'constants/path'
|
||||||
plugin: 'constants/plugin'
|
plugin: 'constants/plugin'
|
|
@ -0,0 +1,46 @@
|
||||||
|
id: d7_search_page
|
||||||
|
label: Search page configuration
|
||||||
|
migration_tags:
|
||||||
|
- Drupal 7
|
||||||
|
source:
|
||||||
|
plugin: d7_search_page
|
||||||
|
variables:
|
||||||
|
- node_rank_comments
|
||||||
|
- node_rank_promote
|
||||||
|
- node_rank_relevance
|
||||||
|
- node_rank_sticky
|
||||||
|
- node_rank_views
|
||||||
|
constants:
|
||||||
|
suffix: _search
|
||||||
|
process:
|
||||||
|
module: module
|
||||||
|
module_exists:
|
||||||
|
-
|
||||||
|
plugin: skip_on_empty
|
||||||
|
method: row
|
||||||
|
source: module_exists
|
||||||
|
status:
|
||||||
|
-
|
||||||
|
plugin: static_map
|
||||||
|
source: status
|
||||||
|
map:
|
||||||
|
node: true
|
||||||
|
user: true
|
||||||
|
0: false
|
||||||
|
id:
|
||||||
|
-
|
||||||
|
plugin: concat
|
||||||
|
source:
|
||||||
|
- module
|
||||||
|
- 'constants/suffix'
|
||||||
|
plugin:
|
||||||
|
-
|
||||||
|
plugin: concat
|
||||||
|
source:
|
||||||
|
- module
|
||||||
|
- 'constants/suffix'
|
||||||
|
path: module
|
||||||
|
'configuration/rankings':
|
||||||
|
plugin: search_configuration_rankings
|
||||||
|
destination:
|
||||||
|
plugin: entity:search_page
|
|
@ -3,8 +3,12 @@
|
||||||
namespace Drupal\search\Plugin\migrate\destination;
|
namespace Drupal\search\Plugin\migrate\destination;
|
||||||
|
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
|
use Drupal\Core\Entity\EntityStorageInterface;
|
||||||
|
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||||
use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
|
use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
|
||||||
|
use Drupal\migrate\Plugin\MigrationInterface;
|
||||||
use Drupal\migrate\Row;
|
use Drupal\migrate\Row;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @MigrateDestination(
|
* @MigrateDestination(
|
||||||
|
@ -13,6 +17,72 @@ use Drupal\migrate\Row;
|
||||||
*/
|
*/
|
||||||
class EntitySearchPage extends EntityConfigBase {
|
class EntitySearchPage extends EntityConfigBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The module handler.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||||
|
*/
|
||||||
|
protected $moduleHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new EntitySearchPage.
|
||||||
|
*
|
||||||
|
* @param array $configuration
|
||||||
|
* A configuration array containing information about the plugin instance.
|
||||||
|
* @param string $plugin_id
|
||||||
|
* The plugin_id for the plugin instance.
|
||||||
|
* @param mixed $plugin_definition
|
||||||
|
* The plugin implementation definition.
|
||||||
|
* @param MigrationInterface $migration
|
||||||
|
* The migration.
|
||||||
|
* @param EntityStorageInterface $storage
|
||||||
|
* The storage for this entity type.
|
||||||
|
* @param array $bundles
|
||||||
|
* The list of bundles this entity type has.
|
||||||
|
* @param ModuleHandlerInterface $module_handler
|
||||||
|
* The module handler.
|
||||||
|
*/
|
||||||
|
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, ModuleHandlerInterface $module_handler) {
|
||||||
|
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles);
|
||||||
|
$this->moduleHandler = $module_handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
|
||||||
|
$entity_type_id = static::getEntityTypeId($plugin_id);
|
||||||
|
return new static(
|
||||||
|
$configuration,
|
||||||
|
$plugin_id,
|
||||||
|
$plugin_definition,
|
||||||
|
$migration,
|
||||||
|
$container->get('entity.manager')->getStorage($entity_type_id),
|
||||||
|
array_keys($container->get('entity.manager')->getBundleInfo($entity_type_id)),
|
||||||
|
$container->get('module_handler')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||||
|
if ($this->moduleHandler->moduleExists($row->getDestinationProperty('module'))) {
|
||||||
|
parent::import($row, $old_destination_id_values);
|
||||||
|
$id = $row->getDestinationProperty('id');
|
||||||
|
/** @var \Drupal\search\Entity\SearchPage $search_page */
|
||||||
|
$search_page = $this->storage->load($id);
|
||||||
|
if ($row->getDestinationProperty('status')) {
|
||||||
|
$search_page->enable()->save();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$search_page->disable()->save();
|
||||||
|
}
|
||||||
|
return [$id];
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the entity with the contents of a row.
|
* Updates the entity with the contents of a row.
|
||||||
*
|
*
|
||||||
|
@ -23,7 +93,10 @@ class EntitySearchPage extends EntityConfigBase {
|
||||||
*/
|
*/
|
||||||
protected function updateEntity(EntityInterface $entity, Row $row) {
|
protected function updateEntity(EntityInterface $entity, Row $row) {
|
||||||
$entity->setPlugin($row->getDestinationProperty('plugin'));
|
$entity->setPlugin($row->getDestinationProperty('plugin'));
|
||||||
$entity->getPlugin()->setConfiguration($row->getDestinationProperty('configuration'));
|
// The user_search plugin does not have a setConfiguration() method.
|
||||||
|
if (method_exists($entity->getPlugin(), 'setConfiguration')) {
|
||||||
|
$entity->getPlugin()->setConfiguration($row->getDestinationProperty('configuration'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ class SearchConfigurationRankings extends ProcessPluginBase {
|
||||||
* Generate the configuration rankings.
|
* Generate the configuration rankings.
|
||||||
*/
|
*/
|
||||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||||
$return = array();
|
$return = NULL;
|
||||||
foreach ($row->getSource() as $name => $rank) {
|
foreach ($row->getSource() as $name => $rank) {
|
||||||
if (substr($name, 0, 10) == 'node_rank_' && is_numeric($rank)) {
|
if (substr($name, 0, 10) == 'node_rank_' && is_numeric($rank)) {
|
||||||
$return[substr($name, 10)] = $rank;
|
$return[substr($name, 10)] = $rank;
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Drupal\search\Plugin\migrate\process\d6;
|
|
||||||
|
|
||||||
use Drupal\migrate\ProcessPluginBase;
|
|
||||||
use Drupal\migrate\MigrateExecutableInterface;
|
|
||||||
use Drupal\migrate\Row;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate configuration rankings.
|
|
||||||
*
|
|
||||||
* @MigrateProcessPlugin(
|
|
||||||
* id = "d6_search_configuration_rankings"
|
|
||||||
* )
|
|
||||||
*/
|
|
||||||
class SearchConfigurationRankings extends ProcessPluginBase {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*
|
|
||||||
* Generate the configuration rankings.
|
|
||||||
*/
|
|
||||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
|
||||||
$return = array();
|
|
||||||
foreach ($row->getSource() as $name => $rank) {
|
|
||||||
if (substr($name, 0, 10) == 'node_rank_' && $rank) {
|
|
||||||
$return[substr($name, 10)] = $rank;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\search\Plugin\migrate\source\d6;
|
||||||
|
|
||||||
|
use Drupal\migrate_drupal\Plugin\migrate\source\Variable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get node search rankings for core modules.
|
||||||
|
*
|
||||||
|
* @MigrateSource(
|
||||||
|
* id = "d6_search_page"
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
class SearchPage extends Variable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the values of the variables specified in the plugin configuration.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* An associative array where the keys are the variables specified in the
|
||||||
|
* plugin configuration and the values are the values found in the source.
|
||||||
|
* Only those values are returned that are actually in the database.
|
||||||
|
*/
|
||||||
|
protected function values() {
|
||||||
|
return array_merge(['module' => 'node'], parent::values());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function fields() {
|
||||||
|
return [
|
||||||
|
'module' => $this->t('The search module.'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getIds() {
|
||||||
|
$ids['module']['type'] = 'string';
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,89 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\search\Plugin\migrate\source\d7;
|
||||||
|
|
||||||
|
use Drupal\migrate\Row;
|
||||||
|
use Drupal\migrate_drupal\Plugin\migrate\source\Variable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get search_active_modules and rankings for core modules.
|
||||||
|
*
|
||||||
|
* @MigrateSource(
|
||||||
|
* id = "d7_search_page",
|
||||||
|
* source_provider = "search"
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
class SearchPage extends Variable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function initializeIterator() {
|
||||||
|
return new \ArrayIterator($this->values());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the values of the variables specified in the plugin configuration.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* An associative array where the keys are the variables specified in the
|
||||||
|
* plugin configuration and the values are the values found in the source.
|
||||||
|
* And includes the search module and search status.
|
||||||
|
* Only those values are returned that are actually in the database.
|
||||||
|
*/
|
||||||
|
protected function values() {
|
||||||
|
$search_active_modules = $this->variableGet('search_active_modules', '');
|
||||||
|
$values = [];
|
||||||
|
foreach (['node', 'user'] as $module) {
|
||||||
|
if (isset($search_active_modules[$module])) {
|
||||||
|
// Create an ID field so we can record migration in the map table.
|
||||||
|
$tmp = [
|
||||||
|
'module' => $module,
|
||||||
|
'status' => $search_active_modules[$module],
|
||||||
|
];
|
||||||
|
// Add the node_rank_* variables (only relevant to the node module).
|
||||||
|
if ($module === 'node') {
|
||||||
|
$tmp = array_merge($tmp, parent::values());
|
||||||
|
}
|
||||||
|
$values[] = $tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $values;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function fields() {
|
||||||
|
return [
|
||||||
|
'module' => $this->t('The search module.'),
|
||||||
|
'status' => $this->t('Whether or not this module is enabled for search.'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getIds() {
|
||||||
|
$ids['module']['type'] = 'string';
|
||||||
|
$ids['status']['type'] = 'string';
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function count() {
|
||||||
|
return $this->initializeIterator()->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function prepareRow(Row $row) {
|
||||||
|
$exists = $this->moduleExists($row->getSourceProperty('module'));
|
||||||
|
$row->setSourceProperty('module_exists', $exists);
|
||||||
|
return parent::prepareRow($row);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||||
use Drupal\search\Entity\SearchPage;
|
use Drupal\search\Entity\SearchPage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upgrade search rank settings to search.page.*.yml.
|
* Upgrade search page variables.
|
||||||
*
|
*
|
||||||
* @group migrate_drupal_6
|
* @group migrate_drupal_6
|
||||||
*/
|
*/
|
||||||
|
@ -23,7 +23,7 @@ class MigrateSearchPageTest extends MigrateDrupal6TestBase {
|
||||||
*/
|
*/
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->executeMigration('search_page');
|
$this->executeMigration('d6_search_page');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +53,7 @@ class MigrateSearchPageTest extends MigrateDrupal6TestBase {
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||||
$migration = $this->getMigration('search_page');
|
$migration = $this->getMigration('d6_search_page');
|
||||||
// Indicate we're rerunning a migration that's already run.
|
// Indicate we're rerunning a migration that's already run.
|
||||||
$migration->getIdMap()->prepareUpdate();
|
$migration->getIdMap()->prepareUpdate();
|
||||||
$this->executeMigration($migration);
|
$this->executeMigration($migration);
|
||||||
|
|
|
@ -7,7 +7,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||||
use Drupal\search\Entity\SearchPage;
|
use Drupal\search\Entity\SearchPage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upgrade search rank settings to search.page.*.yml.
|
* Tests migration of search page status and settings.
|
||||||
*
|
*
|
||||||
* @group migrate_drupal_7
|
* @group migrate_drupal_7
|
||||||
*/
|
*/
|
||||||
|
@ -18,34 +18,59 @@ class MigrateSearchPageTest extends MigrateDrupal7TestBase {
|
||||||
*
|
*
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public static $modules = array('node', 'search');
|
public static $modules = ['search'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->executeMigration('search_page');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests Drupal 7 search ranking to Drupal 8 search page entity migration.
|
* Asserts various aspects of an SearchPage entity.
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
* The expected search page ID.
|
||||||
|
* @param string $path
|
||||||
|
* The expected path of the search page.
|
||||||
|
* @param bool $status
|
||||||
|
* The expected status of the search page.
|
||||||
|
* @param array $expected_config
|
||||||
|
* An array of expected configuration for the search page.
|
||||||
*/
|
*/
|
||||||
public function testSearchPage() {
|
protected function assertEntity($id, $path, $status = FALSE, array $expected_config = NULL) {
|
||||||
$id = 'node_search';
|
|
||||||
/** @var \Drupal\search\Entity\SearchPage $search_page */
|
/** @var \Drupal\search\Entity\SearchPage $search_page */
|
||||||
$search_page = SearchPage::load($id);
|
$search_page = SearchPage::load($id);
|
||||||
$this->assertIdentical($id, $search_page->id());
|
$this->assertSame($id, $search_page->id());
|
||||||
$configuration = $search_page->getPlugin()->getConfiguration();
|
$this->assertSame($path, $search_page->getPath());
|
||||||
$expected_rankings = array(
|
$this->assertSame($search_page->status(), $status);
|
||||||
'comments' => 0,
|
if (isset($expected_config)) {
|
||||||
'promote' => 0,
|
$configuration = $search_page->getPlugin()->getConfiguration();
|
||||||
'relevance' => 2,
|
$this->assertSame($expected_config, $configuration);
|
||||||
'sticky' => 0,
|
}
|
||||||
'views' => 0,
|
}
|
||||||
);
|
|
||||||
$this->assertIdentical($expected_rankings, $configuration['rankings']);
|
/**
|
||||||
$this->assertIdentical('node', $search_page->getPath());
|
* Tests Drupal 7 search status and settings to Drupal 8 search page entity
|
||||||
|
* migration.
|
||||||
|
*/
|
||||||
|
public function testSearchPage() {
|
||||||
|
$this->enableModules(['node']);
|
||||||
|
$this->installConfig(['search']);
|
||||||
|
$this->executeMigration('d7_search_page');
|
||||||
|
|
||||||
|
$configuration = [
|
||||||
|
'rankings' => [
|
||||||
|
'comments' => 0,
|
||||||
|
'promote' => 0,
|
||||||
|
'relevance' => 2,
|
||||||
|
'sticky' => 0,
|
||||||
|
'views' => 0,
|
||||||
|
]
|
||||||
|
];
|
||||||
|
$this->assertEntity('node_search', 'node', TRUE, $configuration);
|
||||||
|
$this->assertEntity('user_search', 'user');
|
||||||
|
|
||||||
// Test that we can re-import using the EntitySearchPage destination.
|
// Test that we can re-import using the EntitySearchPage destination.
|
||||||
Database::getConnection('default', 'migrate')
|
Database::getConnection('default', 'migrate')
|
||||||
|
@ -55,13 +80,38 @@ class MigrateSearchPageTest extends MigrateDrupal7TestBase {
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||||
$migration = $this->getMigration('search_page');
|
$migration = $this->getMigration('d7_search_page');
|
||||||
// Indicate we're rerunning a migration that's already run.
|
// Indicate we're rerunning a migration that's already run.
|
||||||
$migration->getIdMap()->prepareUpdate();
|
$migration->getIdMap()->prepareUpdate();
|
||||||
$this->executeMigration($migration);
|
$this->executeMigration($migration);
|
||||||
|
$configuration['rankings']['comments'] = 4;
|
||||||
|
$this->assertEntity('node_search', 'node', TRUE, $configuration);
|
||||||
|
}
|
||||||
|
|
||||||
$configuration = SearchPage::load($id)->getPlugin()->getConfiguration();
|
/**
|
||||||
$this->assertIdentical(4, $configuration['rankings']['comments']);
|
* Tests that search page is only migrated for modules enabled on
|
||||||
|
* destination site.
|
||||||
|
*/
|
||||||
|
public function testModuleExists() {
|
||||||
|
$this->installConfig(['search']);
|
||||||
|
$this->executeMigration('d7_search_page');
|
||||||
|
|
||||||
|
$this->assertNull(SearchPage::load('node_search'));
|
||||||
|
$this->assertEntity('user_search', 'user');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that a search page will be created if it does not exist.
|
||||||
|
*/
|
||||||
|
public function testUserSearchCreate() {
|
||||||
|
$this->enableModules(['node']);
|
||||||
|
$this->installConfig(['search']);
|
||||||
|
/** @var \Drupal\search\Entity\SearchPage $search_page */
|
||||||
|
$search_page = SearchPage::load('user_search');
|
||||||
|
$search_page->delete();
|
||||||
|
$this->executeMigration('d7_search_page');
|
||||||
|
|
||||||
|
$this->assertEntity('user_search', 'user');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\Tests\search\Unit\Plugin\migrate\source\d6;
|
||||||
|
|
||||||
|
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests D6 search page source plugin.
|
||||||
|
*
|
||||||
|
* @covers \Drupal\search\Plugin\migrate\source\d6\SearchPage
|
||||||
|
* @group search
|
||||||
|
*/
|
||||||
|
class SearchPageTest extends MigrateSqlSourceTestBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static $modules = ['search', 'migrate_drupal'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function providerSource() {
|
||||||
|
$tests[0]['source_data'] = [
|
||||||
|
'variable' => [
|
||||||
|
[
|
||||||
|
'name' => 'node_rank_comments',
|
||||||
|
'value' => 's:1:"5";',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'node_rank_promote',
|
||||||
|
'value' => 's:1:"1";',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'system' => [
|
||||||
|
[
|
||||||
|
'name' => 'node',
|
||||||
|
'type' => 'module',
|
||||||
|
'status' => '1',
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$tests[0]['expected_data'] = [
|
||||||
|
[
|
||||||
|
'module' => 'node',
|
||||||
|
'node_rank_comments' => '5',
|
||||||
|
'node_rank_promote' => '1',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$tests[0]['expected_count'] = NULL;
|
||||||
|
|
||||||
|
$tests[0]['configuration'] = [
|
||||||
|
'variables' => ['node_rank_comments', 'node_rank_promote'],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $tests;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\Tests\search\Unit\Plugin\migrate\source\d7;
|
||||||
|
|
||||||
|
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests D7 search page source plugin.
|
||||||
|
*
|
||||||
|
* @covers \Drupal\search\Plugin\migrate\source\d7\SearchPage
|
||||||
|
* @group search
|
||||||
|
*/
|
||||||
|
class SearchPageTest extends MigrateSqlSourceTestBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static $modules = ['search', 'migrate_drupal'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function providerSource() {
|
||||||
|
$tests[0]['source_data'] = [
|
||||||
|
'variable' => [
|
||||||
|
[
|
||||||
|
'name' => 'search_active_modules',
|
||||||
|
'value' => 'a:2:{s:4:"node";s:4:"node";s:4:"user";i:0;}',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'node_rank_comments',
|
||||||
|
'value' => 's:1:"5";',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'node_rank_promote',
|
||||||
|
'value' => 's:1:"1";',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'system' => [
|
||||||
|
[
|
||||||
|
'name' => 'node',
|
||||||
|
'type' => 'module',
|
||||||
|
'status' => '0',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'user',
|
||||||
|
'type' => 'module',
|
||||||
|
'status' => '1',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$tests[0]['expected_data'] = [
|
||||||
|
[
|
||||||
|
'module' => 'node',
|
||||||
|
'status' => 'node',
|
||||||
|
'module_exists' => FALSE,
|
||||||
|
'node_rank_comments' => '5',
|
||||||
|
'node_rank_promote' => '1',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'module' => 'user',
|
||||||
|
'status' => 0,
|
||||||
|
'module_exists' => TRUE,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$tests[0]['expected_count'] = NULL;
|
||||||
|
|
||||||
|
$tests[0]['configuration'] = [
|
||||||
|
'variables' => ['node_rank_comments', 'node_rank_promote'],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $tests;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue