Version 1
[yaffs-website] / web / core / modules / migrate_drupal / tests / src / Kernel / MigrateFieldPluginManagerTest.php
1 <?php
2
3 namespace Drupal\Tests\migrate_drupal\Kernel;
4
5 use Drupal\Component\Plugin\Exception\PluginNotFoundException;
6
7 /**
8  * Tests the field plugin manager.
9  *
10  * @group migrate_drupal
11  */
12 class MigrateFieldPluginManagerTest extends MigrateDrupalTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public static $modules = ['system', 'user', 'field', 'migrate_drupal', 'options', 'file', 'text', 'migrate_field_plugin_manager_test'];
18
19   /**
20    * Tests that the correct MigrateField plugins are used.
21    */
22   public function testPluginSelection() {
23     $plugin_manager = $this->container->get('plugin.manager.migrate.field');
24
25     try {
26       // If this test passes, getPluginIdFromFieldType will raise a
27       // PluginNotFoundException and we'll never reach fail().
28       $plugin_manager->getPluginIdFromFieldType('filefield', ['core' => 7]);
29       $this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
30     }
31     catch (PluginNotFoundException $e) {
32       $this->assertIdentical($e->getMessage(), "Plugin ID 'filefield' was not found.");
33     }
34
35     $this->assertIdentical('d6_file', $plugin_manager->getPluginIdFromFieldType('file', ['core' => 6]));
36
37     // Test fallback when no core version is specified.
38     $this->assertIdentical('d6_no_core_version_specified', $plugin_manager->getPluginIdFromFieldType('d6_no_core_version_specified', ['core' => 6]));
39
40     try {
41       // If this test passes, getPluginIdFromFieldType will raise a
42       // PluginNotFoundException and we'll never reach fail().
43       $plugin_manager->getPluginIdFromFieldType('d6_no_core_version_specified', ['core' => 7]);
44       $this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
45     }
46     catch (PluginNotFoundException $e) {
47       $this->assertIdentical($e->getMessage(), "Plugin ID 'd6_no_core_version_specified' was not found.");
48     }
49   }
50
51 }