protected function EntityResourceTest::setUp in JSON:API 8.2
Same name and namespace in other branches
- 8 tests/src/Kernel/Controller/EntityResourceTest.php \Drupal\Tests\jsonapi\Kernel\Controller\EntityResourceTest::setUp()
Overrides KernelTestBase::setUp
File
- tests/
src/ Kernel/ Controller/ EntityResourceTest.php, line 105
Class
- EntityResourceTest
- @coversDefaultClass \Drupal\jsonapi\Controller\EntityResource @group jsonapi @group legacy
Namespace
Drupal\Tests\jsonapi\Kernel\ControllerCode
protected function setUp() {
parent::setUp();
// Add the entity schemas.
$this
->installEntitySchema('node');
$this
->installEntitySchema('user');
// Add the additional table schemas.
$this
->installSchema('system', [
'sequences',
]);
$this
->installSchema('node', [
'node_access',
]);
$this
->installSchema('user', [
'users_data',
]);
NodeType::create([
'type' => 'lorem',
])
->save();
$type = NodeType::create([
'type' => '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',
],
])
->save();
}, [
RoleInterface::ANONYMOUS_ID,
'test_role_one',
'test_role_two',
]);
$this->entityResource = $this
->createEntityResource();
}