Skip to content
Snippets Groups Projects
Commit ac584f1f authored by catch's avatar catch
Browse files

Issue #3125763 by quietone, heddn, dww, benjifisher, Lal_, Neslee Canil Pinto,...

Issue #3125763 by quietone, heddn, dww, benjifisher, Lal_, Neslee Canil Pinto, alexpott, mikelutz: Test coverage for hidden dependency on migrate_drupal from node module when only migrate.module is enabled
parent a9e15efb
No related branches found
No related tags found
No related merge requests found
name: 'Migrate No Migrate Drupal Test'
type: module
description: Provides fixture for testing without migrate_drupal.
package: Testing
version: VERSION
dependencies:
- drupal:migrate
- drupal:node
migrate_no_migrate_drupal_test.execute:
path: '/migrate_no_migrate_drupal_test/execute'
defaults:
_controller: '\Drupal\migrate_no_migrate_drupal_test\Controller\ExecuteMigration::execute'
_title: 'Execute'
requirements:
_access: 'TRUE'
id: node_migration_no_migrate_drupal
label: Node Migration No Migrate Drupal
source:
plugin: embedded_data
data_rows:
-
id: 1
nid: 1
title: Node 1
-
id: 2
nid: 2
title: Node 2
ids:
id:
type: integer
process:
nid: nid
title: title
destination:
default_bundle: no_migrate_drupal
plugin: entity:node
<?php
namespace Drupal\migrate_no_migrate_drupal_test\Controller;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\Core\Controller\ControllerBase;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\Plugin\MigrationInterface;
/**
* Custom controller to execute the test migrations.
*
* This controller class is required for the proper functional testing of
* migration dependencies. Otherwise, the migration directly executed from the
* functional test would use the functional test's class map and autoloader. The
* functional test has all the classes available to it but the controller
* does not.
*/
class ExecuteMigration extends ControllerBase {
/**
* Run the node_migration_no_migrate_drupal test migration.
*
* @return array
* A renderable array.
*/
public function execute() {
$migration_plugin_manager = \Drupal::service('plugin.manager.migration');
$definitions = $migration_plugin_manager->getDefinitions();
if ($definitions['node_migration_no_migrate_drupal']['label'] !== 'Node Migration No Migrate Drupal') {
throw new InvalidPluginDefinitionException('node_migration_no_migrate_drupal');
}
$migrations = $migration_plugin_manager->createInstances('');
$result = (new MigrateExecutable($migrations['node_migration_no_migrate_drupal']))->import();
if ($result !== MigrationInterface::RESULT_COMPLETED) {
throw new \RuntimeException('Migration failed');
}
return [
'#type' => 'markup',
'#markup' => 'Migration was successful.',
];
}
}
<?php
namespace Drupal\Tests\migrate\Functional;
use Drupal\node\Entity\Node;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
/**
* Execute migration.
*
* This is intentionally a Functional test instead of a Kernel test because
* Kernel tests have proven to not catch all edge cases that are encountered
* via a Functional test.
*
* @group migrate
*/
class MigrateNoMigrateDrupalTest extends BrowserTestBase {
use ContentTypeCreationTrait;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = [
'migrate',
'migrate_no_migrate_drupal_test',
'node',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Ensures that code from the migrate_drupal module can not be autoloaded
// while testing on DrupalCI.
$this->writeSettings(['settings' => ['deployment_identifier' => (object) ['value' => 'force-new-apcu-key', 'required' => TRUE]]]);
$this->createContentType(['type' => 'no_migrate_drupal']);
}
/**
* Tests execution of a migration.
*/
public function testExecutionNoMigrateDrupal() {
$this->drupalGet('/migrate_no_migrate_drupal_test/execute');
$this->assertSession()->pageTextContains('Migration was successful.');
$node_1 = Node::load(1);
$node_2 = Node::load(2);
$this->assertEquals('Node 1', $node_1->label());
$this->assertEquals('Node 2', $node_2->label());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment