You are here

function ContentTaxonomyTestCase::createTerms in Content Taxonomy 6

Same name and namespace in other branches
  1. 6.2 tests/content_taxonomy.test \ContentTaxonomyTestCase::createTerms()

helper function to create a vocabulary and terms

3 calls to ContentTaxonomyTestCase::createTerms()
ContentTaxonomyAutocompletePermissionsTest::testAutocomplete in tests/content_taxonomy.test
ContentTaxonomyAutocompleteTest::testAutocomplete in tests/content_taxonomy.test
ContentTaxonomyTest::testContentTaxonomySaving in tests/content_taxonomy.test

File

tests/content_taxonomy.test, line 21

Class

ContentTaxonomyTestCase
Base Class for testing Content Taxonomy extends the ContentCrudTestCase Class from CCK, which provides many useful helper functions

Code

function createTerms($count = 1) {
  $edit['name'] = $this
    ->randomName(200);
  $edit['hierarchy'] = 2;

  // Hierarchy 0,1,2
  $edit['multiple'] = 1;

  // multiple 0,1
  $edit['required'] = 0;

  // required 0,1
  $edit['relations'] = 0;
  $edit['tags'] = 1;

  // exec save function
  taxonomy_save_vocabulary($edit);
  $vid = $edit['vid'];
  for ($i = 0; $i < $count; $i++) {

    // create term
    $termname = $this
      ->randomName(20);
    $data = array(
      'name' => $termname,
      'vid' => $vid,
    );
    taxonomy_save_term($data);
    $terms[] = taxonomy_get_term($data['tid']);
  }
  return $terms;
}