You are here

protected function FieldResolverTest::setUp in JSON:API 8.2

Same name and namespace in other branches
  1. 8 tests/src/Kernel/Context/FieldResolverTest.php \Drupal\Tests\jsonapi\Kernel\Context\FieldResolverTest::setUp()

Overrides KernelTestBase::setUp

File

tests/src/Kernel/Context/FieldResolverTest.php, line 47

Class

FieldResolverTest
@coversDefaultClass \Drupal\jsonapi\Context\FieldResolver @group jsonapi @group legacy

Namespace

Drupal\Tests\jsonapi\Kernel\Context

Code

protected function setUp() {
  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');
}