You are here

class Drupal6SqlBaseTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 17
Contains \Drupal\Tests\migrate_drupal\Unit\source\d6\Drupal6SqlBaseTest.

Namespace

Drupal\Tests\migrate_drupal\Unit\source\d6
View source
class Drupal6SqlBaseTest extends MigrateTestCase {

  /**
   * Define bare minimum migration configuration.
   */
  protected $migrationConfiguration = array(
    'id' => 'Drupal6SqlBase',
  );

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

  /**
   * Minimum database contents needed to test Drupal6SqlBase.
   */
  protected $databaseContents = array(
    'system' => array(
      array(
        'filename' => 'sites/all/modules/module1',
        'name' => 'module1',
        'type' => 'module',
        'status' => 1,
        'schema_version' => -1,
      ),
      array(
        'filename' => 'sites/all/modules/module2',
        'name' => 'module2',
        'type' => 'module',
        'status' => 0,
        'schema_version' => 7201,
      ),
      array(
        'filename' => 'sites/all/modules/test2',
        'name' => 'test2',
        'type' => 'theme',
        'status' => 1,
        'schema_version' => -1,
      ),
    ),
    'variable' => array(
      array(
        'name' => 'my_variable',
        'value' => 'b:1;',
      ),
    ),
  );

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    $plugin = 'placeholder_id';

    /** @var \Drupal\Core\State\StateInterface $state */
    $state = $this
      ->getMock('Drupal\\Core\\State\\StateInterface');

    /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
    $entity_manager = $this
      ->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
    $this->base = new TestDrupal6SqlBase($this->migrationConfiguration, $plugin, array(), $this
      ->getMigration(), $state, $entity_manager);
    $this->base
      ->setDatabase($this
      ->getDatabase($this->databaseContents));
  }

  /**
   * Tests for Drupal6SqlBase::getSystemData().
   */
  public function testGetSystemData() {
    $system_data = $this->base
      ->getSystemData();

    // Should be 1 theme and 2 modules.
    $this
      ->assertEquals(1, count($system_data['theme']));
    $this
      ->assertEquals(2, count($system_data['module']));

    // Calling again should be identical.
    $this
      ->assertSame($system_data, $this->base
      ->getSystemData());
  }

  /**
   * Tests for Drupal6SqlBase::moduleExists().
   */
  public function testDrupal6ModuleExists() {

    // 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() {

    // 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() {

    // Test default value.
    $this
      ->assertEquals('my_default', $this->base
      ->variableGetWrapper('non_existent_variable', 'my_default'));

    // Test non-default.
    $this
      ->assertSame(TRUE, $this->base
      ->variableGetWrapper('my_variable', FALSE));
  }

}

Members

Namesort descending Modifiers Type Description 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
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 Get an SQLite database connection object for use in tests.
MigrateTestCase::getMigration protected function Retrieve a mocked migration.
MigrateTestCase::getValue protected function 1
MigrateTestCase::queryResultTest public function Tests a query
MigrateTestCase::retrievalAssertHelper protected function Asserts tested values during test retrieval.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root.
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName protected function Mocks a block with a block plugin.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in 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.