You are here

public function FieldInstancePerViewModeTest::providerSource in Drupal 8

Same name in this branch
  1. 8 core/modules/field/tests/src/Kernel/Plugin/migrate/source/d6/FieldInstancePerViewModeTest.php \Drupal\Tests\field\Kernel\Plugin\migrate\source\d6\FieldInstancePerViewModeTest::providerSource()
  2. 8 core/modules/field/tests/src/Kernel/Plugin/migrate/source/d7/FieldInstancePerViewModeTest.php \Drupal\Tests\field\Kernel\Plugin\migrate\source\d7\FieldInstancePerViewModeTest::providerSource()
Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Kernel/Plugin/migrate/source/d6/FieldInstancePerViewModeTest.php \Drupal\Tests\field\Kernel\Plugin\migrate\source\d6\FieldInstancePerViewModeTest::providerSource()

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

core/modules/field/tests/src/Kernel/Plugin/migrate/source/d6/FieldInstancePerViewModeTest.php, line 23

Class

FieldInstancePerViewModeTest
Tests D6 fields per view mode source plugin.

Namespace

Drupal\Tests\field\Kernel\Plugin\migrate\source\d6

Code

public function providerSource() {
  $tests = [
    [
      'source_data' => [],
      'expected_data' => [],
    ],
  ];

  // The expected results.
  $tests[0]['expected_data'] = [
    [
      'entity_type' => 'node',
      'view_mode' => 4,
      'type_name' => 'article',
      'field_name' => 'field_test',
      'type' => 'text',
      'module' => 'text',
      'weight' => 1,
      'label' => 'above',
      'display_settings' => [
        'weight' => 1,
        'parent' => '',
        'label' => [
          'format' => 'above',
        ],
        4 => [
          'format' => 'trimmed',
          'exclude' => 0,
        ],
      ],
      'widget_settings' => [],
    ],
    [
      'entity_type' => 'node',
      'view_mode' => 'teaser',
      'type_name' => 'story',
      'field_name' => 'field_test',
      'type' => 'text',
      'module' => 'text',
      'weight' => 2,
      'label' => 'above',
      'display_settings' => [
        'weight' => 1,
        'parent' => '',
        'label' => [
          'format' => 'above',
        ],
        'teaser' => [
          'format' => 'trimmed',
          'exclude' => 0,
        ],
      ],
      'widget_settings' => [],
    ],
  ];

  // The source data.
  foreach ($tests[0]['expected_data'] as $k => $field_view_mode) {

    // These are stored as serialized strings.
    $field_view_mode['display_settings'] = serialize($field_view_mode['display_settings']);
    $field_view_mode['widget_settings'] = serialize($field_view_mode['widget_settings']);
    $tests[0]['source_data']['content_node_field'][] = [
      'field_name' => $field_view_mode['field_name'],
      'type' => $field_view_mode['type'],
      'module' => $field_view_mode['module'],
    ];
    unset($field_view_mode['type'], $field_view_mode['module']);
    $tests[0]['source_data']['content_node_field_instance'][] = $field_view_mode;

    // Update the expected display settings.
    $tests[0]['expected_data'][$k]['display_settings'] = $tests[0]['expected_data'][$k]['display_settings'][$field_view_mode['view_mode']];
  }
  return $tests;
}