You are here

function restful_test_create_vocabulary_and_terms in RESTful 7.2

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

Helper function; Create a vocabulary and terms.

Parameters

string $machine_name: The machine name of the vocabulary. Defaults to 'test_vocab'.

bool $create_vocab: Determines if to create a vocabulary, or use an existing one.

Return value

int The newly created vocabulary ID.

2 calls to restful_test_create_vocabulary_and_terms()
RestfulAutoCompleteTestCase::testAutocomplete in tests/RestfulAutoCompleteTestCase.test
Test the autocomplete functionality.
restful_test_add_fields in tests/modules/restful_test/restful_test.module
Helper function to add common fields.

File

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

Code

function restful_test_create_vocabulary_and_terms($machine_name = 'test_vocab', $create_vocab = TRUE) {
  if ($create_vocab) {
    $vocabulary = (object) array(
      'name' => 'Tags test',
      'description' => '',
      'machine_name' => $machine_name,
    );
    taxonomy_vocabulary_save($vocabulary);
  }
  else {
    $vocabulary = taxonomy_vocabulary_machine_name_load($machine_name);
  }
  $vid = $vocabulary->vid;

  // Create three terms.
  foreach (array(
    1,
    2,
    3,
  ) as $id) {
    $values = array(
      'name' => 'term' . $id,
      'vid' => $vid,
    );
    $term = entity_create('taxonomy_term', $values);
    taxonomy_term_save($term);
  }
  return $vid;
}