function TaxonomyTermFunctions::testTermsFunctions in SimpleTest 5
Same name and namespace in other branches
- 6 tests/taxonomy.module.test \TaxonomyTermFunctions::testTermsFunctions()
File
- tests/
taxonomy.module.test, line 89
Class
Code
function testTermsFunctions() {
//preparing data
// vocabulary, hierarchy -> disabled, related terms = on;
$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);
$relation = 1;
$edit['name'] = $name;
taxonomy_save_vocabulary($edit);
// create term
$termname = $this
->randomName(20);
$termdesc = $this
->randomName(200);
$termweight = rand(-9, 9);
$randSyn = rand(0, 9);
$synonyms = array();
for ($i = 0; $i < $randSyn; $i++) {
$synonyms[] = $this
->randomName(20);
}
$termsyn = implode("\n", $synonyms);
$data = array(
'name' => $termname,
'description' => $termdesc,
'weight' => $termweight,
'synonyms' => $termsyn,
'vid' => $edit['vid'],
'tid' => 0,
'relations' => 0,
);
taxonomy_save_term($data);
// retrieve term and check all fields
$_tArray = taxonomy_get_term_by_name($termname);
$getTerm = $_tArray[0];
$checkField = array(
'name',
'description',
'weight',
'vid',
);
foreach ($checkField as $v) {
$this
->assertEqual($data[$v], $getTerm->{$v}, "Checking value of the term ({$v})");
}
$getSynonyms = taxonomy_get_synonyms($getTerm->tid);
$this
->assertEqual(sort($synonyms), sort($getSynonyms), 'Checking synonyms');
// creating related terms
$relations = array();
$staryTid = $getTerm->tid;
$relations[] = $staryTid;
$termname = $this
->randomName(20);
$data = array(
'name' => $termname,
'description' => '',
'weight' => 0,
'synonyms' => 0,
'vid' => $vid,
'tid' => 0,
'relations' => array(
$staryTid,
),
);
taxonomy_save_term($data);
$_tArray = taxonomy_get_term_by_name($termname);
$getTerm = $_tArray[0];
$relations[] = $getTerm->tid;
// Creating another term related to 2 terms above;
$termname = $this
->randomName(20);
$data = array(
'name' => $termname,
'description' => '',
'weight' => 0,
'synonyms' => 0,
'vid' => $vid,
'tid' => 0,
'relations' => array(
$staryTid,
$getTerm->tid,
),
);
taxonomy_save_term($data);
$_tArray = taxonomy_get_term_by_name($termname);
$getTerm = $_tArray[0];
// check related terms
$related = taxonomy_get_related($getTerm->tid);
foreach ($relations as $rTid) {
$this
->assertTrue(array_key_exists($rTid, $related), "Checking relations ({$rTid})");
}
// delete vocabulary
$edit['name'] = 0;
taxonomy_save_vocabulary($edit);
}