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. 8.9.x 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.

1 call to ResourceTestBase::getSparseFieldSets()
ResourceTestBase::doTestSparseFieldSets in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Tests sparse field sets.
4 methods override ResourceTestBase::getSparseFieldSets()
EntityTestComputedFieldTest::getSparseFieldSets in core/modules/jsonapi/tests/src/Functional/EntityTestComputedFieldTest.php
Returns an array of sparse fields sets to test.
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.
WorkspaceTest::getSparseFieldSets in core/modules/jsonapi/tests/src/Functional/WorkspaceTest.php
Returns an array of sparse fields sets to test.

File

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

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, (int) 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.