You are here

public function ServicesResourceNodetests::testEndpointResourceNodeUpdate in Services 6.3

Same name and namespace in other branches
  1. 7.3 tests/functional/ServicesResourceNodeTests.test \ServicesResourceNodetests::testEndpointResourceNodeUpdate()

Testing node_resource Update

File

tests/functional/ServicesResourceNodeTests.test, line 383

Class

ServicesResourceNodetests
Run test cases for the endpoint with no authentication turned on.

Code

public function testEndpointResourceNodeUpdate() {

  // Create and log in our privileged user.
  $this->privilegedUser = $this
    ->drupalCreateUser(array(
    'administer services',
    'administer nodes',
  ));
  $this
    ->drupalLogin($this->privilegedUser);
  $node = $this
    ->drupalCreateNode();
  $node_update = array(
    'title' => 'testing',
    'body' => 'bodytest',
    'type' => 'page',
    'name' => $this->privilegedUser->name,
  );
  $responseArray = $this
    ->servicesPut($this->endpoint->path . '/node/' . $node->nid, $node_update);
  $nodeAfterUpdate = node_load($responseArray['body']['nid']);
  $this
    ->assertTrue(isset($nodeAfterUpdate->nid), t('Node was successfully updated'), 'NodeResource: Updated');
  if (isset($nodeAfterUpdate->nid)) {
    $this
      ->assertTrue($nodeAfterUpdate->title == $node_update['title'], t('Title was the same'), 'NodeResource: Update');
    $this
      ->assertTrue($nodeAfterUpdate->body == $node_update['body'], t('Body was the same'), 'NodeResource: Update');
  }

  // Try to update the node without node type.
  $node_update_no_type = $node_update;
  unset($node_update_no_type['type']);
  $node_update_no_type['title'] = $this
    ->randomName();
  $responseArray = $this
    ->servicesPut($this->endpoint->path . '/node/' . $node->nid, $node_update_no_type);
  $this
    ->assertNotEqual($responseArray['code'], 200, t('Can\'t update node without specifying node type'), 'NodeResource: Update');
}