You are here

public function EntityMutationTest::testCreateEntityMutationViolation in GraphQL 8.3

Test entity creation violations.

File

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

Class

EntityMutationTest
Test abstract entity mutation classes.

Namespace

Drupal\Tests\graphql_core\Kernel\EntityMutation

Code

public function testCreateEntityMutationViolation() {
  $this
    ->mockMutation('createNode', [
    'name' => 'createNode',
    'entity_type' => 'node',
    'entity_bundle' => 'test',
    'arguments' => [
      'input' => 'NodeInput',
    ],
    'type' => 'EntityCrudOutput',
  ], function ($source, $args, $context, $info) {
    return [
      'status' => 1,
      'body' => [
        'value' => $args['input']['body'],
      ],
    ];
  });
  $this
    ->assertResults('mutation ($node: NodeInput!) { createNode(input: $node) { violations { message path } } }', [
    'node' => [
      'title' => 'Test',
      'body' => 'This is a test.',
    ],
  ], [
    'createNode' => [
      'violations' => [
        0 => [
          'message' => 'This value should not be null.',
          'path' => 'title',
        ],
      ],
    ],
  ], $this
    ->defaultMutationCacheMetaData());
  $this
    ->assertEmpty(Node::load(1));
}