3 namespace Drupal\Tests\migrate_drupal\Kernel;
5 use Drupal\Component\Plugin\Exception\PluginNotFoundException;
8 * Tests the cck field plugin manager.
10 * @group migrate_drupal
12 class MigrateCckFieldPluginManagerTest extends MigrateDrupalTestBase {
17 public static $modules = ['system', 'user', 'field', 'migrate_drupal', 'options', 'file', 'text', 'migrate_cckfield_plugin_manager_test'];
20 * Tests that the correct MigrateCckField plugins are used.
22 public function testPluginSelection() {
23 $plugin_manager = \Drupal::service('plugin.manager.migrate.cckfield');
25 $plugin_id = $plugin_manager->getPluginIdFromFieldType('filefield', ['core' => 6]);
26 $this->assertIdentical('Drupal\\file\\Plugin\\migrate\\cckfield\\d6\\FileField', get_class($plugin_manager->createInstance($plugin_id, ['core' => 6])));
29 // If this test passes, getPluginIdFromFieldType will raise a
30 // PluginNotFoundException and we'll never reach fail().
31 $plugin_manager->getPluginIdFromFieldType('filefield', ['core' => 7]);
32 $this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
34 catch (PluginNotFoundException $e) {
35 $this->assertIdentical($e->getMessage(), "Plugin ID 'filefield' was not found.");
38 $this->assertIdentical('image', $plugin_manager->getPluginIdFromFieldType('image', ['core' => 7]));
39 $this->assertIdentical('file', $plugin_manager->getPluginIdFromFieldType('file', ['core' => 7]));
40 $this->assertIdentical('d6_file', $plugin_manager->getPluginIdFromFieldType('file', ['core' => 6]));
42 $this->assertIdentical('text', $plugin_manager->getPluginIdFromFieldType('text', ['core' => 6]));
43 $this->assertIdentical('text', $plugin_manager->getPluginIdFromFieldType('text', ['core' => 7]));
45 // Test fallback when no core version is specified.
46 $this->assertIdentical('d6_no_core_version_specified', $plugin_manager->getPluginIdFromFieldType('d6_no_core_version_specified', ['core' => 6]));
49 // If this test passes, getPluginIdFromFieldType will raise a
50 // PluginNotFoundException and we'll never reach fail().
51 $plugin_manager->getPluginIdFromFieldType('d6_no_core_version_specified', ['core' => 7]);
52 $this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
54 catch (PluginNotFoundException $e) {
55 $this->assertIdentical($e->getMessage(), "Plugin ID 'd6_no_core_version_specified' was not found.");