function RestfulUpdateEntityTestCase::testUpdateEntityAsPatch in RESTful 7
Same name and namespace in other branches
- 7.2 tests/RestfulUpdateEntityTestCase.test \RestfulUpdateEntityTestCase::testUpdateEntityAsPatch()
Test update an entity (PATCH method).
File
- tests/
RestfulUpdateEntityTestCase.test, line 87 - Contains RestfulUpdateEntityTestCase
Class
- RestfulUpdateEntityTestCase
- @file Contains RestfulUpdateEntityTestCase
Code
function testUpdateEntityAsPatch() {
$label = $this
->randomName();
$new_label = $this
->randomName();
$text = $this
->randomName();
$settings = array(
'type' => 'article',
'title' => $label,
);
$settings['body'][LANGUAGE_NONE][0]['value'] = $text;
$node = $this
->drupalCreateNode($settings);
$id = $node->nid;
$handler = restful_get_restful_handler('test_articles');
$request = array(
'label' => $new_label,
);
$result = $handler
->patch($id, $request);
$expected_result = array(
array(
'id' => $id,
'label' => $new_label,
'self' => $handler
->versionedUrl($id),
'body' => $text,
),
);
$result[0]['body'] = trim(strip_tags($result[0]['body']));
$this
->assertEqual($result, $expected_result);
// Update an entity with invalid property name.
$request['invalid'] = 'wrong';
try {
$handler
->patch($id, $request);
$this
->fail('User can update using PATCH method an entity with invalid property name.');
} catch (Exception $e) {
$this
->pass('User cannot update using PATCH method an entity with invalid property name.');
}
$new_body = $this
->randomName();
$request = array(
'body' => $new_body,
);
// Setting new value for 'body'.
$result = $handler
->patch($id, $request);
// Making sure the new body has been set.
$this
->assertEqual(trim(strip_tags($result[0]['body'])), $new_body);
// Removing the body value.
$request = array(
'body' => NULL,
);
$result = $handler
->patch($id, $request);
$this
->assertEqual($result[0]['body'], NULL);
}