protected function FieldResolverTest::setUp in Drupal 9
Same name and namespace in other branches
- 8 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 46 
Class
- FieldResolverTest
- @coversDefaultClass \Drupal\jsonapi\Context\FieldResolver @group jsonapi
Namespace
Drupal\Tests\jsonapi\Kernel\ContextCode
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');
}