class MigrateFieldPluginManagerTest

Same name in this branch
  1. 11.x core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php \Drupal\Tests\migrate_drupal\Kernel\MigrateFieldPluginManagerTest
Same name and namespace in other branches
  1. 9 core/modules/migrate_drupal/tests/src/Unit/MigrateFieldPluginManagerTest.php \Drupal\Tests\migrate_drupal\Unit\MigrateFieldPluginManagerTest
  2. 9 core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php \Drupal\Tests\migrate_drupal\Kernel\MigrateFieldPluginManagerTest
  3. 8.9.x core/modules/migrate_drupal/tests/src/Unit/MigrateFieldPluginManagerTest.php \Drupal\Tests\migrate_drupal\Unit\MigrateFieldPluginManagerTest
  4. 8.9.x core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php \Drupal\Tests\migrate_drupal\Kernel\MigrateFieldPluginManagerTest
  5. 10 core/modules/migrate_drupal/tests/src/Unit/MigrateFieldPluginManagerTest.php \Drupal\Tests\migrate_drupal\Unit\MigrateFieldPluginManagerTest
  6. 10 core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php \Drupal\Tests\migrate_drupal\Kernel\MigrateFieldPluginManagerTest

Tests the MigrateFieldPluginManager class.

@group migrate_drupal @coversDefaultClass \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManager

Hierarchy

Expanded class hierarchy of MigrateFieldPluginManagerTest

File

core/modules/migrate_drupal/tests/src/Unit/MigrateFieldPluginManagerTest.php, line 21

Namespace

Drupal\Tests\migrate_drupal\Unit
View source
class MigrateFieldPluginManagerTest extends UnitTestCase {
    
    /**
     * Tests the plugin weighting system.
     *
     * @covers ::getPluginIdFromFieldType
     * @covers ::sortDefinitions
     * @covers ::findDefinitions
     * @dataProvider weightsData
     */
    public function testWeights($field_type, $core, $expected_plugin_id) : void {
        
        /** @var \Drupal\Core\Cache\CacheBackendInterface $cache */
        $cache = $this->prophesize(CacheBackendInterface::class)
            ->reveal();
        
        /** @var \Drupal\Core\Extension\ModuleHandlerInterfaceModuleHandlerInterface $module_handler */
        $module_handler = $this->prophesize(ModuleHandlerInterface::class)
            ->reveal();
        $discovery = $this->prophesize(AnnotatedClassDiscovery::class);
        $discovery->getDefinitions()
            ->willReturn($this->pluginFixtureData());
        $manager = new MigrateFieldPluginManagerTestClass('field', new \ArrayObject(), $cache, $module_handler, MigrateField::class, $discovery->reveal());
        if (!$expected_plugin_id) {
            $this->expectException(PluginNotFoundException::class);
            $this->expectExceptionMessage(sprintf("Plugin ID '%s' was not found.", $field_type));
        }
        $actual_plugin_id = $manager->getPluginIdFromFieldType($field_type, [
            'core' => $core,
        ]);
        $this->assertSame($expected_plugin_id, $actual_plugin_id);
    }
    
    /**
     * Provides data for testWeights().
     *
     * @return array
     *   The data.
     */
    public static function weightsData() {
        return [
            'Field 1, D6' => [
                'field_type' => 'field_1',
                'core' => 6,
                'expected_plugin_id' => 'core_replacement_plugin',
            ],
            'Field 2, D6' => [
                'field_type' => 'field_2',
                'core' => 6,
                'expected_plugin_id' => 'field_1',
            ],
            'Field 3, D6' => [
                'field_type' => 'field_3',
                'core' => 6,
                'expected_plugin_id' => 'field_3',
            ],
            'Field 4, D6' => [
                'field_type' => 'field_4',
                'core' => 6,
                'expected_plugin_id' => 'field_4',
            ],
            'Field 5, D6' => [
                'field_type' => 'field_5',
                'core' => 6,
                'expected_plugin_id' => 'alphabetically_second',
            ],
            'Field 1, D7' => [
                'field_type' => 'field_1',
                'core' => 7,
                'expected_plugin_id' => 'core_replacement_plugin',
            ],
            'Field 2, D7' => [
                'field_type' => 'field_2',
                'core' => 7,
                'expected_plugin_id' => FALSE,
            ],
            'Field 3, D7' => [
                'field_type' => 'field_3',
                'core' => 7,
                'expected_plugin_id' => 'field_3',
            ],
            'Field 4, D7' => [
                'field_type' => 'field_4',
                'core' => 7,
                'expected_plugin_id' => 'contrib_override_plugin',
            ],
            'Field 5, D7' => [
                'field_type' => 'field_5',
                'core' => 7,
                'expected_plugin_id' => 'alphabetically_first',
            ],
        ];
    }
    
    /**
     * Returns test plugin data for the test class to use.
     *
     * @return array
     *   The test plugin data.
     */
    protected function pluginFixtureData() {
        return [
            // Represents a deprecated core field plugin that applied to field_1
            // and field_2 for Drupal 6.
'field_1' => [
                'weight' => 99999999,
                'core' => [
                    6,
                ],
                'type_map' => [
                    'field_1' => 'field_1',
                    'field_2' => 'field_2',
                ],
                'source_module' => 'system',
                'destination_module' => 'system',
            ],
            // Replacement for deprecated plugin for field_1 in Drupal 6 and 7.
            // Does not provide replacement for field_2.
'core_replacement_plugin' => [
                'weight' => 0,
                'core' => [
                    6,
                    7,
                ],
                'type_map' => [
                    'field_1' => 'field_1',
                ],
                'source_module' => 'system',
                'destination_module' => 'system',
            ],
            // Represents a core plugin with no type_map, applies to field_3 due to
            // plugin id.
'field_3' => [
                'core' => [
                    6,
                    7,
                ],
                'type_map' => [],
                'weight' => 0,
                'source_module' => 'system',
                'destination_module' => 'system',
            ],
            // Represents a core plugin with no type_map, applies to field_4 due to
            // plugin id.
'field_4' => [
                'core' => [
                    6,
                    7,
                ],
                'type_map' => [],
                'weight' => 0,
                'source_module' => 'system',
                'destination_module' => 'system',
            ],
            // Represents a contrib plugin overriding field_4 for Drupal 7 only.
'contrib_override_plugin' => [
                'weight' => -100,
                'core' => [
                    7,
                ],
                'type_map' => [
                    'field_4' => 'field_4',
                ],
                'source_module' => 'system',
                'destination_module' => 'system',
            ],
            // field_5 is served by alphabetically_second in Drupal 6 and
            // alphabetically_first and alphabetically_second in Drupal 7.  It should
            // be served by the alphabetically_first in Drupal 7 regardless of the
            // order they appear here.
'alphabetically_second' => [
                'weight' => 0,
                'core' => [
                    6,
                    7,
                ],
                'type_map' => [
                    'field_5' => 'field_5',
                ],
                'source_module' => 'system',
                'destination_module' => 'system',
            ],
            'alphabetically_first' => [
                'weight' => 0,
                'core' => [
                    7,
                ],
                'type_map' => [
                    'field_5' => 'field_5',
                ],
                'source_module' => 'system',
                'destination_module' => 'system',
            ],
        ];
    }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
ExpectDeprecationTrait::expectDeprecation public function Adds an expected deprecation.
ExpectDeprecationTrait::getCallableName private static function Returns a callable as a string suitable for inclusion in a message.
ExpectDeprecationTrait::setUpErrorHandler public function Sets up the test error handler.
ExpectDeprecationTrait::tearDownErrorHandler public function Tears down the test error handler.
MigrateFieldPluginManagerTest::pluginFixtureData protected function Returns test plugin data for the test class to use.
MigrateFieldPluginManagerTest::testWeights public function Tests the plugin weighting system.
MigrateFieldPluginManagerTest::weightsData public static function Provides data for testWeights().
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
UnitTestCase::$root protected property The app root.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUp protected function 354
UnitTestCase::setUpBeforeClass public static function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.