function JsonApiDocumentTopLevelNormalizerTest::setUp

Same name in this branch
  1. 10 core/modules/jsonapi/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Unit\Normalizer\JsonApiDocumentTopLevelNormalizerTest::setUp()
Same name and namespace in other branches
  1. 9 core/modules/jsonapi/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Unit\Normalizer\JsonApiDocumentTopLevelNormalizerTest::setUp()
  2. 9 core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::setUp()
  3. 8.9.x core/modules/jsonapi/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Unit\Normalizer\JsonApiDocumentTopLevelNormalizerTest::setUp()
  4. 8.9.x core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::setUp()
  5. 11.x core/modules/jsonapi/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Unit\Normalizer\JsonApiDocumentTopLevelNormalizerTest::setUp()
  6. 11.x core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::setUp()

Overrides KernelTestBase::setUp

File

core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php, line 133

Class

JsonApiDocumentTopLevelNormalizerTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21jsonapi%21src%21Normalizer%21JsonApiDocumentTopLevelNormalizer.php/class/JsonApiDocumentTopLevelNormalizer/10" title="Normalizes the top-level document according to the JSON:API specification." class="local">\Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer</a> @group jsonapi @group #slow

Namespace

Drupal\Tests\jsonapi\Kernel\Normalizer

Code

protected function setUp() : void {
    parent::setUp();
    // Add the entity schemas.
    $this->installEntitySchema('node');
    $this->installEntitySchema('user');
    $this->installEntitySchema('taxonomy_term');
    $this->installEntitySchema('file');
    // Add the additional table schemas.
    $this->installSchema('node', [
        'node_access',
    ]);
    $this->installSchema('user', [
        'users_data',
    ]);
    $this->installSchema('file', [
        'file_usage',
    ]);
    $type = NodeType::create([
        'type' => 'article',
        'name' => 'Article',
    ]);
    $type->save();
    $this->createEntityReferenceField('node', 'article', 'field_tags', 'Tags', 'taxonomy_term', 'default', [
        'target_bundles' => [
            'tags',
        ],
    ], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
    $this->createTextField('node', 'article', 'body', 'Body');
    $this->createImageField('field_image', 'node', 'article');
    $this->user = User::create([
        'name' => 'user1',
        'mail' => 'user@localhost',
    ]);
    $this->user2 = User::create([
        'name' => 'user2',
        'mail' => 'user2@localhost',
    ]);
    $this->user
        ->save();
    $this->user2
        ->save();
    $this->vocabulary = Vocabulary::create([
        'name' => 'Tags',
        'vid' => 'tags',
    ]);
    $this->vocabulary
        ->save();
    $this->term1 = Term::create([
        'name' => 'term1',
        'vid' => $this->vocabulary
            ->id(),
    ]);
    $this->term2 = Term::create([
        'name' => 'term2',
        'vid' => $this->vocabulary
            ->id(),
    ]);
    $this->term1
        ->save();
    $this->term2
        ->save();
    $this->file = File::create([
        'uri' => 'public://example.png',
        'filename' => 'example.png',
    ]);
    $this->file
        ->save();
    $this->node = Node::create([
        'title' => 'dummy_title',
        'type' => 'article',
        'uid' => $this->user,
        'body' => [
            'format' => 'plain_text',
            'value' => $this->randomString(),
        ],
        'field_tags' => [
            [
                'target_id' => $this->term1
                    ->id(),
            ],
            [
                'target_id' => $this->term2
                    ->id(),
            ],
        ],
        'field_image' => [
            [
                'target_id' => $this->file
                    ->id(),
                'alt' => 'test alt',
                'title' => 'test title',
                'width' => 10,
                'height' => 11,
            ],
        ],
    ]);
    $this->node
        ->save();
    $this->nodeType = NodeType::load('article');
    Role::create([
        'id' => RoleInterface::ANONYMOUS_ID,
        'permissions' => [
            'access content',
        ],
        'label' => 'Anonymous',
    ])->save();
    $this->includeResolver = $this->container
        ->get('jsonapi.include_resolver');
    $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.