Loading core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php +39 −28 Original line number Diff line number Diff line Loading @@ -2,11 +2,13 @@ namespace Drupal\Tests\migrate_drupal\Unit\source; use Drupal\Core\Database\Connection; use Drupal\Tests\migrate\Unit\MigrateTestCase; use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; /** * @coversDefaultClass Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase * @coversDefaultClass \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase * @group migrate_drupal */ class DrupalSqlBaseTest extends MigrateTestCase { Loading @@ -23,6 +25,27 @@ class DrupalSqlBaseTest extends MigrateTestCase { */ protected $base; /** * The plugin definition. * * @var array */ protected $pluginDefinition = []; /** * Mock StateInterface. * * @var \PHPUnit\Framework\MockObject\MockObject */ protected $state; /** * Mock entity type manager. * * @var \PHPUnit\Framework\MockObject\MockObject */ protected $entityTypeManager; /** * Minimum database contents needed to test DrupalSqlBase. */ Loading @@ -38,17 +61,22 @@ class DrupalSqlBaseTest extends MigrateTestCase { ], ]; /** * {@inheritdoc} */ public function setUp(): void { parent::setUp(); $this->pluginDefinition['requirements_met'] = TRUE; $this->pluginDefinition['source_module'] = 'module1'; $this->state = $this->createMock('Drupal\Core\State\StateInterface'); $this->entityTypeManager = $this->createMock('Drupal\Core\Entity\EntityTypeManagerInterface'); } /** * @covers ::checkRequirements */ public function testSourceProviderNotActive() { $plugin_definition['requirements_met'] = TRUE; $plugin_definition['source_module'] = 'module1'; /** @var \Drupal\Core\State\StateInterface $state */ $state = $this->createMock('Drupal\Core\State\StateInterface'); /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ $entity_type_manager = $this->createMock('Drupal\Core\Entity\EntityTypeManagerInterface'); $plugin = new TestDrupalSqlBase([], 'placeholder_id', $plugin_definition, $this->getMigration(), $state, $entity_type_manager); $plugin = new TestDrupalSqlBase([], 'placeholder_id', $this->pluginDefinition, $this->getMigration(), $this->state, $this->entityTypeManager); $plugin->setDatabase($this->getDatabase($this->databaseContents)); $this->expectException(RequirementsException::class); $this->expectExceptionMessage('The module module1 is not enabled in the source site.'); Loading @@ -67,13 +95,7 @@ public function testSourceProviderNotActive() { * @covers ::checkRequirements */ public function testSourceDatabaseError() { $plugin_definition['requirements_met'] = TRUE; $plugin_definition['source_module'] = 'module1'; /** @var \Drupal\Core\State\StateInterface $state */ $state = $this->createMock('Drupal\Core\State\StateInterface'); /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ $entity_type_manager = $this->createMock('Drupal\Core\Entity\EntityTypeManagerInterface'); $plugin = new TestDrupalSqlBase([], 'test', $plugin_definition, $this->getMigration(), $state, $entity_type_manager); $plugin = new TestDrupalSqlBase([], 'test', $this->pluginDefinition, $this->getMigration(), $this->state, $this->entityTypeManager); $this->expectException(RequirementsException::class); $this->expectExceptionMessage('No database connection configured for source plugin test'); $plugin->checkRequirements(); Loading @@ -92,16 +114,10 @@ public function testSourceDatabaseError() { * @dataProvider providerMinimumVersion */ public function testMinimumVersion($success, $minimum_version, $schema_version) { $plugin_definition['requirements_met'] = TRUE; $plugin_definition['source_module'] = 'module1'; $plugin_definition['minimum_version'] = $minimum_version; /** @var \Drupal\Core\State\StateInterface $state */ $state = $this->createMock('Drupal\Core\State\StateInterface'); /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ $entity_type_manager = $this->createMock('Drupal\Core\Entity\EntityTypeManagerInterface'); $this->pluginDefinition['minimum_version'] = $minimum_version; $this->databaseContents['system'][0]['status'] = 1; $this->databaseContents['system'][0]['schema_version'] = $schema_version; $plugin = new TestDrupalSqlBase([], 'test', $plugin_definition, $this->getMigration(), $state, $entity_type_manager); $plugin = new TestDrupalSqlBase([], 'test', $this->pluginDefinition, $this->getMigration(), $this->state, $this->entityTypeManager); $plugin->setDatabase($this->getDatabase($this->databaseContents)); if (!$success) { Loading Loading @@ -152,11 +168,6 @@ public function providerMinimumVersion() { } namespace Drupal\Tests\migrate_drupal\Unit\source; use Drupal\Core\Database\Connection; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; /** * Extends the DrupalSqlBase abstract class. */ Loading Loading
core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php +39 −28 Original line number Diff line number Diff line Loading @@ -2,11 +2,13 @@ namespace Drupal\Tests\migrate_drupal\Unit\source; use Drupal\Core\Database\Connection; use Drupal\Tests\migrate\Unit\MigrateTestCase; use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; /** * @coversDefaultClass Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase * @coversDefaultClass \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase * @group migrate_drupal */ class DrupalSqlBaseTest extends MigrateTestCase { Loading @@ -23,6 +25,27 @@ class DrupalSqlBaseTest extends MigrateTestCase { */ protected $base; /** * The plugin definition. * * @var array */ protected $pluginDefinition = []; /** * Mock StateInterface. * * @var \PHPUnit\Framework\MockObject\MockObject */ protected $state; /** * Mock entity type manager. * * @var \PHPUnit\Framework\MockObject\MockObject */ protected $entityTypeManager; /** * Minimum database contents needed to test DrupalSqlBase. */ Loading @@ -38,17 +61,22 @@ class DrupalSqlBaseTest extends MigrateTestCase { ], ]; /** * {@inheritdoc} */ public function setUp(): void { parent::setUp(); $this->pluginDefinition['requirements_met'] = TRUE; $this->pluginDefinition['source_module'] = 'module1'; $this->state = $this->createMock('Drupal\Core\State\StateInterface'); $this->entityTypeManager = $this->createMock('Drupal\Core\Entity\EntityTypeManagerInterface'); } /** * @covers ::checkRequirements */ public function testSourceProviderNotActive() { $plugin_definition['requirements_met'] = TRUE; $plugin_definition['source_module'] = 'module1'; /** @var \Drupal\Core\State\StateInterface $state */ $state = $this->createMock('Drupal\Core\State\StateInterface'); /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ $entity_type_manager = $this->createMock('Drupal\Core\Entity\EntityTypeManagerInterface'); $plugin = new TestDrupalSqlBase([], 'placeholder_id', $plugin_definition, $this->getMigration(), $state, $entity_type_manager); $plugin = new TestDrupalSqlBase([], 'placeholder_id', $this->pluginDefinition, $this->getMigration(), $this->state, $this->entityTypeManager); $plugin->setDatabase($this->getDatabase($this->databaseContents)); $this->expectException(RequirementsException::class); $this->expectExceptionMessage('The module module1 is not enabled in the source site.'); Loading @@ -67,13 +95,7 @@ public function testSourceProviderNotActive() { * @covers ::checkRequirements */ public function testSourceDatabaseError() { $plugin_definition['requirements_met'] = TRUE; $plugin_definition['source_module'] = 'module1'; /** @var \Drupal\Core\State\StateInterface $state */ $state = $this->createMock('Drupal\Core\State\StateInterface'); /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ $entity_type_manager = $this->createMock('Drupal\Core\Entity\EntityTypeManagerInterface'); $plugin = new TestDrupalSqlBase([], 'test', $plugin_definition, $this->getMigration(), $state, $entity_type_manager); $plugin = new TestDrupalSqlBase([], 'test', $this->pluginDefinition, $this->getMigration(), $this->state, $this->entityTypeManager); $this->expectException(RequirementsException::class); $this->expectExceptionMessage('No database connection configured for source plugin test'); $plugin->checkRequirements(); Loading @@ -92,16 +114,10 @@ public function testSourceDatabaseError() { * @dataProvider providerMinimumVersion */ public function testMinimumVersion($success, $minimum_version, $schema_version) { $plugin_definition['requirements_met'] = TRUE; $plugin_definition['source_module'] = 'module1'; $plugin_definition['minimum_version'] = $minimum_version; /** @var \Drupal\Core\State\StateInterface $state */ $state = $this->createMock('Drupal\Core\State\StateInterface'); /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ $entity_type_manager = $this->createMock('Drupal\Core\Entity\EntityTypeManagerInterface'); $this->pluginDefinition['minimum_version'] = $minimum_version; $this->databaseContents['system'][0]['status'] = 1; $this->databaseContents['system'][0]['schema_version'] = $schema_version; $plugin = new TestDrupalSqlBase([], 'test', $plugin_definition, $this->getMigration(), $state, $entity_type_manager); $plugin = new TestDrupalSqlBase([], 'test', $this->pluginDefinition, $this->getMigration(), $this->state, $this->entityTypeManager); $plugin->setDatabase($this->getDatabase($this->databaseContents)); if (!$success) { Loading Loading @@ -152,11 +168,6 @@ public function providerMinimumVersion() { } namespace Drupal\Tests\migrate_drupal\Unit\source; use Drupal\Core\Database\Connection; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; /** * Extends the DrupalSqlBase abstract class. */ Loading