function ResourceTestBase::getSparseFieldSets

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getSparseFieldSets()
  2. 10 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getSparseFieldSets()
  3. 11.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getSparseFieldSets()

Returns an array of sparse fields sets to test.

Return value

array An array of sparse field sets (an array of field names), keyed by a label for the field set.

3 calls to ResourceTestBase::getSparseFieldSets()
EntityTestMapFieldTest::getSparseFieldSets in core/modules/jsonapi/tests/src/Functional/EntityTestMapFieldTest.php
Returns an array of sparse fields sets to test.
EntityTestTest::getSparseFieldSets in core/modules/jsonapi/tests/src/Functional/EntityTestTest.php
Returns an array of sparse fields sets to test.
ResourceTestBase::doTestSparseFieldSets in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Tests sparse field sets.
2 methods override ResourceTestBase::getSparseFieldSets()
EntityTestMapFieldTest::getSparseFieldSets in core/modules/jsonapi/tests/src/Functional/EntityTestMapFieldTest.php
Returns an array of sparse fields sets to test.
EntityTestTest::getSparseFieldSets in core/modules/jsonapi/tests/src/Functional/EntityTestTest.php
Returns an array of sparse fields sets to test.

File

core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php, line 3230

Class

ResourceTestBase
Subclass this for every JSON:API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getSparseFieldSets() {
    $field_names = array_keys($this->entity
        ->toArray());
    $field_sets = [
        'empty' => [],
        'some' => array_slice($field_names, floor(count($field_names) / 2)),
        'all' => $field_names,
    ];
    if ($this->entity instanceof EntityOwnerInterface) {
        $field_sets['nested_empty_fieldset'] = $field_sets['empty'];
        $field_sets['nested_fieldset_with_owner_fieldset'] = [
            'name',
            'created',
        ];
    }
    return $field_sets;
}

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