function FieldResolverTest::setUp

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php \Drupal\Tests\jsonapi\Kernel\Context\FieldResolverTest::setUp()
  2. 8.9.x core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php \Drupal\Tests\jsonapi\Kernel\Context\FieldResolverTest::setUp()
  3. 10 core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php \Drupal\Tests\jsonapi\Kernel\Context\FieldResolverTest::setUp()

Overrides KernelTestBase::setUp

File

core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php, line 53

Class

FieldResolverTest
@coversDefaultClass \Drupal\jsonapi\Context\FieldResolver @group jsonapi @group #slow

Namespace

Drupal\Tests\jsonapi\Kernel\Context

Code

protected function setUp() : void {
    parent::setUp();
    $this->installEntitySchema('entity_test_with_bundle');
    $this->sut = \Drupal::service('jsonapi.field_resolver');
    $this->makeBundle('bundle1');
    $this->makeBundle('bundle2');
    $this->makeBundle('bundle3');
    $this->makeField('string', 'field_test1', 'entity_test_with_bundle', [
        'bundle1',
    ]);
    $this->makeField('string', 'field_test2', 'entity_test_with_bundle', [
        'bundle1',
    ]);
    $this->makeField('string', 'field_test3', 'entity_test_with_bundle', [
        'bundle2',
        'bundle3',
    ]);
    // Provides entity reference fields.
    $settings = [
        'target_type' => 'entity_test_with_bundle',
    ];
    $this->makeField('entity_reference', 'field_test_ref1', 'entity_test_with_bundle', [
        'bundle1',
    ], $settings, [
        'handler_settings' => [
            'target_bundles' => [
                'bundle2',
                'bundle3',
            ],
        ],
    ]);
    $this->makeField('entity_reference', 'field_test_ref2', 'entity_test_with_bundle', [
        'bundle1',
    ], $settings);
    $this->makeField('entity_reference', 'field_test_ref3', 'entity_test_with_bundle', [
        'bundle2',
        'bundle3',
    ], $settings);
    // Add a field with multiple properties.
    $this->makeField('text', 'field_test_text', 'entity_test_with_bundle', [
        'bundle1',
        'bundle2',
    ]);
    // Add two fields that have different internal names but have the same
    // public name.
    $this->makeField('entity_reference', 'field_test_alias_a', 'entity_test_with_bundle', [
        'bundle2',
    ], $settings);
    $this->makeField('entity_reference', 'field_test_alias_b', 'entity_test_with_bundle', [
        'bundle3',
    ], $settings);
    $this->resourceTypeRepository = $this->container
        ->get('jsonapi.resource_type.repository');
}

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