Commit 32d88bfa authored by catch's avatar catch

Issue #3151732 by quietone, benjifisher: DrupalSqlBase::checkRequirements...

Issue #3151732 by quietone, benjifisher: DrupalSqlBase::checkRequirements should test version with $minimum_version
parent c2e91dcc
......@@ -105,8 +105,12 @@ public function checkRequirements() {
if ($this->pluginDefinition['requirements_met'] === TRUE) {
if (isset($this->pluginDefinition['source_module'])) {
if ($this->moduleExists($this->pluginDefinition['source_module'])) {
if (isset($this->pluginDefinition['minimum_schema_version']) && !$this->getModuleSchemaVersion($this->pluginDefinition['source_module']) < $this->pluginDefinition['minimum_schema_version']) {
throw new RequirementsException('Required minimum schema version ' . $this->pluginDefinition['minimum_schema_version'], ['minimum_schema_version' => $this->pluginDefinition['minimum_schema_version']]);
if (isset($this->pluginDefinition['minimum_version'])) {
$minimum_version = $this->pluginDefinition['minimum_version'];
$installed_version = $this->getModuleSchemaVersion($this->pluginDefinition['source_module']);
if ($minimum_version > $installed_version) {
throw new RequirementsException('Required minimum version ' . $this->pluginDefinition['minimum_version'], ['minimum_version' => $this->pluginDefinition['minimum_version']]);
}
}
}
else {
......
......@@ -79,6 +79,77 @@ public function testSourceDatabaseError() {
$plugin->checkRequirements();
}
/**
* @covers ::checkRequirements
*
* @param bool $success
* True if this test will not throw an exception.
* @param null|string $minimum_version
* The minimum version declared in the configuration of a source plugin.
* @param string $schema_version
* The schema version for the source module declared in a source plugin.
*
* @dataProvider providerMinimumVersion
*/
public function testMinimumVersion($success, $minimum_version, $schema_version) {
$plugin_definition['requirements_met'] = TRUE;
$plugin_definition['source_module'] = 'module1';
$plugin_definition['minimum_version'] = $minimum_version;
/** @var \Drupal\Core\State\StateInterface $state */
$state = $this->createMock('Drupal\Core\State\StateInterface');
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
$entity_type_manager = $this->createMock('Drupal\Core\Entity\EntityTypeManagerInterface');
$this->databaseContents['system'][0]['status'] = 1;
$this->databaseContents['system'][0]['schema_version'] = $schema_version;
$plugin = new TestDrupalSqlBase([], 'test', $plugin_definition, $this->getMigration(), $state, $entity_type_manager);
$plugin->setDatabase($this->getDatabase($this->databaseContents));
if (!$success) {
$this->expectException(RequirementsException::class);
$this->expectExceptionMessage("Required minimum version $minimum_version");
}
$plugin->checkRequirements();
}
/**
* Provides data for testMinimumVersion.
*/
public function providerMinimumVersion() {
return [
'minimum less than schema' => [
TRUE,
'7000',
'7001',
],
'same version' => [
TRUE,
'7001',
'7001',
],
'minimum greater than schema' => [
FALSE,
'7005',
'7001',
],
'schema version 0' => [
FALSE,
'7000',
'0',
],
'schema version -1' => [
FALSE,
'7000',
'-1',
],
'minimum not set' => [
TRUE,
NULL,
'-1',
],
];
}
}
namespace Drupal\Tests\migrate_drupal\Unit\source;
......
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