Commit 1e03b1c6 authored by catch's avatar catch

Issue #3143720 by quietone, ayushmishra206, Spokje, sarvjeetsingh, mikelutz,...

Issue #3143720 by quietone, ayushmishra206, Spokje, sarvjeetsingh, mikelutz, benjifisher: Create a separate CredentialFormTest
parent bee8afa8
<?php
namespace Drupal\Tests\migrate_drupal_ui\Functional;
use Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait;
/**
* Test the credential form for both Drupal 6 and Drupal 7 sources.
*
* The credential form is tested with incorrect credentials, correct
* credentials, and incorrect file paths.
*
* @group migrate_drupal_ui
*/
class CredentialFormTest extends MigrateUpgradeTestBase {
use CreateTestContentEntitiesTrait;
/**
* {@inheritdoc}
*/
protected static $modules = ['migrate_drupal_ui'];
/**
* Test the credential form.
*
* @dataProvider providerCredentialForm
*/
public function testCredentialFrom($path_to_database) {
$this->loadFixture(drupal_get_path('module', 'migrate_drupal') . $path_to_database);
$session = $this->assertSession();
// Get valid credentials.
$edit = $this->getCredentials();
$version = $edit['version'];
$edits = $this->translatePostValues($edit);
$this->drupalGet('/upgrade');
$session->responseContains("Upgrade a site by importing its files and the data from its database into a clean and empty new install of Drupal $this->destinationSiteVersion.");
$this->drupalPostForm(NULL, [], 'Continue');
$session->pageTextContains('Provide credentials for the database of the Drupal site you want to upgrade.');
$session->fieldExists('mysql[host]');
// Ensure submitting the form with invalid database credentials gives us a
// nice warning.
$this->drupalPostForm(NULL, [$edit['driver'] . '[database]' => 'wrong'] + $edits, 'Review upgrade');
$session->pageTextContains('Resolve all issues below to continue the upgrade.');
// Resubmit with correct credentials.
$this->drupalPostForm(NULL, $edits, 'Review upgrade');
$this->drupalPostForm(NULL, [], 'I acknowledge I may lose data. Continue anyway.');
$session->statusCodeEquals(200);
// Restart the upgrade and test the file source paths.
$this->drupalGet('/upgrade');
$this->drupalPostForm(NULL, [], 'Continue');
if ($version == 6) {
$paths['d6_source_base_path'] = DRUPAL_ROOT . '/wrong-path';
}
else {
$paths['source_base_path'] = 'https://example.com/wrong-path';
$paths['source_private_file_path'] = DRUPAL_ROOT . '/wrong-path';
}
$this->drupalPostForm(NULL, $paths + $edits, 'Review upgrade');
if ($version == 6) {
$session->responseContains('Failed to read from Document root for files.');
}
else {
$session->responseContains('Failed to read from Document root for public files.');
$session->responseContains('Failed to read from Document root for private files.');
}
}
/**
* Data provider for testCredentialForm.
*/
public function providerCredentialForm() {
return [
[
'path_to_database' => '/tests/fixtures/drupal6.php',
],
[
'path_to_database' => '/tests/fixtures/drupal7.php',
],
];
}
/**
* {@inheritdoc}
*/
protected function getSourceBasePath() {
$version = $this->getLegacyDrupalVersion($this->sourceDatabase);
return __DIR__ . '/d' . $version . '/files';
}
/**
* {@inheritdoc}
*/
protected function getAvailablePaths() {
return [];
}
/**
* {@inheritdoc}
*/
protected function getEntityCounts() {
return [];
}
/**
* {@inheritdoc}
*/
protected function getEntityCountsIncremental() {
return [];
}
/**
* {@inheritdoc}
*/
protected function getMissingPaths() {
return [];
}
}
......@@ -32,7 +32,6 @@ protected function setUp() {
* and assert the results.
*/
public function testMigrateUpgradeExecute() {
$connection_options = $this->sourceDatabase->getConnectionOptions();
$this->drupalGet('/upgrade');
$session = $this->assertSession();
$session->responseContains("Upgrade a site by importing its files and the data from its database into a clean and empty new install of Drupal $this->destinationSiteVersion.");
......@@ -40,38 +39,12 @@ public function testMigrateUpgradeExecute() {
$this->drupalPostForm(NULL, [], t('Continue'));
$session->pageTextContains('Provide credentials for the database of the Drupal site you want to upgrade.');
$session->fieldExists('mysql[host]');
$driver = $connection_options['driver'];
// Get valid credentials.
$edits = $this->translatePostValues($this->getCredentials());
// Ensure submitting the form with invalid database credentials gives us a
// nice warning.
$this->drupalPostForm(NULL, [$driver . '[database]' => 'wrong'] + $edits, t('Review upgrade'));
$session->pageTextContains('Resolve all issues below to continue the upgrade.');
$this->drupalPostForm(NULL, $edits, t('Review upgrade'));
// Test the file sources.
$this->drupalGet('/upgrade');
$this->drupalPostForm(NULL, [], t('Continue'));
$version = $this->getLegacyDrupalVersion($this->sourceDatabase);
if ($version == 6) {
$paths['d6_source_base_path'] = DRUPAL_ROOT . '/wrong-path';
}
else {
$paths['source_base_path'] = 'https://example.com/wrong-path';
$paths['source_private_file_path'] = DRUPAL_ROOT . '/wrong-path';
}
$this->drupalPostForm(NULL, $paths + $edits, t('Review upgrade'));
if ($version == 6) {
$session->responseContains('Failed to read from Document root for files.');
}
else {
$session->responseContains('Failed to read from Document root for public files.');
$session->responseContains('Failed to read from Document root for private files.');
}
// Restart the upgrade process.
$this->drupalGet('/upgrade');
$session->responseContains("Upgrade a site by importing its files and the data from its database into a clean and empty new install of Drupal $this->destinationSiteVersion.");
......@@ -103,7 +76,7 @@ public function testMigrateUpgradeExecute() {
$this->assertReviewForm();
$this->drupalPostForm(NULL, [], t('Perform upgrade'));
$this->assertUpgrade($version, $this->getEntityCounts());
$this->assertUpgrade($this->getEntityCounts());
\Drupal::service('module_installer')->install(['forum']);
\Drupal::service('module_installer')->install(['book']);
......@@ -126,7 +99,7 @@ public function testMigrateUpgradeExecute() {
// Run the incremental migration and check the results.
$this->drupalPostForm(NULL, [], t('Perform upgrade'));
$this->assertUpgrade($version, $this->getEntityCountsIncremental());
$this->assertUpgrade($this->getEntityCountsIncremental());
}
}
......@@ -210,15 +210,13 @@ protected function assertReviewForm(array $available_paths = NULL, array $missin
/**
* Asserts the upgrade completed successfully.
*
* @param string $version
* The legacy Drupal version.
* @param array $entity_counts
* An array of entity count, where the key is the entity type and the value
* is the number of the entities that should exist post migration.
*
* @throws \Behat\Mink\Exception\ExpectationException
*/
protected function assertUpgrade($version, array $entity_counts) {
protected function assertUpgrade(array $entity_counts) {
$session = $this->assertSession();
$session->pageTextContains(t('Congratulations, you upgraded Drupal!'));
......@@ -241,6 +239,7 @@ protected function assertUpgrade($version, array $entity_counts) {
}
$plugin_manager = \Drupal::service('plugin.manager.migration');
$version = $this->getLegacyDrupalVersion($this->sourceDatabase);
/** @var \Drupal\migrate\Plugin\Migration[] $all_migrations */
$all_migrations = $plugin_manager->createInstancesByTag('Drupal ' . $version);
foreach ($all_migrations as $migration) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment