function EntityStorageBaseTest::providerLoadMultiple

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Core/Entity/EntityStorageBaseTest.php \Drupal\Tests\Core\Entity\EntityStorageBaseTest::providerLoadMultiple()
  2. 11.x core/tests/Drupal/Tests/Core/Entity/EntityStorageBaseTest.php \Drupal\Tests\Core\Entity\EntityStorageBaseTest::providerLoadMultiple()

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.