You are here

protected function ResourceTestBase::getSparseFieldSets in Drupal 8

Same name and namespace 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()

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