You are here

public function FileEntitySourceFieldInstanceTest::providerSource in Media Migration 8

The data provider.

Return value

array Array of data sets to test, each of which is a numerically indexed array with the following elements:

  • An array of source data, which can be optionally processed and set up by subclasses.
  • An array of expected result rows.
  • (optional) The number of result rows the plugin under test is expected to return. If this is not a numeric value, the plugin will not be counted.
  • (optional) Array of configuration options for the plugin under test.

Overrides MigrateSourceTestBase::providerSource

See also

\Drupal\Tests\migrate\Kernel\MigrateSourceTestBase::testSource

File

tests/src/Kernel/Plugin/migrate/source/d7/FileEntitySourceFieldInstanceTest.php, line 48

Class

FileEntitySourceFieldInstanceTest
Tests the d7_file_entity_source_field_instance migration source plugin.

Namespace

Drupal\Tests\media_migration\Kernel\Plugin\migrate\source\d7

Code

public function providerSource() {
  $expected_audio_row = [
    'types' => 'audio',
    'schemes' => 'public',
    'bundle' => 'audio',
    'bundle_label' => 'Audio',
    'source_plugin_id' => 'audio_file',
    'source_field_name' => 'field_media_audio_file',
    'source_field_label' => 'Audio file',
    'file_extensions' => 'm4a',
  ];
  $expected_document_row = [
    'types' => 'document',
    'schemes' => 'public',
    'bundle' => 'document',
    'bundle_label' => 'Document',
    'source_plugin_id' => 'file',
    'source_field_name' => 'field_media_document',
    'source_field_label' => 'Document',
    'file_extensions' => 'txt::odt',
  ];
  $expected_image_row = [
    'types' => 'image',
    'schemes' => 'public',
    'bundle' => 'image',
    'bundle_label' => 'Image',
    'source_plugin_id' => 'image',
    'source_field_name' => 'field_media_image',
    'source_field_label' => 'Image',
    'file_extensions' => 'png::jpg::jpeg::webp',
  ];
  $expected_local_video_row = [
    'types' => 'video',
    'schemes' => 'public',
    'bundle' => 'video',
    'bundle_label' => 'Video',
    'source_plugin_id' => 'video_file',
    'source_field_name' => 'field_media_video_file',
    'source_field_label' => 'Video file',
    'file_extensions' => 'webm::mp4',
  ];
  $expected_youtube_row = [
    'types' => 'video',
    'schemes' => 'youtube',
    'bundle' => 'remote_video',
    'bundle_label' => 'Remote video',
    'source_plugin_id' => 'oembed:video',
    'source_field_name' => 'field_media_oembed_video',
    'source_field_label' => 'Video URL',
  ];
  $expected_vimeo_row = [
    'types' => 'video',
    'schemes' => 'vimeo',
    'bundle' => 'remote_video',
    'bundle_label' => 'Remote video',
    'source_plugin_id' => 'oembed:video',
    'source_field_name' => 'field_media_oembed_video',
    'source_field_label' => 'Video URL',
  ];
  $expected_remote_row = [
    'types' => 'video',
    'schemes' => 'youtube::vimeo',
    'bundle' => 'remote_video',
    'bundle_label' => 'Remote video',
    'source_plugin_id' => 'oembed:video',
    'source_field_name' => 'field_media_oembed_video',
    'source_field_label' => 'Video URL',
  ];
  return [
    'Audio' => [
      'source_data' => [
        'file_managed' => static::getFileManagedTableData(),
        'file_usage' => static::getFileUsageTableData(),
        'field_data_field_file_image_alt_text' => static::getFieldDataFieldFileImageAltTextTableData(FALSE),
        'field_data_field_file_image_title_text' => static::getFieldDataFieldFileImageTitleTextTableData(FALSE),
        'field_config_instance' => static::getFieldConfigInstanceTableData(FALSE, FALSE, FALSE, FALSE, FALSE),
        'field_config' => static::getFieldConfigTableData(FALSE),
        'users' => static::getUsersTableData(),
      ],
      'expected_data' => [
        $expected_audio_row,
      ],
      'count' => 1,
      'plugin_configuration' => [
        'types' => 'audio',
      ],
    ],
    'Document' => [
      'source_data' => [
        'file_managed' => static::getFileManagedTableData(),
        'file_usage' => static::getFileUsageTableData(),
        'field_data_field_file_image_alt_text' => static::getFieldDataFieldFileImageAltTextTableData(FALSE),
        'field_data_field_file_image_title_text' => static::getFieldDataFieldFileImageTitleTextTableData(FALSE),
        'field_config_instance' => static::getFieldConfigInstanceTableData(FALSE, FALSE, FALSE, FALSE, FALSE),
        'field_config' => static::getFieldConfigTableData(FALSE),
        'users' => static::getUsersTableData(),
      ],
      'expected_data' => [
        $expected_document_row,
      ],
      'count' => 1,
      'plugin_configuration' => [
        'types' => 'document',
      ],
    ],
    // Image: we use a customized Image FileEntityDealer plugin here to
    // prevent unnecessary DB selects.
    'Image' => [
      'source_data' => [
        'file_managed' => static::getFileManagedTableData(),
        'file_usage' => static::getFileUsageTableData(),
        'field_data_field_file_image_alt_text' => static::getFieldDataFieldFileImageAltTextTableData(FALSE),
        'field_data_field_file_image_title_text' => static::getFieldDataFieldFileImageTitleTextTableData(FALSE),
        'field_config_instance' => static::getFieldConfigInstanceTableData(FALSE, FALSE, FALSE, FALSE, FALSE),
        'field_config' => static::getFieldConfigTableData(FALSE),
        'users' => static::getUsersTableData(),
      ],
      'expected_data' => [
        $expected_image_row,
      ],
      'count' => 1,
      'plugin_configuration' => [
        'types' => 'image',
        'schemes' => 'public',
      ],
    ],
    'Local video' => [
      'source_data' => [
        'file_managed' => static::getFileManagedTableData(),
        'file_usage' => static::getFileUsageTableData(),
        'field_data_field_file_image_alt_text' => static::getFieldDataFieldFileImageAltTextTableData(FALSE),
        'field_data_field_file_image_title_text' => static::getFieldDataFieldFileImageTitleTextTableData(FALSE),
        'field_config_instance' => static::getFieldConfigInstanceTableData(FALSE, FALSE, FALSE, FALSE, FALSE),
        'field_config' => static::getFieldConfigTableData(FALSE),
        'users' => static::getUsersTableData(),
      ],
      'expected_data' => [
        $expected_local_video_row,
      ],
      'count' => 1,
      'plugin_configuration' => [
        'types' => 'video',
        'schemes' => 'public',
      ],
    ],
    'Youtube video' => [
      'source_data' => [
        'file_managed' => static::getFileManagedTableData(),
        'file_usage' => static::getFileUsageTableData(),
        'users' => static::getUsersTableData(),
      ],
      'expected_data' => [
        $expected_youtube_row,
      ],
      'count' => 1,
      'plugin_configuration' => [
        'types' => 'video',
        'schemes' => 'youtube',
      ],
    ],
    'Vimeo video' => [
      'source_data' => [
        'file_managed' => static::getFileManagedTableData(),
        'file_usage' => static::getFileUsageTableData(),
        'users' => static::getUsersTableData(),
      ],
      'expected_data' => [
        $expected_vimeo_row,
      ],
      'count' => 1,
      'plugin_configuration' => [
        'types' => 'video',
        'schemes' => 'vimeo',
      ],
    ],
    'All: plugin with default configuration' => [
      'source_data' => [
        'file_managed' => static::getFileManagedTableData(),
        'file_usage' => static::getFileUsageTableData(),
        'field_data_field_file_image_alt_text' => static::getFieldDataFieldFileImageAltTextTableData(FALSE),
        'field_data_field_file_image_title_text' => static::getFieldDataFieldFileImageTitleTextTableData(FALSE),
        'field_config_instance' => static::getFieldConfigInstanceTableData(FALSE, FALSE, FALSE, FALSE, FALSE),
        'field_config' => static::getFieldConfigTableData(FALSE),
        'users' => static::getUsersTableData(),
      ],
      'expected_data' => [
        $expected_image_row,
        $expected_remote_row,
        $expected_document_row,
        $expected_local_video_row,
        $expected_audio_row,
      ],
      'count' => 5,
      'plugin_configuration' => [],
    ],
    'Missing custom scheme as config' => [
      'source_data' => [
        'file_managed' => static::getFileManagedTableData(),
        'file_usage' => static::getFileUsageTableData(),
        'field_data_field_file_image_alt_text' => static::getFieldDataFieldFileImageAltTextTableData(FALSE),
        'field_data_field_file_image_title_text' => static::getFieldDataFieldFileImageTitleTextTableData(FALSE),
        'field_config_instance' => static::getFieldConfigInstanceTableData(FALSE, FALSE, FALSE, FALSE, FALSE),
        'field_config' => static::getFieldConfigTableData(FALSE),
        'users' => static::getUsersTableData(),
      ],
      'expected_data' => [],
      'count' => 0,
      'plugin_configuration' => [
        'schemes' => '_missing_custom',
      ],
    ],
  ];
}