You are here

function TaxonomyTermFunctions::testTermsFunctionsMultipleHierarchy in SimpleTest 6

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

File

tests/taxonomy.module.test, line 187

Class

TaxonomyTermFunctions

Code

function testTermsFunctionsMultipleHierarchy() {

  //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;
  }
  $name = $this
    ->randomName(20);
  $edit['hierarchy'] = 1;
  $edit['name'] = $name;
  taxonomy_save_vocabulary($edit);

  // create 1st term
  $parent = array();
  $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]->tid;

  // create 2nd 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]->tid;

  // create 3rd 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,
    ),
  );
  taxonomy_save_term($data);
  $_tArray = taxonomy_get_term_by_name($termname);
  $children = $_tArray[0];
  $getParent = taxonomy_get_parents($children->tid);
  foreach ($parent as $p) {
    $this
      ->assertTrue(array_key_exists($p, $getParent), "Checking parents ({$p})");

    //$this->assertEqual($parent,$getParent[$parent->tid], 'Checking parents');
  }

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