View source
<?php
namespace Drupal\Tests\migrate_drupal\Unit\source\d6;
use Drupal\Tests\migrate\Unit\MigrateTestCase;
class Drupal6SqlBaseTest extends MigrateTestCase {
protected $migrationConfiguration = [
'id' => 'Drupal6SqlBase',
];
protected $base;
protected $databaseContents = [
'system' => [
[
'filename' => 'sites/all/modules/module1',
'name' => 'module1',
'type' => 'module',
'status' => 1,
'schema_version' => -1,
],
[
'filename' => 'sites/all/modules/module2',
'name' => 'module2',
'type' => 'module',
'status' => 0,
'schema_version' => 7201,
],
[
'filename' => 'sites/all/modules/test2',
'name' => 'test2',
'type' => 'theme',
'status' => 1,
'schema_version' => -1,
],
],
'variable' => [
[
'name' => 'my_variable',
'value' => 'b:1;',
],
],
];
protected function setUp() {
$plugin = 'placeholder_id';
$state = $this
->createMock('Drupal\\Core\\State\\StateInterface');
$entity_type_manager = $this
->createMock('Drupal\\Core\\Entity\\EntityTypeManagerInterface');
$this->base = new TestDrupal6SqlBase($this->migrationConfiguration, $plugin, [], $this
->getMigration(), $state, $entity_type_manager);
$this->base
->setDatabase($this
->getDatabase($this->databaseContents));
}
public function testGetSystemData() {
$system_data = $this->base
->getSystemData();
$this
->assertCount(1, $system_data['theme']);
$this
->assertCount(2, $system_data['module']);
$this
->assertSame($system_data, $this->base
->getSystemData());
}
public function testDrupal6ModuleExists() {
$this
->assertTrue($this->base
->moduleExistsWrapper('module1'));
$this
->assertFalse($this->base
->moduleExistsWrapper('module2'));
$this
->assertFalse($this->base
->moduleExistsWrapper('module3'));
}
public function testGetModuleSchemaVersion() {
$this
->assertFalse($this->base
->getModuleSchemaVersionWrapper('module3'));
$this
->assertEquals(7201, $this->base
->getModuleSchemaVersionWrapper('module2'));
$this
->assertEquals(-1, $this->base
->getModuleSchemaVersionWrapper('module1'));
}
public function testVariableGet() {
$this
->assertEquals('my_default', $this->base
->variableGetWrapper('non_existent_variable', 'my_default'));
$this
->assertSame(TRUE, $this->base
->variableGetWrapper('my_variable', FALSE));
}
}
namespace Drupal\Tests\migrate_drupal\Unit\source\d6;
use Drupal\Core\Database\Connection;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
class TestDrupal6SqlBase extends DrupalSqlBase {
public function fields() {
return [
'filename' => t('The path of the primary file for this item.'),
'name' => t('The name of the item; e.g. node.'),
'type' => t('The type of the item, either module, theme, or theme_engine.'),
'owner' => t("A theme's 'parent'. Can be either a theme or an engine."),
'status' => t('Boolean indicating whether or not this item is enabled.'),
'throttle' => t('Boolean indicating whether this item is disabled when the throttle.module disables throttleable items.'),
'bootstrap' => t("Boolean indicating whether this module is loaded during Drupal's early bootstrapping phase (e.g. even before the page cache is consulted)."),
'schema_version' => t("The module's database schema version number."),
'weight' => t("The order in which this module's hooks should be invoked."),
'info' => t("A serialized array containing information from the module's .info file."),
];
}
public function query() {
$query = $this->database
->select('system', 's')
->fields('s', [
'filename',
'name',
'schema_version',
]);
return $query;
}
public function setDatabase(Connection $database) {
$this->database = $database;
}
public function setModuleHandler(ModuleHandlerInterface $module_handler) {
$this->moduleHandler = $module_handler;
}
public function moduleExistsWrapper($module) {
return parent::moduleExists($module);
}
public function getModuleSchemaVersionWrapper($module) {
return parent::getModuleSchemaVersion($module);
}
public function variableGetWrapper($name, $default) {
return parent::variableGet($name, $default);
}
public function getIds() {
return [];
}
}