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