You are here

public function FileEntityDealerTest::testFileEntityDealerPlugins in Media Migration 8

Tests the file entity dealer plugin instances.

@dataProvider providerTestFileEntityDealer

Parameters

string $type: The incoming file entity type ID.

string $scheme: The scheme of the actual file entity.

string|null $expected_plugin_class: The expected class of the file entity dealer plugin instance.

string|null $expected_type_id_base: The expected media type ID base returned by the file entity dealer plugin instance.

string|null $expected_type_id: The expected media type ID returned by the file entity dealer plugin instance.

string|null $expected_type_label: The expected media type label returned by the file entity dealer plugin instance.

string|null $expected_source_plugin_id: The expected media source plugin ID from the file entity dealer plugin.

string|null $expected_source_field_name: The expected media source field name from the file entity dealer plugin.

string|null $expected_source_field_label: The expected media source field label from the file entity dealer plugin.

File

tests/src/Kernel/Plugin/FileEntityDealerTest.php, line 79

Class

FileEntityDealerTest
Tests the file entity dealer manager and the plugin instances.

Namespace

Drupal\Tests\media_migration\Kernel\Plugin

Code

public function testFileEntityDealerPlugins(string $type, string $scheme, string $expected_plugin_class = NULL, string $expected_type_id_base = NULL, string $expected_type_id = NULL, string $expected_type_label = NULL, string $expected_source_plugin_id = NULL, string $expected_source_field_name = NULL, string $expected_source_field_label = NULL) {
  $expectations = [
    'Media type ID base' => $expected_type_id_base,
    'Media type ID' => $expected_type_id,
    'Media type label' => $expected_type_label,
    'Media source plugin ID' => $expected_source_plugin_id,
    'Media source field name' => $expected_source_field_name,
    'Media source field label ID' => $expected_source_field_label,
  ];

  // If expectations are empty, we skip testing this case.
  if (empty(array_filter($expectations))) {
    $this
      ->markTestSkipped();
  }
  $dealer = $this->container
    ->get('plugin.manager.file_entity_dealer');
  assert($dealer instanceof FileEntityDealerManagerInterface);
  $plugin_instance = $dealer
    ->createInstanceFromTypeAndScheme($type, $scheme);
  $this
    ->assertInstanceOf($expected_plugin_class, $plugin_instance);
  $this
    ->assertEquals([
    'Media type ID base' => $expected_type_id_base,
    'Media type ID' => $expected_type_id,
    'Media type label' => $expected_type_label,
    'Media source plugin ID' => $expected_source_plugin_id,
    'Media source field name' => $expected_source_field_name,
    'Media source field label ID' => $expected_source_field_label,
  ], [
    'Media type ID base' => $plugin_instance
      ->getDestinationMediaTypeIdBase(),
    'Media type ID' => $plugin_instance
      ->getDestinationMediaTypeId(),
    'Media type label' => $plugin_instance
      ->getDestinationMediaTypeLabel(),
    'Media source plugin ID' => $plugin_instance
      ->getDestinationMediaSourcePluginId(),
    'Media source field name' => $plugin_instance
      ->getDestinationMediaSourceFieldName(),
    'Media source field label ID' => $plugin_instance
      ->getDestinationMediaTypeSourceFieldLabel(),
  ]);
}