function WSClientRestWSTestCase::testCRUD in Web service client 7
Test the RestWS node service.
File
- wsclient_examples/
wsclient_examples.test, line 147 - Web service client SOAP/REST Tests.
Class
Code
function testCRUD() {
// Get.
$title = $this
->randomName(8);
$node = $this
->drupalCreateNode(array(
'title' => $title,
));
$account = $this
->drupalCreateUser(array(
'access resource node',
));
$service = wsclient_service_load('restws_node');
$this
->addSimpletestCurlOptions($service, $account);
$result = $service
->get($node->nid);
$this
->assertEqual($node->title, $result['title'], 'Node title received correctly');
// Create.
$account = $this
->drupalCreateUser(array(
'access resource node',
'access content',
'bypass node access',
));
$this
->addSimpletestCurlOptions($service, $account);
$service
->clearCache();
$node = array(
'type' => $node->title,
'title' => $title,
'author' => $node->uid,
);
$result = $service
->create($node);
$nid = $result['id'];
// Clear the static cache, otherwise we won't see the update.
$created_node = node_load($nid, NULL, TRUE);
$this
->assertEqual($created_node->title, $title, 'Created node title is correct.');
$this
->assertEqual($result['uri'], url('node/' . $nid, array(
'absolute' => TRUE,
)), 'Returned URI is correct.');
$this
->assertEqual($result['resource'], 'node', 'Returned resource is correct.');
// Update.
$new_title = $this
->randomName();
$node = array(
'title' => $new_title,
);
$service
->update($node, $nid);
// Clear the static cache, otherwise we won't see the update.
$updated_node = node_load($nid, NULL, TRUE);
$this
->assertEqual($new_title, $updated_node->title, 'Node title has been updated sucessfully');
// Delete.
// We cannot directly call the method delete() as it is used for another
// purpose.
$service
->invoke('delete', array(
$nid,
));
// Clear the static cache, otherwise we won't see the update.
$deleted_node = node_load($nid, NULL, TRUE);
$this
->assertFalse($deleted_node, 'Node is not in the DB anymore.');
}