You are here

class DrupalSqlBaseTest in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php \Drupal\Tests\migrate_drupal\Unit\source\DrupalSqlBaseTest
  2. 10 core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php \Drupal\Tests\migrate_drupal\Unit\source\DrupalSqlBaseTest

@coversDefaultClass Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase @group migrate_drupal

Hierarchy

Expanded class hierarchy of DrupalSqlBaseTest

File

core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php, line 12

Namespace

Drupal\Tests\migrate_drupal\Unit\source
View source
class DrupalSqlBaseTest extends MigrateTestCase {

  /**
   * Define bare minimum migration configuration.
   */
  protected $migrationConfiguration = [
    'id' => 'DrupalSqlBase',
  ];

  /**
   * @var \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
   */
  protected $base;

  /**
   * Minimum database contents needed to test DrupalSqlBase.
   */
  protected $databaseContents = [
    'system' => [
      [
        'filename' => 'sites/all/modules/module1',
        'name' => 'module1',
        'type' => 'module',
        'status' => 0,
        'schema_version' => -1,
      ],
    ],
  ];

  /**
   * @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
      ->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) {

      // Ensure requirements are set on the exception.
      $this
        ->assertEquals([
        'source_module' => 'module1',
      ], $e
        ->getRequirements());

      // Re-throw so PHPUnit can assert the exception.
      throw $e;
    }
  }

  /**
   * @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_manager */
    $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();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalSqlBaseTest::$base protected property
DrupalSqlBaseTest::$databaseContents protected property Minimum database contents needed to test DrupalSqlBase.
DrupalSqlBaseTest::$migrationConfiguration protected property Define bare minimum migration configuration. Overrides MigrateTestCase::$migrationConfiguration
DrupalSqlBaseTest::testSourceDatabaseError public function @covers ::checkRequirements
DrupalSqlBaseTest::testSourceProviderNotActive public function @covers ::checkRequirements
MigrateTestCase::$idMap protected property The migration ID map.
MigrateTestCase::$migrationStatus protected property Local store for mocking setStatus()/getStatus().
MigrateTestCase::createSchemaFromRow protected function Generates a table schema from a row.
MigrateTestCase::getDatabase protected function Gets an SQLite database connection object for use in tests.
MigrateTestCase::getMigration protected function Retrieves a mocked migration. 1
MigrateTestCase::getValue protected function Gets the value on a row for a given key. 1
MigrateTestCase::queryResultTest public function Tests a query.
MigrateTestCase::retrievalAssertHelper protected function Asserts tested values during test retrieval.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340