You are here

public function RoleTest::providerSource in Drupal 10

Same name in this branch
  1. 10 core/modules/user/tests/src/Kernel/Plugin/migrate/source/d6/RoleTest.php \Drupal\Tests\user\Kernel\Plugin\migrate\source\d6\RoleTest::providerSource()
  2. 10 core/modules/user/tests/src/Kernel/Plugin/migrate/source/d7/RoleTest.php \Drupal\Tests\user\Kernel\Plugin\migrate\source\d7\RoleTest::providerSource()
Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Kernel/Plugin/migrate/source/d7/RoleTest.php \Drupal\Tests\user\Kernel\Plugin\migrate\source\d7\RoleTest::providerSource()
  2. 9 core/modules/user/tests/src/Kernel/Plugin/migrate/source/d7/RoleTest.php \Drupal\Tests\user\Kernel\Plugin\migrate\source\d7\RoleTest::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/user/tests/src/Kernel/Plugin/migrate/source/d7/RoleTest.php, line 23

Class

RoleTest
Tests the d7_user_role source plugin.

Namespace

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

Code

public function providerSource() {
  $expected = [
    [
      'rid' => 1,
      'name' => 'anonymous user',
      'permissions' => [
        'access content',
      ],
    ],
    [
      'rid' => 2,
      'name' => 'authenticated user',
      'permissions' => [
        'access comments',
        'access content',
        'post comments',
        'post comments without approval',
      ],
    ],
    [
      'rid' => 3,
      'name' => 'administrator',
      'permissions' => [
        'access comments',
        'administer comments',
        'post comments',
        'post comments without approval',
        'access content',
        'administer content types',
        'administer nodes',
      ],
    ],
  ];
  $data = [
    [
      [],
      $expected,
    ],
  ];
  foreach ($expected as $row) {
    foreach ($row['permissions'] as $permission) {
      $data[0][0]['role_permission'][] = [
        'permission' => $permission,
        'rid' => $row['rid'],
      ];
    }
    unset($row['permissions']);
    $data[0][0]['role'][] = $row;
  }
  return $data;
}