DrupalSqlBaseTest.php in Drupal 8
File
core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php
View source
<?php
namespace Drupal\Tests\migrate_drupal\Unit\source;
use Drupal\Tests\migrate\Unit\MigrateTestCase;
use Drupal\migrate\Exception\RequirementsException;
class DrupalSqlBaseTest extends MigrateTestCase {
protected $migrationConfiguration = [
'id' => 'DrupalSqlBase',
];
protected $base;
protected $databaseContents = [
'system' => [
[
'filename' => 'sites/all/modules/module1',
'name' => 'module1',
'type' => 'module',
'status' => 0,
'schema_version' => -1,
],
],
];
public function testSourceProviderNotActive() {
$plugin_definition['requirements_met'] = TRUE;
$plugin_definition['source_module'] = 'module1';
$state = $this
->createMock('Drupal\\Core\\State\\StateInterface');
$entity_type_manager = $this
->createMock('Drupal\\Core\\Entity\\EntityTypeManagerInterface');
$plugin = new TestDrupalSqlBase([], 'placeholder_id', $plugin_definition, $this
->getMigration(), $state, $entity_type_manager);
$plugin
->setDatabase($this
->getDatabase($this->databaseContents));
$system_data = $plugin
->getSystemData();
$this
->expectException(RequirementsException::class);
$this
->expectExceptionMessage('The module module1 is not enabled in the source site.');
try {
$plugin
->checkRequirements();
} catch (RequirementsException $e) {
$this
->assertEquals([
'source_module' => 'module1',
], $e
->getRequirements());
throw $e;
}
}
public function testSourceDatabaseError() {
$plugin_definition['requirements_met'] = TRUE;
$plugin_definition['source_module'] = 'module1';
$state = $this
->createMock('Drupal\\Core\\State\\StateInterface');
$entity_manager = $this
->createMock('Drupal\\Core\\Entity\\EntityTypeManagerInterface');
$plugin = new TestDrupalSqlBase([], 'test', $plugin_definition, $this
->getMigration(), $state, $entity_manager);
$system_data = $plugin
->getSystemData();
$this
->expectException(RequirementsException::class);
$this
->expectExceptionMessage('No database connection configured for source plugin test');
$plugin
->checkRequirements();
}
}
namespace Drupal\Tests\migrate_drupal\Unit\source;
use Drupal\Core\Database\Connection;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
class TestDrupalSqlBase extends DrupalSqlBase {
public function fields() {
return [];
}
public function query() {
}
public function setDatabase(Connection $database) {
$this->database = $database;
}
public function getIds() {
return [];
}
}