You are here

public function EntityMutationTest::testCreateEntityMutation in GraphQL 8.3

Test entity creation.

File

modules/graphql_core/tests/src/Kernel/EntityMutation/EntityMutationTest.php, line 79

Class

EntityMutationTest
Test abstract entity mutation classes.

Namespace

Drupal\Tests\graphql_core\Kernel\EntityMutation

Code

public function testCreateEntityMutation() {
  $this
    ->mockMutation('createNode', [
    'name' => 'createNode',
    'entity_type' => 'node',
    'entity_bundle' => 'test',
    'arguments' => [
      'input' => 'NodeInput',
    ],
    'type' => 'EntityCrudOutput',
  ], function ($source, $args, $context, $info) {
    return [
      'title' => $args['input']['title'],
      'status' => 1,
      'body' => [
        'value' => $args['input']['body'],
      ],
    ];
  });
  $this
    ->assertResults('mutation ($node: NodeInput!) { createNode(input: $node) { entity { entityId } } }', [
    'node' => [
      'title' => 'Test',
      'body' => 'This is a test.',
    ],
  ], [
    'createNode' => [
      'entity' => [
        'entityId' => 1,
      ],
    ],
  ], $this
    ->defaultMutationCacheMetaData());
  $this
    ->assertEquals('Test', Node::load(1)
    ->getTitle());
}