You are here

public function ConfigTest::providerSource in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\d8\ConfigTest::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/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php, line 23

Class

ConfigTest
Tests the config source plugin.

Namespace

Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\d8

Code

public function providerSource() {
  $data = [];

  // The source database tables.
  $data[0]['source_data'] = [
    'config' => [
      [
        'collection' => 'language.af',
        'name' => 'user.settings',
        'data' => 'a:1:{s:9:"anonymous";s:14:"af - Anonymous";}',
      ],
      [
        'collection' => '',
        'name' => 'user.settings',
        'data' => 'a:1:{s:9:"anonymous";s:9:"Anonymous";}',
      ],
      [
        'collection' => 'language.de',
        'name' => 'user.settings',
        'data' => 'a:1:{s:9:"anonymous";s:14:"de - Anonymous";}',
      ],
      [
        'collection' => 'language.af',
        'name' => 'bar',
        'data' => 'b:0;',
      ],
    ],
  ];

  // The expected results.
  $data[0]['expected_results'] = [
    [
      'collection' => 'language.af',
      'name' => 'user.settings',
      'data' => [
        'anonymous' => 'af - Anonymous',
      ],
    ],
    [
      'collection' => 'language.af',
      'name' => 'bar',
      'data' => FALSE,
    ],
  ];
  $data[0]['expected_count'] = NULL;
  $data[0]['configuration'] = [
    'names' => [
      'user.settings',
      'bar',
    ],
    'collections' => [
      'language.af',
    ],
  ];

  // Test with name and no collection in configuration.
  $data[1]['source_data'] = $data[0]['source_data'];
  $data[1]['expected_results'] = [
    [
      'collection' => 'language.af',
      'name' => 'bar',
      'data' => FALSE,
    ],
  ];
  $data[1]['expected_count'] = NULL;
  $data[1]['configuration'] = [
    'names' => [
      'bar',
    ],
  ];

  // Test with collection and no name in configuration.
  $data[2]['source_data'] = $data[0]['source_data'];
  $data[2]['expected_results'] = [
    [
      'collection' => 'language.de',
      'name' => 'user.settings',
      'data' => [
        'anonymous' => 'de - Anonymous',
      ],
    ],
  ];
  $data[2]['expected_count'] = NULL;
  $data[2]['configuration'] = [
    'collections' => [
      'language.de',
    ],
  ];
  return $data;
}