function MigrateFieldPluginManagerTest::testWeights

Same name in other branches
  1. 9 core/modules/migrate_drupal/tests/src/Unit/MigrateFieldPluginManagerTest.php \Drupal\Tests\migrate_drupal\Unit\MigrateFieldPluginManagerTest::testWeights()
  2. 8.9.x core/modules/migrate_drupal/tests/src/Unit/MigrateFieldPluginManagerTest.php \Drupal\Tests\migrate_drupal\Unit\MigrateFieldPluginManagerTest::testWeights()
  3. 11.x core/modules/migrate_drupal/tests/src/Unit/MigrateFieldPluginManagerTest.php \Drupal\Tests\migrate_drupal\Unit\MigrateFieldPluginManagerTest::testWeights()

Tests the plugin weighting system.

@covers ::getPluginIdFromFieldType @covers ::sortDefinitions @covers ::findDefinitions @dataProvider weightsData

File

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

Class

MigrateFieldPluginManagerTest
Tests the MigrateFieldPluginManager class.

Namespace

Drupal\Tests\migrate_drupal\Unit

Code

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);
}

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