function RelationshipNormalizerTest::setUp

Same name and namespace in other branches
  1. 8.9.x core/modules/jsonapi/tests/src/Kernel/Normalizer/RelationshipNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\RelationshipNormalizerTest::setUp()
  2. 10 core/modules/jsonapi/tests/src/Kernel/Normalizer/RelationshipNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\RelationshipNormalizerTest::setUp()
  3. 11.x core/modules/jsonapi/tests/src/Kernel/Normalizer/RelationshipNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\RelationshipNormalizerTest::setUp()

Overrides KernelTestBase::setUp

File

core/modules/jsonapi/tests/src/Kernel/Normalizer/RelationshipNormalizerTest.php, line 142

Class

RelationshipNormalizerTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21jsonapi%21src%21Normalizer%21RelationshipNormalizer.php/class/RelationshipNormalizer/9" title="Normalizes a JSON:API relationship object." class="local">\Drupal\jsonapi\Normalizer\RelationshipNormalizer</a> @group jsonapi

Namespace

Drupal\Tests\jsonapi\Kernel\Normalizer

Code

protected function setUp() : void {
    parent::setUp();
    // Set up the data model.
    // Add the entity schemas.
    $this->installEntitySchema('node');
    $this->installEntitySchema('user');
    $this->installEntitySchema('file');
    // Add the additional table schemas.
    $this->installSchema('system', [
        'sequences',
    ]);
    $this->installSchema('node', [
        'node_access',
    ]);
    $this->installSchema('file', [
        'file_usage',
    ]);
    NodeType::create([
        'type' => 'referencer',
    ])->save();
    $this->createEntityReferenceField('node', 'referencer', 'field_user', 'User', 'user', 'default', [
        'target_bundles' => NULL,
    ], 1);
    $this->createEntityReferenceField('node', 'referencer', 'field_users', 'Users', 'user', 'default', [
        'target_bundles' => NULL,
    ], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
    $field_storage_config = [
        'type' => 'image',
        'entity_type' => 'node',
    ];
    FieldStorageConfig::create([
        'field_name' => 'field_image',
        'cardinality' => 1,
    ] + $field_storage_config)->save();
    FieldStorageConfig::create([
        'field_name' => 'field_images',
        'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
    ] + $field_storage_config)->save();
    $field_config = [
        'entity_type' => 'node',
        'bundle' => 'referencer',
    ];
    FieldConfig::create([
        'field_name' => 'field_image',
        'label' => 'Image',
    ] + $field_config)->save();
    FieldConfig::create([
        'field_name' => 'field_images',
        'label' => 'Images',
    ] + $field_config)->save();
    // Set up the test data.
    $this->setUpCurrentUser([], [
        'access content',
    ]);
    $this->user1 = User::create([
        'name' => $this->randomMachineName(),
        'mail' => $this->randomMachineName() . '@example.com',
        'uuid' => static::$userIds[0],
        'uid' => static::$userUids[0],
    ]);
    $this->user1
        ->save();
    $this->user2 = User::create([
        'name' => $this->randomMachineName(),
        'mail' => $this->randomMachineName() . '@example.com',
        'uuid' => static::$userIds[1],
        'uid' => static::$userUids[1],
    ]);
    $this->user2
        ->save();
    $this->image1 = File::create([
        'uri' => 'public:/image1.png',
        'uuid' => static::$imageIds[0],
        'uid' => static::$imageUids[0],
    ]);
    $this->image1
        ->save();
    $this->image2 = File::create([
        'uri' => 'public:/image2.png',
        'uuid' => static::$imageIds[1],
        'uid' => static::$imageUids[1],
    ]);
    $this->image2
        ->save();
    // Create the node from which all the previously created entities will be
    // referenced.
    $this->referencer = Node::create([
        'title' => 'Referencing node',
        'type' => 'referencer',
        'status' => 1,
        'uuid' => static::$referencerId,
    ]);
    $this->referencer
        ->save();
    // Set up the test dependencies.
    $this->referencingResourceType = $this->container
        ->get('jsonapi.resource_type.repository')
        ->get('node', 'referencer');
    $this->normalizer = new RelationshipNormalizer();
    $this->normalizer
        ->setSerializer($this->container
        ->get('jsonapi.serializer'));
}

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