View source
<?php
namespace Drupal\Tests\search\Kernel\Migrate\d7;
use Drupal\Core\Database\Database;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
use Drupal\search\Entity\SearchPage;
class MigrateSearchPageTest extends MigrateDrupal7TestBase {
protected static $modules = [
'search',
];
protected function assertEntity($id, $path, $status = FALSE, array $expected_config = NULL) {
$search_page = SearchPage::load($id);
$this
->assertSame($id, $search_page
->id());
$this
->assertSame($path, $search_page
->getPath());
$this
->assertSame($status, $search_page
->status());
if (isset($expected_config)) {
$configuration = $search_page
->getPlugin()
->getConfiguration();
$this
->assertSame($expected_config, $configuration);
}
}
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');
Database::getConnection('default', 'migrate')
->update('variable')
->fields([
'value' => serialize(4),
])
->condition('name', 'node_rank_comments')
->execute();
$migration = $this
->getMigration('d7_search_page');
$migration
->getIdMap()
->prepareUpdate();
$this
->executeMigration($migration);
$configuration['rankings']['comments'] = 4;
$this
->assertEntity('node_search', 'node', TRUE, $configuration);
}
public function testModuleExists() {
$this
->installConfig([
'search',
]);
$this
->executeMigration('d7_search_page');
$this
->assertNull(SearchPage::load('node_search'));
$this
->assertEntity('user_search', 'user');
}
public function testUserSearchCreate() {
$this
->enableModules([
'node',
]);
$this
->installConfig([
'search',
]);
$search_page = SearchPage::load('user_search');
$search_page
->delete();
$this
->executeMigration('d7_search_page');
$this
->assertEntity('user_search', 'user');
}
}