function EntityResourceTest::setUp

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

Overrides KernelTestBase::setUp

File

core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php, line 105

Class

EntityResourceTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21jsonapi%21src%21Controller%21EntityResource.php/class/EntityResource/10" title="Process all entity requests." class="local">\Drupal\jsonapi\Controller\EntityResource</a> @group jsonapi

Namespace

Drupal\Tests\jsonapi\Kernel\Controller

Code

protected function setUp() : void {
    parent::setUp();
    // Add the entity schemas.
    $this->installEntitySchema('node');
    $this->installEntitySchema('user');
    // Add the additional table schemas.
    $this->installSchema('node', [
        'node_access',
    ]);
    $this->installSchema('user', [
        'users_data',
    ]);
    NodeType::create([
        'type' => 'lorem',
        'name' => 'Lorem',
    ])->save();
    $type = NodeType::create([
        'type' => 'article',
        'name' => 'Article',
    ]);
    $type->save();
    $this->user = User::create([
        'name' => 'user1',
        'mail' => 'user@localhost',
        'status' => 1,
        'roles' => [
            'test_role_one',
            'test_role_two',
        ],
    ]);
    $this->createEntityReferenceField('node', 'article', 'field_relationships', 'Relationship', 'node', 'default', [
        'target_bundles' => [
            'article',
        ],
    ], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
    $this->user
        ->save();
    $this->node = Node::create([
        'title' => 'dummy_title',
        'type' => 'article',
        'uid' => $this->user
            ->id(),
        'uuid' => static::$nodeUuid[1],
    ]);
    $this->node
        ->save();
    $this->node2 = Node::create([
        'type' => 'article',
        'title' => 'Another test node',
        'uid' => $this->user
            ->id(),
        'uuid' => static::$nodeUuid[2],
    ]);
    $this->node2
        ->save();
    $this->node3 = Node::create([
        'type' => 'article',
        'title' => 'Unpublished test node',
        'uid' => $this->user
            ->id(),
        'status' => 0,
        'uuid' => static::$nodeUuid[3],
    ]);
    $this->node3
        ->save();
    $this->node4 = Node::create([
        'type' => 'article',
        'title' => 'Test node with related nodes',
        'uid' => $this->user
            ->id(),
        'field_relationships' => [
            [
                'target_id' => $this->node
                    ->id(),
            ],
            [
                'target_id' => $this->node2
                    ->id(),
            ],
            [
                'target_id' => $this->node3
                    ->id(),
            ],
        ],
        'uuid' => static::$nodeUuid[4],
    ]);
    $this->node4
        ->save();
    // Give anonymous users permission to view user profiles, so that we can
    // verify the cache tags of cached versions of user profile pages.
    array_map(function ($role_id) {
        Role::create([
            'id' => $role_id,
            'permissions' => [
                'access user profiles',
                'access content',
            ],
            'label' => $role_id,
        ])->save();
    }, [
        RoleInterface::ANONYMOUS_ID,
        'test_role_one',
        'test_role_two',
    ]);
    $this->entityResource = $this->createEntityResource();
}

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