You are here

public function SqlBaseTest::testMapJoinable in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/migrate/tests/src/Unit/SqlBaseTest.php \Drupal\Tests\migrate\Unit\SqlBaseTest::testMapJoinable()

@dataProvider sqlBaseTestProvider

Parameters

bool $expected_result: The expected result.

bool $id_map_is_sql: TRUE if we want getIdMap() to return an instance of Sql.

bool $with_id_map: TRUE if we want the id map to have a valid map of ids.

array $source_options: An array of connection options for the source connection.

array $idmap_options: An array of connection options for the id map connection.

File

core/modules/migrate/tests/src/Unit/SqlBaseTest.php, line 34
Contains \Drupal\Tests\migrate\Unit\SqlBaseTest.

Class

SqlBaseTest
Tests the SqlBase class.

Namespace

Drupal\Tests\migrate\Unit

Code

public function testMapJoinable($expected_result, $id_map_is_sql, $with_id_map, $source_options = [], $idmap_options = []) {

  // Setup a connection object.
  $source_connection = $this
    ->getMockBuilder('Drupal\\Core\\Database\\Connection')
    ->disableOriginalConstructor()
    ->getMock();
  $source_connection
    ->expects($id_map_is_sql && $with_id_map ? $this
    ->once() : $this
    ->never())
    ->method('getConnectionOptions')
    ->willReturn($source_options);

  // Setup the id map connection.
  $idmap_connection = $this
    ->getMockBuilder('Drupal\\Core\\Database\\Connection')
    ->disableOriginalConstructor()
    ->getMock();
  $idmap_connection
    ->expects($id_map_is_sql && $with_id_map ? $this
    ->once() : $this
    ->never())
    ->method('getConnectionOptions')
    ->willReturn($idmap_options);

  // Setup the Sql object.
  $sql = $this
    ->getMockBuilder('Drupal\\migrate\\Plugin\\migrate\\id_map\\Sql')
    ->disableOriginalConstructor()
    ->getMock();
  $sql
    ->expects($id_map_is_sql && $with_id_map ? $this
    ->once() : $this
    ->never())
    ->method('getDatabase')
    ->willReturn($idmap_connection);

  // Setup a migration entity.
  $migration = $this
    ->getMock('Drupal\\migrate\\Entity\\MigrationInterface');
  $migration
    ->expects($with_id_map ? $this
    ->once() : $this
    ->never())
    ->method('getIdMap')
    ->willReturn($id_map_is_sql ? $sql : NULL);

  // Create our SqlBase test class.
  $sql_base = new TestSqlBase();
  $sql_base
    ->setMigration($migration);
  $sql_base
    ->setDatabase($source_connection);

  // Configure the idMap to make the check in mapJoinable() pass.
  if ($with_id_map) {
    $sql_base
      ->setIds([
      'uid' => [
        'type' => 'integer',
        'alias' => 'u',
      ],
    ]);
  }
  $this
    ->assertEquals($expected_result, $sql_base
    ->mapJoinable());
}