You are here

function restful_test_create_node_with_tags in RESTful 7

Same name and namespace in other branches
  1. 7.2 tests/modules/restful_test/restful_test.module \restful_test_create_node_with_tags()

Helper function; Create a node with taxonomy terms.

Return value

object The saved node.

2 calls to restful_test_create_node_with_tags()
RestfulSimpleJsonTestCase::testSimpleJson in tests/RestfulSimpleJsonTestCase.test
Test the Simple JSON formatter.
RestfulViewModeAndFormatterTestCase::testViewModeIntegration in tests/RestfulViewModeAndFormatterTestCase.test
Test the view mode integration.

File

tests/modules/restful_test/restful_test.module, line 416
Helper module for testing the RESTful module.

Code

function restful_test_create_node_with_tags() {
  $values = array(
    'type' => 'article',
  );
  $node = entity_create('node', $values);
  $vocabulary = taxonomy_vocabulary_machine_name_load('tags');

  // Create a random number of tags for the created node.
  for ($index = 0; $index < mt_rand(1, 10); $index++) {
    $term = (object) array(
      'vid' => $vocabulary->vid,
      'name' => 'term ' . $vocabulary->vid . '::' . $index,
    );
    taxonomy_term_save($term);
    $terms[] = $term;
    $node->field_tags[LANGUAGE_NONE][$index]['tid'] = $term->tid;
  }
  node_save($node);
  return $node;
}