public function NodeTest::testCreate in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/rest/src/Tests/NodeTest.php \Drupal\rest\Tests\NodeTest::testCreate()
Test creating a node using json serialization.
File
- core/modules/ rest/ src/ Tests/ NodeTest.php, line 131 
- Contains \Drupal\rest\Tests\NodeTest.
Class
- NodeTest
- Tests special cases for node entities.
Namespace
Drupal\rest\TestsCode
public function testCreate() {
  // Data to be used for serialization.
  $data = [
    'type' => [
      [
        'target_id' => 'resttest',
      ],
    ],
    'title' => [
      [
        'value' => $this
          ->randomString(),
      ],
    ],
  ];
  $this
    ->postNode($data);
  // Make sure the response is "CREATED".
  $this
    ->assertResponse(201);
  // Make sure the node was created and the title matches.
  $node = $this
    ->assertNodeTitleMatch($data);
  // Make sure the request returned a redirect header to view the node.
  $this
    ->assertHeader('Location', $node
    ->url('canonical', [
    'absolute' => TRUE,
  ]));
}