function SettingsTest::testCredentialForm

Same name in other branches
  1. 9 core/modules/migrate_drupal_ui/tests/src/FunctionalJavascript/SettingsTest.php \Drupal\Tests\migrate_drupal_ui\FunctionalJavascript\SettingsTest::testCredentialForm()
  2. 11.x core/modules/migrate_drupal_ui/tests/src/FunctionalJavascript/SettingsTest.php \Drupal\Tests\migrate_drupal_ui\FunctionalJavascript\SettingsTest::testCredentialForm()

Test the Credential form with defaults in settings.php.

@dataProvider providerTestCredentialForm

Parameters

string|null $source_connection: The value for the source_connection select field.

string $version: The legacy Drupal version.

string[] $manual: User entered form values.

string[] $databases: Databases data or the settings array.

string $expected_source_connection: The expected source database connection key.

Throws

\Behat\Mink\Exception\ElementNotFoundException

\Behat\Mink\Exception\ExpectationException

File

core/modules/migrate_drupal_ui/tests/src/FunctionalJavascript/SettingsTest.php, line 61

Class

SettingsTest
Tests migrate upgrade credential form with settings in settings.php.

Namespace

Drupal\Tests\migrate_drupal_ui\FunctionalJavascript

Code

public function testCredentialForm($source_connection, $version, array $manual, array $databases, $expected_source_connection) : void {
    // Write settings.
    $migrate_file_public_path = '/var/www/drupal7/sites/default/files';
    $migrate_file_private_path = '/var/www/drupal7/sites/default/files/private';
    $settings['settings']['migrate_source_version'] = (object) [
        'value' => $version,
        'required' => TRUE,
    ];
    $settings['settings']['migrate_source_connection'] = (object) [
        'value' => $source_connection,
        'required' => TRUE,
    ];
    $settings['settings']['migrate_file_public_path'] = (object) [
        'value' => $migrate_file_public_path,
        'required' => TRUE,
    ];
    $settings['settings']['migrate_file_private_path'] = (object) [
        'value' => $migrate_file_private_path,
        'required' => TRUE,
    ];
    foreach ($databases as $key => $value) {
        $settings['databases'][$key]['default'] = (object) [
            'value' => $value['default'],
            'required' => TRUE,
        ];
    }
    $this->writeSettings($settings);
    $edits = [];
    // Enter the values manually if provided.
    if (!empty($manual)) {
        $edit = [];
        $driver = 'Drupal\\mysql\\Driver\\Database\\mysql';
        $edit[$driver]['host'] = $manual['host'];
        $edit[$driver]['database'] = $manual['database'];
        $edit[$driver]['username'] = $manual['username'];
        $edit[$driver]['password'] = $manual['password'];
        $edits = $this->translatePostValues($edit);
    }
    // Start the upgrade process.
    $this->drupalGet('/upgrade');
    $this->submitForm([], 'Continue');
    $session = $this->assertSession();
    // The source connection field is only displayed when there are connections
    // other than default.
    if (empty($databases)) {
        $session->fieldNotExists('source_connection');
    }
    else {
        $session->fieldExists('source_connection');
    }
    // Submit the Credential form.
    $this->submitForm($edits, 'Review upgrade');
    // Confirm that the form actually submitted. IF it submitted, we should see
    // error messages about reading files. If there is no error message, that
    // indicates that the form did not submit.
    $session->responseContains('Failed to read from Document root');
    // Assert the form values.
    $session->fieldValueEquals('version', $version);
    // Check the manually entered credentials or simply the database key.
    if (empty($manual)) {
        $session->fieldValueEquals('source_connection', $expected_source_connection);
    }
    else {
        $session->fieldValueEquals('edit-drupalmysqldriverdatabasemysql-host', $manual['host']);
        $session->fieldValueEquals('edit-drupalmysqldriverdatabasemysql-database', $manual['database']);
        $session->fieldValueEquals('edit-drupalmysqldriverdatabasemysql-username', $manual['username']);
    }
    // Confirm the file paths are correct.
    $session->fieldValueEquals('d6_source_base_path', $migrate_file_public_path);
    $session->fieldValueEquals('source_base_path', $migrate_file_public_path);
    $session->fieldValueEquals('source_private_file_path', $migrate_file_private_path);
}

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