You are here

public function ProfileFieldTest::providerSource in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Kernel/Plugin/migrate/source/ProfileFieldTest.php \Drupal\Tests\user\Kernel\Plugin\migrate\source\ProfileFieldTest::providerSource()
  2. 9 core/modules/user/tests/src/Kernel/Plugin/migrate/source/ProfileFieldTest.php \Drupal\Tests\user\Kernel\Plugin\migrate\source\ProfileFieldTest::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

1 method overrides ProfileFieldTest::providerSource()
ProfileFieldOptionTranslationTest::providerSource in core/modules/user/tests/src/Kernel/Plugin/migrate/source/d6/ProfileFieldOptionTranslationTest.php
The data provider.

File

core/modules/user/tests/src/Kernel/Plugin/migrate/source/ProfileFieldTest.php, line 23

Class

ProfileFieldTest
Tests the profile_field source plugin.

Namespace

Drupal\Tests\user\Kernel\Plugin\migrate\source

Code

public function providerSource() {
  $tests = [
    [
      'source_data' => [],
      'expected_data' => [],
    ],
  ];
  $profile_fields = [
    [
      'fid' => 1,
      'title' => 'First name',
      'name' => 'profile_first_name',
      'explanation' => 'First name user',
      'category' => 'profile',
      'page' => '',
      'type' => 'textfield',
      'weight' => 0,
      'required' => 1,
      'register' => 0,
      'visibility' => 2,
      'autocomplete' => 0,
      'options' => '',
    ],
    [
      'fid' => 2,
      'title' => 'Last name',
      'name' => 'profile_last_name',
      'explanation' => 'Last name user',
      'category' => 'profile',
      'page' => '',
      'type' => 'textfield',
      'weight' => 0,
      'required' => 0,
      'register' => 0,
      'visibility' => 2,
      'autocomplete' => 0,
      'options' => '',
    ],
    [
      'fid' => 3,
      'title' => 'Policy',
      'name' => 'profile_policy',
      'explanation' => 'A checkbox that say if you accept policy of website',
      'category' => 'profile',
      'page' => '',
      'type' => 'checkbox',
      'weight' => 0,
      'required' => 1,
      'register' => 1,
      'visibility' => 2,
      'autocomplete' => 0,
      'options' => '',
    ],
    [
      'fid' => 4,
      'title' => 'Color',
      'name' => 'profile_color',
      'explanation' => 'A selection that allows user to select a color',
      'category' => 'profile',
      'page' => '',
      'type' => 'selection',
      'weight' => 0,
      'required' => 0,
      'register' => 0,
      'visibility' => 2,
      'autocomplete' => 0,
      'options' => "red\nblue\ngreen",
    ],
  ];
  $tests[0]['source_data']['profile_fields'] = $profile_fields;

  // Profile values are merged with pre-set options of a "selection" field.
  $tests[0]['source_data']['profile_values'] = [
    [
      'fid' => 4,
      'uid' => 1,
      'value' => 'yellow',
    ],
  ];

  // Expected options are:
  // - for "checkbox" fields - array with NULL options.
  // - for "selection" fields - options in both keys and values.
  $expected_field_options = [
    '',
    '',
    [
      NULL,
      NULL,
    ],
    [
      'red' => 'red',
      'blue' => 'blue',
      'green' => 'green',
      'yellow' => 'yellow',
    ],
  ];
  $tests[0]['expected_data'] = $profile_fields;
  foreach ($tests[0]['expected_data'] as $delta => $row) {
    $tests[0]['expected_data'][$delta]['options'] = $expected_field_options[$delta];
  }
  return $tests;
}