class Drupal6SqlBaseTest

Same name 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. 10 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 17

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

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. 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.

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