You are here

function ServicesResourceNodeTaxonomytests::testServicesTaxonomyNode in Services 7.3

Test that hook_node_$op implementations work correctly.

Save & edit a node and assert that taxonomy terms are saved/loaded properly.

File

tests/functional/ServicesResourceNodeTests.test, line 554
Call the endpoint tests when no authentication is being used.

Class

ServicesResourceNodeTaxonomytests
Test create node with taxonomy terms attached.

Code

function testServicesTaxonomyNode() {

  // Create two taxonomy terms.
  $term1 = $this
    ->createTerm($this->vocabulary);
  $term2 = $this
    ->createTerm($this->vocabulary);
  $field_name = $this->instance['field_name'];

  // Post an article.
  $edit = array();
  $langcode = LANGUAGE_NONE;
  $edit['title'] = $this
    ->randomName();
  $edit["body[{$langcode}][0][value]"] = $this
    ->randomName();
  $edit[$field_name][$langcode][0] = $term1->tid;
  $edit['type'] = 'page';
  $edit['name'] = $this->admin_user->name;
  $edit['language'] = LANGUAGE_NONE;
  $responseArray = $this
    ->servicesPost($this->endpoint->path . '/node', array(
    'node' => $edit,
  ));
  $nodeResourceCreateReturn = $responseArray['body'];
  $this
    ->assertTrue(isset($nodeResourceCreateReturn['nid']), 'Node was successfully created', 'NodeResource: Create');
  $newNode = node_load($nodeResourceCreateReturn['nid']);
  $this
    ->assertTrue($newNode->{$field_name}[$langcode][0]['tid'] = $term1->tid, 'Term was the same', 'Taxonomy: Create');

  // Edit the node with a different term.
  $edit[$field_name][$langcode][0] = $term2->tid;
  $responseArray = $this
    ->servicesPost($this->endpoint->path . '/node', array(
    'node' => $edit,
  ));
  $nodeResourceCreateReturn = $responseArray['body'];
  $this
    ->assertTrue(isset($nodeResourceCreateReturn['nid']), 'Node was successfully created', 'NodeResource: Create');
  $newNode = node_load($nodeResourceCreateReturn['nid']);
  $this
    ->assertTrue($newNode->{$field_name}[$langcode][0]['tid'] = $term2->tid, 'Term was the same', 'Taxonomy: updated');
}