Version 1
[yaffs-website] / web / core / modules / migrate_drupal / tests / src / Kernel / MigrateCckFieldPluginManagerTest.php
1 <?php
2
3 namespace Drupal\Tests\migrate_drupal\Kernel;
4
5 use Drupal\Component\Plugin\Exception\PluginNotFoundException;
6
7 /**
8  * Tests the cck field plugin manager.
9  *
10  * @group migrate_drupal
11  */
12 class MigrateCckFieldPluginManagerTest extends MigrateDrupalTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public static $modules = ['system', 'user', 'field', 'migrate_drupal', 'options', 'file', 'text', 'migrate_cckfield_plugin_manager_test'];
18
19   /**
20    * Tests that the correct MigrateCckField plugins are used.
21    */
22   public function testPluginSelection() {
23     $plugin_manager = \Drupal::service('plugin.manager.migrate.cckfield');
24
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])));
27
28     try {
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.');
33     }
34     catch (PluginNotFoundException $e) {
35       $this->assertIdentical($e->getMessage(), "Plugin ID 'filefield' was not found.");
36     }
37
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]));
41
42     $this->assertIdentical('text', $plugin_manager->getPluginIdFromFieldType('text', ['core' => 6]));
43     $this->assertIdentical('text', $plugin_manager->getPluginIdFromFieldType('text', ['core' => 7]));
44
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]));
47
48     try {
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.');
53     }
54     catch (PluginNotFoundException $e) {
55       $this->assertIdentical($e->getMessage(), "Plugin ID 'd6_no_core_version_specified' was not found.");
56     }
57   }
58
59 }