You are here

function TaxonomyTermFunctions::testTermsFunctionsSingleHierarchy in SimpleTest 5

Same name and namespace in other branches
  1. 6 tests/taxonomy.module.test \TaxonomyTermFunctions::testTermsFunctionsSingleHierarchy()

File

tests/taxonomy.module.test, line 155

Class

TaxonomyTermFunctions

Code

function testTermsFunctionsSingleHierarchy() {

  //preparing data

  // vocabulary hierarchy->single
  $edit = array();
  $_t = array(
    'vid',
    'name',
    'description',
    'help',
    'relations',
    'hierarchy',
    'multiple',
    'required',
    'tags',
    'module',
    'weight',
    'nodes',
  );
  foreach ($_t as $key) {
    $edit[$key] = 0;
  }

  // create vocab
  $name = $this
    ->randomName(20);
  $edit['hierarchy'] = 1;
  $edit['name'] = $name;
  taxonomy_save_vocabulary($edit);

  // create 1st term
  $termname = $this
    ->randomName(20);
  $data = array(
    'name' => $termname,
    'description' => '',
    'weight' => 0,
    'synonyms' => '',
    'vid' => $edit['vid'],
    'tid' => 0,
    'relations' => 0,
  );
  taxonomy_save_term($data);
  $_tArray = taxonomy_get_term_by_name($termname);
  $parent = $_tArray[0];

  // create 2nd term as a child
  $termname = $this
    ->randomName(20);
  $data = array(
    'name' => $termname,
    'description' => '',
    'weight' => 0,
    'synonyms' => '',
    'vid' => $edit['vid'],
    'tid' => 0,
    'relations' => 0,
    'parent' => array(
      $parent->tid,
    ),
  );
  taxonomy_save_term($data);
  $_tArray = taxonomy_get_term_by_name($termname);
  $children = $_tArray[0];

  // check hierarchy
  $getChildren = taxonomy_get_children($parent->tid);
  $getParent = taxonomy_get_parents($children->tid);
  $this
    ->assertEqual($parent, $getParent[$parent->tid], 'Checking parents');
  $this
    ->assertEqual($children, $getChildren[$children->tid], 'Checking children');

  // delete vocabulary
  $edit['name'] = 0;
  taxonomy_save_vocabulary($edit);
}