3 namespace Drupal\Tests\migrate_drupal\Unit\source;
5 use Drupal\Tests\migrate\Unit\MigrateTestCase;
6 use Drupal\migrate\Exception\RequirementsException;
9 * @coversDefaultClass Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
10 * @group migrate_drupal
12 class DrupalSqlBaseTest extends MigrateTestCase {
15 * Define bare minimum migration configuration.
17 protected $migrationConfiguration = [
18 'id' => 'DrupalSqlBase',
22 * @var \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
27 * Minimum database contents needed to test DrupalSqlBase.
29 protected $databaseContents = [
32 'filename' => 'sites/all/modules/module1',
36 'schema_version' => -1,
42 * @covers ::checkRequirements
44 public function testSourceProviderNotActive() {
45 $plugin_definition['requirements_met'] = TRUE;
46 $plugin_definition['source_module'] = 'module1';
47 /** @var \Drupal\Core\State\StateInterface $state */
48 $state = $this->getMock('Drupal\Core\State\StateInterface');
49 /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
50 $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
51 $plugin = new TestDrupalSqlBase([], 'placeholder_id', $plugin_definition, $this->getMigration(), $state, $entity_manager);
52 $plugin->setDatabase($this->getDatabase($this->databaseContents));
53 $system_data = $plugin->getSystemData();
54 $this->setExpectedException(RequirementsException::class, 'The module module1 is not enabled in the source site.');
56 $plugin->checkRequirements();
58 catch (RequirementsException $e) {
59 // Ensure requirements are set on the exception.
60 $this->assertEquals(['source_module' => 'module1'], $e->getRequirements());
61 // Re-throw so PHPUnit can assert the exception.
68 namespace Drupal\Tests\migrate_drupal\Unit\source;
70 use Drupal\Core\Database\Connection;
71 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
74 * Extends the DrupalSqlBase abstract class.
76 class TestDrupalSqlBase extends DrupalSqlBase {
81 public function fields() {
88 public function query() {
92 * Tweaks DrupalSqlBase to set a new database connection for tests.
94 * @param \Drupal\Core\Database\Connection $database
95 * The new connection to use.
97 * @see \Drupal\Tests\migrate\Unit\MigrateSourceSqlTestCase
99 public function setDatabase(Connection $database) {
100 $this->database = $database;
106 public function getIds() {