You are here

public function EntityStorageBaseTest::providerLoadMultiple in Drupal 10

Data provider for testLoadMultiple.

Return value

array

  • The expected result.
  • Results for doLoadMultiple(), called internally by loadMultiple().
  • The query, an array of IDs.

File

core/tests/Drupal/Tests/Core/Entity/EntityStorageBaseTest.php, line 82

Class

EntityStorageBaseTest
@coversDefaultClass \Drupal\Core\Entity\EntityStorageBase @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

public function providerLoadMultiple() {

  // Create a fixture of entity objects.
  $fixture = [];
  foreach (range(1, 10) as $index) {
    $fixture[(string) $index] = $this
      ->generateEntityInterface($index);
  }
  $data = [];

  // Data set for NULL ID parameter.
  $data['null-id-parameter'] = [
    $fixture,
    $fixture,
    NULL,
  ];

  // Data set for no results.
  $data['no-results'] = [
    [],
    [],
    [
      '11',
    ],
  ];

  // Data set for 0 results for multiple IDs.
  $data['no-results-multiple-ids'] = [
    [],
    [],
    [
      '11',
      '12',
      '13',
    ],
  ];

  // Data set for 1 result for 1 ID.
  $data['1-result-for-1-id'] = [
    [
      '1' => $fixture['1'],
    ],
    [
      '1' => $fixture['1'],
    ],
    [
      '1',
    ],
  ];

  // Data set for results for all IDs.
  $ids = [
    '1',
    '2',
    '3',
  ];
  foreach ($ids as $id) {
    $expectation[$id] = $fixture[$id];
    $load_multiple[$id] = $fixture[$id];
  }
  $data['results-for-all-ids'] = [
    $expectation,
    $load_multiple,
    $ids,
  ];

  // Data set for partial results for multiple IDs.
  $ids = [
    '1',
    '2',
    '3',
  ];
  foreach ($ids as $id) {
    $expectation[$id] = $fixture[$id];
    $load_multiple[$id] = $fixture[$id];
  }
  $ids = array_merge($ids, [
    '11',
    '12',
  ]);
  $data['partial-results-for-multiple-ids'] = [
    $expectation,
    $load_multiple,
    $ids,
  ];
  return $data;
}