endpoint = $this->saveNewEndpoint(); } /** * Implementation of getInfo(). */ public static function getInfo() { return array( 'name' => t('Resource Node'), 'description' => t('test the resource Node methods and actions.'), 'group' => t('Services'), ); } /** * testing node_resource Index */ public function testNewEndpointResourceNodeIndex() { // Create and log in our privileged user. $this->privilegedUser = $this->drupalCreateUser(array( 'administer services', )); $this->drupalLogin($this->privilegedUser); $node = $this->drupalCreateNode(); $responseArray = $this->servicesGet($this->endpoint->path . '/node'); $this->assertTrue($node->title == $responseArray['body'][0]->title, t('Successfully received Node info'), 'NodeResource: Index'); } /** * testing node_resource Get */ public function testNewEndpointResourceNodeGet() { // Create and log in our privileged user. $this->privilegedUser = $this->drupalCreateUser(array( 'administer services', )); $this->drupalLogin($this->privilegedUser); $node = $this->drupalCreateNode(); $responseArray = $this->servicesGet($this->endpoint->path . '/node/' . $node->nid); $this->assertTrue($node->title == $responseArray['body']->title, t('Successfully received Node info'), 'NodeResource: Retrieve'); //Verify node not found. unset($node); $responseArray = $this->servicesGet($this->endpoint->path . '/node/99'); $this->assertTrue($responseArray['code'] == '404', t('Successfully was rejected to non existent node'), 'NodeResource: Retrieve'); } /** * testing node_resource Create */ public function testEndpointResourceNodeCreate() { // Create and log in our privileged user. $this->privilegedUser = $this->drupalCreateUser(array( 'administer services', 'bypass node access', )); $this->drupalLogin($this->privilegedUser); $node = array( 'title' => 'testing', 'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomString()))), 'type' => 'page', 'name' => $this->privilegedUser->name, 'language' => LANGUAGE_NONE, ); $responseArray = $this->servicesPost($this->endpoint->path . '/node', array('node' => $node)); $nodeResourceCreateReturn = $responseArray['body']; $this->assertTrue(isset($nodeResourceCreateReturn['nid']), t('Node was successfully created'), 'NodeResource: Create'); $newNode = node_load($nodeResourceCreateReturn['nid']); $this->assertTrue($newNode->title = $node['title'], t('Title was the same'), 'NodeResource: Create'); $this->assertTrue($newNode->body = $node['body'], t('Body was the same'), 'NodeResource: Create'); } /** * testing node_resource Created make ure it fails with no perms */ public function testEndpointResourceNodeCreateFail() { // Create and log in our privileged user. $this->privilegedUser = $this->drupalCreateUser(array( 'administer services', )); $this->drupalLogin($this->privilegedUser); $node = array( 'title' => 'testing', 'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomString()))), 'type' => 'page', 'name' => $this->privilegedUser->name, 'language' => LANGUAGE_NONE, ); $responseArray = $this->servicesPost($this->endpoint->path . '/node', array('node' => $node)); $this->assertTrue($responseArray['code'] == 401, t('User with not sufficient permissions cannot create node'), 'NodeResource: Create'); } /** * testing node_resource Validate missing Title */ public function testEndpointResourceNodeCreateMissingTitle() { // Create and log in our privileged user. $this->privilegedUser = $this->drupalCreateUser(array( 'administer services', 'bypass node access', )); $this->drupalLogin($this->privilegedUser); $node = array( 'title' => '', 'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomString()))), 'type' => 'page', 'name' => $this->privilegedUser->name, 'language' => LANGUAGE_NONE, ); $responseArray = $this->servicesPost($this->endpoint->path . '/node', array('node' => $node)); $nodeResourceUpdateReturn = $responseArray['body']; $this->assertTrue(strpos($responseArray['status'], 'Title field is required.'), t('Node was not created without title.'), 'NodeResource: Create'); } /** * testing node_resource Update */ public function testEndpointResourceNodeUpdate() { // Create and log in our privileged user. $this->privilegedUser = $this->drupalCreateUser(array( 'administer services', 'bypass node access', )); $this->drupalLogin($this->privilegedUser); $node = $this->drupalCreateNode(); $node_update = clone $node; $node_update->title = $this->randomName(); $node_update->body[LANGUAGE_NONE][0]['value'] = $this->randomName(); $responseArray = $this->servicesPut($this->endpoint->path . '/node/' . $node->nid, array('node' => $node_update)); // Load node not from cache. $nodeAfterUpdate = node_load($responseArray['body'], NULL, TRUE); $this->assertTrue(isset($nodeAfterUpdate->nid), t('Node was successfully updated'), 'NodeResource: Updated'); $this->assertEqual($nodeAfterUpdate->title, $node_update->title, t('Title is the same'), 'NodeResource: Update'); $this->assertEqual($nodeAfterUpdate->body[LANGUAGE_NONE][0]['value'], $node_update->body[LANGUAGE_NONE][0]['value'], t('Body is the same'), 'NodeResource: Update'); } /** * testing node_resource Update fail with no permissions */ public function testEndpointResourceNodeUpdatePermFail() { // Create and log in our privileged user. $this->privilegedUser = $this->drupalCreateUser(array( 'administer services', 'create page content', 'edit own page content', )); $this->drupalLogin($this->privilegedUser); // Create node from user no 1. $node = $this->drupalCreateNode(array('uid' => 1)); // Try to update this node with different user not // having permission to edit any story content. $node_update = clone $node; $node_update->title = $this->randomName(); $node_update->body[LANGUAGE_NONE][0]['value'] = $this->randomName(); $responseArray = $this->servicesPut($this->endpoint->path . '/node/' . $node->nid, array('node' => $node_update)); $this->assertTrue(strpos($responseArray['status'], 'Access denied for user'), t('Updating the node failed without needed permissions. This is good!'), 'NodeResource: Update'); } /** * testing node_resource Update verify missing title */ public function testEndpointResourceNodeUpdateMissingTitle() { // Create and log in our privileged user. $this->privilegedUser = $this->drupalCreateUser(array( 'administer services', 'bypass node access', )); $this->drupalLogin($this->privilegedUser); $node = $this->drupalCreateNode(); $node_update = array( 'title' => '', 'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomString()))), 'name' => $this->privilegedUser->name, 'type' => 'page', ); $responseArray = $this->servicesPut($this->endpoint->path . '/node/' . $node->nid, array('node' => $node_update)); $this->assertTrue(strpos($responseArray['status'], 'Title field is required.'), t('Node was not updated without title.'), 'NodeResource: Update'); } /** * testing node_resource Delete */ public function testEndpointResourceNodeDelete() { // Create and log in our privileged user. $this->privilegedUser = $this->drupalCreateUser(array( 'administer services', 'bypass node access', )); $this->drupalLogin($this->privilegedUser); $node = $this->drupalCreateNode(); $data = ''; $responseArray = $this->servicesDelete($this->endpoint->path . '/node/' . $node->nid, $data); $deleted_node = node_load($node->nid, NULL, TRUE); $this->assertTrue(empty($deleted_node), t('Node was deleted.'), 'NodeResource: Deleted'); $responseArray = $this->servicesDelete($this->endpoint->path . '/node/' . $node->nid, $data); $this->assertFalse($responseArray['code'] == 200, t('Node was deleted. It shoudlnt have been because it doesnt exist'), 'NodeResource: Deleted'); } }