You are here

private function TaxonomyEdgeTreeTestCase::treeInit in Taxonomy Edge 8

Same name and namespace in other branches
  1. 6 tests/tree.test \TaxonomyEdgeTreeTestCase::treeInit()
  2. 7 tests/tree.test \TaxonomyEdgeTreeTestCase::treeInit()
1 call to TaxonomyEdgeTreeTestCase::treeInit()
TaxonomyEdgeTreeTestCase::setUp in tests/tree.test

File

tests/tree.test, line 329

Class

TaxonomyEdgeTreeTestCase
@file

Code

private function treeInit() {

  // Create a vocabulary.
  $vocabulary = new stdClass();
  $vocabulary->name = 'taxonomy_edge_test1';
  $vocabulary->description = 'taxonomy_edge_test1';
  $vocabulary->machine_name = 'taxonomy_edge_test1' . rand(0, 10000);
  $vocabulary->help = '';
  taxonomy_vocabulary_save($vocabulary);
  $this->vocabulary = $vocabulary;
  $tree = array();
  $tree[] = "test1";
  $tree[] = "test1/test2";
  $tree[] = "test1/test2/test3";
  $tree[] = "test1/test4";
  $tree[] = "test1/test4/test5";
  $tree[] = "sub1";
  $tree[] = "sub2";
  $tree[] = "sub3";
  $terms = array();
  $weight = 0;
  foreach ($tree as $path) {
    $parts = explode('/', $path);
    $name = array_pop($parts);
    $parent = array_pop($parts);
    $term = new stdClass();
    $term->name = $name;
    $term->vid = $vocabulary->vid;
    $term->parent = $parent ? $terms[$parent]->tid : 0;
    $term->weight = $weight++;
    taxonomy_term_save($term);
    $terms[$name] = $term;
  }
  $this->terms = $terms;
}