Issue #3081123 by quietone, alexpott: Add checkrequirements to VariableTranslation source plugin

(cherry picked from commit de2072c9fa)
merge-requests/64/head
Alex Pott 2019-10-25 23:20:56 +01:00
parent a6f060af0d
commit c792c0421d
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
2 changed files with 50 additions and 1 deletions

View File

@ -4,6 +4,7 @@ namespace Drupal\migrate_drupal\Plugin\migrate\source\d6;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
@ -12,7 +13,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
*
* @MigrateSource(
* id = "d6_variable_translation",
* source_module = "system",
* source_module = "i18n",
* )
*/
class VariableTranslation extends DrupalSqlBase {
@ -98,4 +99,14 @@ class VariableTranslation extends DrupalSqlBase {
return $ids;
}
/**
* {@inheritdoc}
*/
public function checkRequirements() {
if (!$this->getDatabase()->schema()->tableExists('i18n_variable')) {
throw new RequirementsException("Source database table 'i18n_variable' does not exist");
}
parent::checkRequirements();
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace Drupal\Tests\migrate_drupal\Kernel\d6;
use Drupal\migrate\Exception\RequirementsException;
/**
* Tests check requirements for variable translation source plugin.
*
* @group migrate_drupal
*/
class VariableTranslationCheckRequirementsTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['config_translation'];
/**
* {@inheritdoc}
*/
public function setup() {
parent::setUp();
$this->sourceDatabase->schema()->dropTable('i18n_variable');
}
/**
* Tests exception in thrown when the i18n_variable table does not exist.
*/
public function testCheckRequirements() {
$this->expectException(RequirementsException::class);
$this->expectExceptionMessage("Source database table 'i18n_variable' does not exist");
$this->getMigration('d6_system_maintenance_translation')
->getSourcePlugin()
->checkRequirements();
}
}