You are here

protected function ResourceTestBase::getSparseFieldSets in Drupal 9

Same name and namespace in other branches
  1. 8 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.
3 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.

File

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

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