| @@ 80-113 (lines=34) @@ | ||
| 77 | /** |
|
| 78 | * Test entity creation. |
|
| 79 | */ |
|
| 80 | public function testCreateEntityMutation() { |
|
| 81 | $this->mockMutation('createNode', [ |
|
| 82 | 'name' => 'createNode', |
|
| 83 | 'entity_type' => 'node', |
|
| 84 | 'entity_bundle' => 'test', |
|
| 85 | 'arguments' => [ |
|
| 86 | 'input' => 'NodeInput', |
|
| 87 | ], |
|
| 88 | 'type' => 'EntityCrudOutput', |
|
| 89 | ], function ($source, $args, $context, $info) { |
|
| 90 | return [ |
|
| 91 | 'title' => $args['input']['title'], |
|
| 92 | 'status' => 1, |
|
| 93 | 'body' => [ |
|
| 94 | 'value' => $args['input']['body'], |
|
| 95 | ], |
|
| 96 | ]; |
|
| 97 | }); |
|
| 98 | ||
| 99 | $this->assertResults('mutation ($node: NodeInput!) { createNode(input: $node) { entity { entityId } } }', [ |
|
| 100 | 'node' => [ |
|
| 101 | 'title' => 'Test', |
|
| 102 | 'body' => 'This is a test.', |
|
| 103 | ], |
|
| 104 | ], [ |
|
| 105 | 'createNode' => [ |
|
| 106 | 'entity' => [ |
|
| 107 | 'entityId' => 1, |
|
| 108 | ], |
|
| 109 | ], |
|
| 110 | ], $this->defaultMutationCacheMetaData()); |
|
| 111 | ||
| 112 | $this->assertEquals('Test', Node::load(1)->getTitle()); |
|
| 113 | } |
|
| 114 | ||
| 115 | /** |
|
| 116 | * Test entity creation violations. |
|
| @@ 118-153 (lines=36) @@ | ||
| 115 | /** |
|
| 116 | * Test entity creation violations. |
|
| 117 | */ |
|
| 118 | public function testCreateEntityMutationViolation() { |
|
| 119 | $this->mockMutation('createNode', [ |
|
| 120 | 'name' => 'createNode', |
|
| 121 | 'entity_type' => 'node', |
|
| 122 | 'entity_bundle' => 'test', |
|
| 123 | 'arguments' => [ |
|
| 124 | 'input' => 'NodeInput', |
|
| 125 | ], |
|
| 126 | 'type' => 'EntityCrudOutput', |
|
| 127 | ], function ($source, $args, $context, $info) { |
|
| 128 | return [ |
|
| 129 | 'status' => 1, |
|
| 130 | 'body' => [ |
|
| 131 | 'value' => $args['input']['body'], |
|
| 132 | ], |
|
| 133 | ]; |
|
| 134 | }); |
|
| 135 | ||
| 136 | $this->assertResults('mutation ($node: NodeInput!) { createNode(input: $node) { violations { message path } } }', [ |
|
| 137 | 'node' => [ |
|
| 138 | 'title' => 'Test', |
|
| 139 | 'body' => 'This is a test.', |
|
| 140 | ], |
|
| 141 | ], [ |
|
| 142 | 'createNode' => [ |
|
| 143 | 'violations' => [ |
|
| 144 | 0 => [ |
|
| 145 | 'message' => 'This value should not be null.', |
|
| 146 | 'path' => 'title', |
|
| 147 | ], |
|
| 148 | ], |
|
| 149 | ], |
|
| 150 | ], $this->defaultMutationCacheMetaData()); |
|
| 151 | ||
| 152 | $this->assertEmpty(Node::load(1)); |
|
| 153 | } |
|
| 154 | ||
| 155 | /** |
|
| 156 | * Test entity updates. |
|