You are here

public function MigrateSqlIdMapEnsureTablesTest::testEnsureTablesNotExist in Zircon Profile 8

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

Tests the ensureTables method when the tables do not exist.

File

core/modules/migrate/tests/src/Unit/MigrateSqlIdMapEnsureTablesTest.php, line 31
Contains \Drupal\Tests\migrate\Unit\MigrateSqlIdMapEnsureTablesTest.

Class

MigrateSqlIdMapEnsureTablesTest
Tests the SQL ID map plugin ensureTables() method.

Namespace

Drupal\Tests\migrate\Unit

Code

public function testEnsureTablesNotExist() {
  $fields['source_row_status'] = array(
    'type' => 'int',
    'size' => 'tiny',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => MigrateIdMapInterface::STATUS_IMPORTED,
    'description' => 'Indicates current status of the source row',
  );
  $fields['rollback_action'] = array(
    'type' => 'int',
    'size' => 'tiny',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => MigrateIdMapInterface::ROLLBACK_DELETE,
    'description' => 'Flag indicating what to do for this item on rollback',
  );
  $fields['last_imported'] = array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
    'description' => 'UNIX timestamp of the last time this row was imported',
  );
  $fields['hash'] = array(
    'type' => 'varchar',
    'length' => '64',
    'not null' => FALSE,
    'description' => 'Hash of source row data, for detecting changes',
  );
  $fields['sourceid1'] = array(
    'type' => 'int',
    'not null' => TRUE,
  );
  $fields['destid1'] = array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => FALSE,
  );
  $map_table_schema = array(
    'description' => 'Mappings from source identifier value(s) to destination identifier value(s).',
    'fields' => $fields,
    'primary key' => array(
      'sourceid1',
    ),
  );
  $schema = $this
    ->getMockBuilder('Drupal\\Core\\Database\\Schema')
    ->disableOriginalConstructor()
    ->getMock();
  $schema
    ->expects($this
    ->at(0))
    ->method('tableExists')
    ->with('migrate_map_sql_idmap_test')
    ->will($this
    ->returnValue(FALSE));
  $schema
    ->expects($this
    ->at(1))
    ->method('createTable')
    ->with('migrate_map_sql_idmap_test', $map_table_schema);

  // Now do the message table.
  $fields = array();
  $fields['msgid'] = array(
    'type' => 'serial',
    'unsigned' => TRUE,
    'not null' => TRUE,
  );
  $fields['sourceid1'] = array(
    'type' => 'int',
    'not null' => TRUE,
  );
  $fields['level'] = array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 1,
  );
  $fields['message'] = array(
    'type' => 'text',
    'size' => 'medium',
    'not null' => TRUE,
  );
  $table_schema = array(
    'description' => 'Messages generated during a migration process',
    'fields' => $fields,
    'primary key' => array(
      'msgid',
    ),
  );
  $table_schema['indexes']['sourcekey'] = array(
    'sourceid1',
  );
  $schema
    ->expects($this
    ->at(2))
    ->method('tableExists')
    ->with('migrate_message_sql_idmap_test')
    ->will($this
    ->returnValue(FALSE));
  $schema
    ->expects($this
    ->at(3))
    ->method('createTable')
    ->with('migrate_message_sql_idmap_test', $table_schema);
  $schema
    ->expects($this
    ->any())
    ->method($this
    ->anything());
  $this
    ->runEnsureTablesTest($schema);
}