class Drupal6SqlBaseTest

Same name and namespace in other branches
  1. 9 core/modules/migrate_drupal/tests/src/Unit/source/d6/Drupal6SqlBaseTest.php \Drupal\Tests\migrate_drupal\Unit\source\d6\Drupal6SqlBaseTest
  2. 8.9.x core/modules/migrate_drupal/tests/src/Unit/source/d6/Drupal6SqlBaseTest.php \Drupal\Tests\migrate_drupal\Unit\source\d6\Drupal6SqlBaseTest
  3. 11.x core/modules/migrate_drupal/tests/src/Unit/source/d6/Drupal6SqlBaseTest.php \Drupal\Tests\migrate_drupal\Unit\source\d6\Drupal6SqlBaseTest

Tests the D6 SQL base class.

@group migrate_drupal

Hierarchy

Expanded class hierarchy of Drupal6SqlBaseTest

File

core/modules/migrate_drupal/tests/src/Unit/source/d6/Drupal6SqlBaseTest.php, line 16

Namespace

Drupal\Tests\migrate_drupal\Unit\source\d6
View source
class Drupal6SqlBaseTest extends MigrateTestCase {
  
  /**
   * Define bare minimum migration configuration.
   */
  protected $migrationConfiguration = [
    'id' => 'Drupal6SqlBase',
  ];
  
  /**
   * @var \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
   */
  protected $base;
  
  /**
   * Minimum database contents needed to test Drupal6SqlBase.
   */
  protected $databaseContents = [
    'system' => [
      [
        'filename' => 'sites/all/modules/module1',
        'name' => 'module1',
        'type' => 'module',
        'status' => 1,
        'schema_version' => -1,
      ],
      [
        'filename' => 'sites/all/modules/module2',
        'name' => 'module2',
        'type' => 'module',
        'status' => 0,
        'schema_version' => 7201,
      ],
      [
        'filename' => 'sites/all/modules/test2',
        'name' => 'test2',
        'type' => 'theme',
        'status' => 1,
        'schema_version' => -1,
      ],
    ],
    'variable' => [
      [
        'name' => 'my_variable',
        'value' => 'b:1;',
      ],
    ],
  ];
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $plugin = 'placeholder_id';
    /** @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->base = new TestDrupal6SqlBase($this->migrationConfiguration, $plugin, [], $this->getMigration(), $state, $entity_type_manager);
    $this->base
      ->setDatabase($this->getDatabase($this->databaseContents));
  }
  
  /**
   * Tests for Drupal6SqlBase::getSystemData().
   */
  public function testGetSystemData() : void {
    $system_data = $this->base
      ->getSystemData();
    // Should be 1 theme and 2 modules.
    $this->assertCount(1, $system_data['theme']);
    $this->assertCount(2, $system_data['module']);
    // Calling again should be identical.
    $this->assertSame($system_data, $this->base
      ->getSystemData());
  }
  
  /**
   * Tests for Drupal6SqlBase::moduleExists().
   */
  public function testDrupal6ModuleExists() : void {
    // 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() : void {
    // 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() : void {
    // Test default value.
    $this->assertEquals('my_default', $this->base
      ->variableGetWrapper('non_existent_variable', 'my_default'));
    // Test non-default.
    $this->assertTrue($this->base
      ->variableGetWrapper('my_variable', FALSE));
  }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
Drupal6SqlBaseTest::$base protected property
Drupal6SqlBaseTest::$databaseContents protected property Minimum database contents needed to test Drupal6SqlBase.
Drupal6SqlBaseTest::$migrationConfiguration protected property Define bare minimum migration configuration. Overrides MigrateTestCase::$migrationConfiguration
Drupal6SqlBaseTest::setUp protected function Overrides UnitTestCase::setUp
Drupal6SqlBaseTest::testDrupal6ModuleExists public function Tests for Drupal6SqlBase::moduleExists().
Drupal6SqlBaseTest::testGetModuleSchemaVersion public function Tests for Drupal6SqlBase::getModuleSchemaVersion().
Drupal6SqlBaseTest::testGetSystemData public function Tests for Drupal6SqlBase::getSystemData().
Drupal6SqlBaseTest::testVariableGet public function Tests for Drupal6SqlBase::variableGet().
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.
MigrateTestCase::getValue protected function Gets the value on a row for a given key.
MigrateTestCase::queryResultTest public function Tests a query.
MigrateTestCase::retrievalAssertHelper protected function Asserts tested values during test retrieval.
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
UnitTestCase::$root protected property The app root. 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::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUpBeforeClass public static function
UnitTestCase::__get public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.