protected function EntityToJsonApiTest::setUp in JSON:API Extras 8.3
Same name and namespace in other branches
- 8.2 tests/src/Kernel/EntityToJsonApiTest.php \Drupal\Tests\jsonapi_extras\Kernel\EntityToJsonApiTest::setUp()
Overrides KernelTestBase::setUp
File
- tests/
src/ Kernel/ EntityToJsonApiTest.php, line 73
Class
- EntityToJsonApiTest
- @coversDefaultClass \Drupal\jsonapi_extras\EntityToJsonApi @group jsonapi @group jsonapi_serializer @group legacy
Namespace
Drupal\Tests\jsonapi_extras\KernelCode
protected function setUp() {
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('system', [
'sequences',
]);
$this
->installSchema('node', [
'node_access',
]);
$this
->installSchema('user', [
'users_data',
]);
$this
->installSchema('file', [
'file_usage',
]);
$this->nodeType = NodeType::create([
'type' => 'article',
]);
$this->nodeType
->save();
$this
->createEntityReferenceField('node', 'article', 'field_tags', 'Tags', 'taxonomy_term', 'default', [
'target_bundles' => [
'tags',
],
], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$this
->createImageField('field_image', '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' => 1,
'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');
$this->role = Role::create([
'id' => RoleInterface::ANONYMOUS_ID,
'permissions' => [
'access content',
],
]);
$this->role
->save();
$this->sut = $this->container
->get('jsonapi_extras.entity.to_jsonapi');
}