function TaxonomyVocabularyFunctions::testVocabularyFunctions in SimpleTest 5
Same name and namespace in other branches
- 6 tests/taxonomy.module.test \TaxonomyVocabularyFunctions::testVocabularyFunctions()
File
- tests/
taxonomy.module.test, line 13
Class
Code
function testVocabularyFunctions() {
//preparing data
$vid = 0;
$name = $this
->randomName(200);
$description = $this
->randomName(200);
$help = $this
->randomName(200);
$hierarchy = rand(0, 2);
// Hierarchy 0,1,2
$multiple = rand(0, 1);
// multiple 0,1
$required = rand(0, 1);
// required 0,1
$relations = rand(0, 1);
$tags = rand(0, 1);
$weight = rand(-9, 9);
$module = 'taxonomy';
$nodesList = array_keys(node_get_types());
$maxNodes = rand(1, count($nodesList));
$nodes = array();
for ($i = 0; $i < $maxNodes; $i++) {
$nodes[$nodesList[$i]] = $nodesList[$i];
$nodesBak[] = $nodesList[$i];
}
$_t = array(
'vid',
'name',
'description',
'help',
'relations',
'hierarchy',
'multiple',
'required',
'tags',
'module',
'weight',
'nodes',
);
$edit = array();
foreach ($_t as $key) {
$edit[$key] = ${$key};
}
// exec save function
taxonomy_save_vocabulary($edit);
//after save we use $nodesBak
sort($nodesBak);
$edit['nodes'] = $nodesBak;
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $voc) {
if ($voc->name == $name) {
$vid = $voc->vid;
break;
}
}
$edit['vid'] = $vid;
// get data using function
$getEdit = taxonomy_get_vocabulary($vid);
foreach ($getEdit as $key => $value) {
$this
->assertEqual($value, $edit[$key], "Checking value of {$key}");
}
// delete vocabulary
// to avoid exception messages we create array with empty fields
$deleteArray = array();
foreach ($getEdit as $key => $v) {
$deleteArray[$key] = 0;
}
$deleteArray['vid'] = $vid;
taxonomy_save_vocabulary($deleteArray);
// checking if we deleted voc.
$vocabularies = taxonomy_get_vocabularies();
$vid = 0;
foreach ($vocabularies as $voc) {
if ($voc->name == $name) {
$vid = $voc->vid;
break;
}
}
$this
->assertEqual($vid, 0, "Deleted vocabulary ({$vid})");
}