5 * Contains \Drupal\Tests\migrate_drupal\Unit\source\d6\Drupal6SqlBaseTest.
8 namespace Drupal\Tests\migrate_drupal\Unit\source\d6;
10 use Drupal\Tests\migrate\Unit\MigrateTestCase;
13 * Tests the D6 SQL base class.
15 * @group migrate_drupal
17 class Drupal6SqlBaseTest extends MigrateTestCase {
20 * Define bare minimum migration configuration.
22 protected $migrationConfiguration = [
23 'id' => 'Drupal6SqlBase',
27 * @var \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
32 * Minimum database contents needed to test Drupal6SqlBase.
34 protected $databaseContents = [
37 'filename' => 'sites/all/modules/module1',
41 'schema_version' => -1,
44 'filename' => 'sites/all/modules/module2',
48 'schema_version' => 7201,
51 'filename' => 'sites/all/modules/test2',
55 'schema_version' => -1,
60 'name' => 'my_variable',
69 protected function setUp() {
70 $plugin = 'placeholder_id';
71 /** @var \Drupal\Core\State\StateInterface $state */
72 $state = $this->getMock('Drupal\Core\State\StateInterface');
73 /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
74 $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
75 $this->base = new TestDrupal6SqlBase($this->migrationConfiguration, $plugin, [], $this->getMigration(), $state, $entity_manager);
76 $this->base->setDatabase($this->getDatabase($this->databaseContents));
80 * Tests for Drupal6SqlBase::getSystemData().
82 public function testGetSystemData() {
83 $system_data = $this->base->getSystemData();
84 // Should be 1 theme and 2 modules.
85 $this->assertEquals(1, count($system_data['theme']));
86 $this->assertEquals(2, count($system_data['module']));
88 // Calling again should be identical.
89 $this->assertSame($system_data, $this->base->getSystemData());
93 * Tests for Drupal6SqlBase::moduleExists().
95 public function testDrupal6ModuleExists() {
96 // This module should exist.
97 $this->assertTrue($this->base->moduleExistsWrapper('module1'));
99 // These modules should not exist.
100 $this->assertFalse($this->base->moduleExistsWrapper('module2'));
101 $this->assertFalse($this->base->moduleExistsWrapper('module3'));
105 * Tests for Drupal6SqlBase::getModuleSchemaVersion().
107 public function testGetModuleSchemaVersion() {
108 // Non-existent module.
109 $this->assertFalse($this->base->getModuleSchemaVersionWrapper('module3'));
111 // Disabled module should still return schema version.
112 $this->assertEquals(7201, $this->base->getModuleSchemaVersionWrapper('module2'));
115 $this->assertEquals(-1, $this->base->getModuleSchemaVersionWrapper('module1'));
119 * Tests for Drupal6SqlBase::variableGet().
121 public function testVariableGet() {
122 // Test default value.
123 $this->assertEquals('my_default', $this->base->variableGetWrapper('non_existent_variable', 'my_default'));
126 $this->assertSame(TRUE, $this->base->variableGetWrapper('my_variable', FALSE));
131 namespace Drupal\Tests\migrate_drupal\Unit\source\d6;
133 use Drupal\Core\Database\Connection;
134 use Drupal\Core\Extension\ModuleHandlerInterface;
135 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
138 * Extends the Drupal6SqlBase abstract class.
140 class TestDrupal6SqlBase extends DrupalSqlBase {
145 public function fields() {
147 'filename' => t('The path of the primary file for this item.'),
148 'name' => t('The name of the item; e.g. node.'),
149 'type' => t('The type of the item, either module, theme, or theme_engine.'),
150 'owner' => t("A theme's 'parent'. Can be either a theme or an engine."),
151 'status' => t('Boolean indicating whether or not this item is enabled.'),
152 'throttle' => t('Boolean indicating whether this item is disabled when the throttle.module disables throttleable items.'),
153 'bootstrap' => t("Boolean indicating whether this module is loaded during Drupal's early bootstrapping phase (e.g. even before the page cache is consulted)."),
154 'schema_version' => t("The module's database schema version number."),
155 'weight' => t("The order in which this module's hooks should be invoked."),
156 'info' => t("A serialized array containing information from the module's .info file."),
163 public function query() {
164 $query = $this->database
165 ->select('system', 's')
166 ->fields('s', ['filename', 'name', 'schema_version']);
171 * Tweaks Drupal6SqlBase to set a new database connection for tests.
173 * @param \Drupal\Core\Database\Connection $database
174 * The new connection to use.
176 * @see \Drupal\Tests\migrate\Unit\MigrateSqlTestCase
178 public function setDatabase(Connection $database) {
179 $this->database = $database;
183 * Tweaks Drupal6SqlBase to set a new module handler for tests.
185 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
186 * The new module handler to use.
188 * @see \Drupal\Tests\migrate\Unit\MigrateSqlTestCase
190 public function setModuleHandler(ModuleHandlerInterface $module_handler) {
191 $this->moduleHandler = $module_handler;
195 * Wrapper method to test protected method moduleExists().
197 public function moduleExistsWrapper($module) {
198 return parent::moduleExists($module);
202 * Wrapper method to test protected method getModuleSchemaVersion().
204 public function getModuleSchemaVersionWrapper($module) {
205 return parent::getModuleSchemaVersion($module);
209 * Wrapper method to test protected method variableGet().
211 public function variableGetWrapper($name, $default) {
212 return parent::variableGet($name, $default);
218 public function getIds() {