Newer
Older
<?php
/**
* @file
Dries Buytaert
committed
* Contains \Drupal\Tests\migrate_drupal\Unit\source\d6\Drupal6SqlBaseTest.
*/
Dries Buytaert
committed
namespace Drupal\Tests\migrate_drupal\Unit\source\d6;
Dries Buytaert
committed
use Drupal\Tests\migrate\Unit\MigrateTestCase;
/**
* Tests the D6 SQL base class.
*
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
* @group migrate_drupal
*/
class Drupal6SqlBaseTest extends MigrateTestCase {
/**
* Define bare minimum migration configuration.
*/
protected $migrationConfiguration = array(
'id' => 'Drupal6SqlBase',
);
/**
* @var \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
*/
protected $base;
/**
* Minimum database contents needed to test Drupal6SqlBase.
*/
protected $databaseContents = array(
'system' => array(
array(
'filename' => 'sites/all/modules/module1',
'name' => 'module1',
'type' => 'module',
'status' => 1,
'schema_version' => -1,
),
array(
'filename' => 'sites/all/modules/module2',
'name' => 'module2',
'type' => 'module',
'status' => 0,
'schema_version' => 7201,
),
array(
'filename' => 'sites/all/modules/test2',
'name' => 'test2',
'type' => 'theme',
'status' => 1,
'schema_version' => -1,
),
),
'variable' => array(
array(
'name' => 'my_variable',
'value' => 'b:1;',
),
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
$plugin = 'placeholder_id';
Angie Byron
committed
/** @var \Drupal\Core\State\StateInterface $state */
$state = $this->getMock('Drupal\Core\State\StateInterface');
/** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$this->base = new TestDrupal6SqlBase($this->migrationConfiguration, $plugin, array(), $this->getMigration(), $state, $entity_manager);
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
$this->base->setDatabase($this->getDatabase($this->databaseContents));
}
/**
* Tests for Drupal6SqlBase::getSystemData().
*/
public function testGetSystemData() {
$system_data = $this->base->getSystemData();
// Should be 1 theme and 2 modules.
$this->assertEquals(1, count($system_data['theme']));
$this->assertEquals(2, count($system_data['module']));
// Calling again should be identical.
$this->assertSame($system_data, $this->base->getSystemData());
}
/**
* Tests for Drupal6SqlBase::moduleExists().
*/
public function testDrupal6ModuleExists() {
// This module should exist.
$this->assertTrue($this->base->moduleExistsWrapper('module1'));
// These modules should not exist.
$this->assertFalse($this->base->moduleExistsWrapper('module2'));
$this->assertFalse($this->base->moduleExistsWrapper('module3'));
}
/**
* Tests for Drupal6SqlBase::getModuleSchemaVersion().
*/
public function testGetModuleSchemaVersion() {
// Non-existent module.
$this->assertFalse($this->base->getModuleSchemaVersionWrapper('module3'));
// Disabled module should still return schema version.
$this->assertEquals(7201, $this->base->getModuleSchemaVersionWrapper('module2'));
// Enabled module.
$this->assertEquals(-1, $this->base->getModuleSchemaVersionWrapper('module1'));
}
/**
* Tests for Drupal6SqlBase::variableGet().
*/
public function testVariableGet() {
// Test default value.
$this->assertEquals('my_default', $this->base->variableGetWrapper('non_existent_variable', 'my_default'));
// Test non-default.
$this->assertSame(TRUE, $this->base->variableGetWrapper('my_variable', FALSE));
}
}
Dries Buytaert
committed
namespace Drupal\Tests\migrate_drupal\Unit\source\d6;
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
use Drupal\Core\Database\Connection;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Extends the Drupal6SqlBase abstract class.
*/
class TestDrupal6SqlBase extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'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.'),
);
}
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->database
->select('system', 's')
->fields('s', array('filename', 'name', 'schema_version'));
return $query;
}
/**
* Tweaks Drupal6SqlBase to set a new database connection for tests.
*
* @param \Drupal\Core\Database\Connection
Alex Pott
committed
* The new connection to use.
*
Dries Buytaert
committed
* @see \Drupal\Tests\migrate\Unit\MigrateSqlTestCase
*/
public function setDatabase(Connection $database) {
$this->database = $database;
}
/**
* Tweaks Drupal6SqlBase to set a new module handler for tests.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface
* The new module handler to use.
*
Dries Buytaert
committed
* @see \Drupal\Tests\migrate\Unit\MigrateSqlTestCase
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
*/
public function setModuleHandler(ModuleHandlerInterface $module_handler) {
$this->moduleHandler = $module_handler;
}
/**
* Wrapper method to test protected method moduleExists().
*/
public function moduleExistsWrapper($module) {
return parent::moduleExists($module);
}
/**
* Wrapper method to test protected method getModuleSchemaVersion().
*/
public function getModuleSchemaVersionWrapper($module) {
return parent::getModuleSchemaVersion($module);
}
/**
* Wrapper method to test protected method variableGet().
*/
public function variableGetWrapper($name, $default) {
return parent::variableGet($name, $default);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return array();
}
}