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', 'administer nodes', )); $this->drupalLogin($this->privilegedUser); $node = array( 'title' => 'testing', 'body' => 'bodytest', 'type' => 'story', 'name' => $this->privilegedUser->name, ); $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'); if (isset($nodeResourceCreateReturn['nid'])) { $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' => 'bodytest', 'type' => 'story', 'name' => $this->privilegedUser->name, ); $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', 'administer nodes', )); $this->drupalLogin($this->privilegedUser); $node = array( 'title' => '', 'body' => 'bodytest', 'name' => $this->privilegedUser->name, 'type' => 'page', ); $responseArray = $this->servicesPost($this->endpoint->path . '/node', array('node' => $node)); $nodeResourceUpdateReturn = $responseArray['body']; $nodeAfterUpdate = node_load($nodeResourceUpdateReturn); $this->assertTrue(strpos($responseArray['status'], 'Title field is required.'), t('Node was not created without title. '), 'NodeResource: Created'); } /** * testing node_resource Update */ 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' => 'story', 'name' => $this->privilegedUser->name, ); $responseArray = $this->servicesPut($this->endpoint->path . '/node/' . $node->nid, array('node' => $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'); } } /** * 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 story content', 'edit own story 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 = array( 'title' => 'testing', 'body' => 'bodytest', 'type' => 'story', ); $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', 'administer nodes', )); $this->drupalLogin($this->privilegedUser); $node = $this->drupalCreateNode(); $node_update = array( 'title' => '', 'body' => 'bodytest', 'name' => $this->privilegedUser->name, 'type' => 'story', ); $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', 'administer nodes', )); $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'); } }