function ServicesResourceTaxonomyTests::testVocabularyGetTree in Services 6.3
Same name and namespace in other branches
- 7.3 tests/functional/ServicesResourceTaxonomyTests.test \ServicesResourceTaxonomyTests::testVocabularyGetTree()
Test taxonomy vocabulary getTree method.
File
- tests/
functional/ ServicesResourceTaxonomyTests.test, line 187
Class
- ServicesResourceTaxonomyTests
- Run test cases for the endpoint with no authentication turned on.
Code
function testVocabularyGetTree() {
$path = $this->endpoint->path;
$vocabulary = $this
->createVocabulary();
$vid = $vocabulary['vid'];
$part_tree_parent = 0;
// Generate taxonomy tree.
for ($i = 0; $i < 10; $i++) {
$parent = rand(0, 1) * db_result(db_query('SELECT tid FROM {term_data} WHERE vid = %d ORDER BY RAND() LIMIT 1', $vid));
$edit = array(
'name' => $this
->randomName(),
'parent' => $parent,
'vid' => $vid,
);
taxonomy_save_term($edit);
if (!empty($parent)) {
$part_tree_parent = $parent;
}
}
// Add term as grandchild to test maxdepth.
$children = taxonomy_get_children($part_tree_parent);
$edit = array(
'name' => $this
->randomName(),
'parent' => key($children),
'vid' => $vid,
);
taxonomy_save_term($edit);
// Compare full tree.
$vocabulary_tree = taxonomy_get_tree($vid);
$response = $this
->servicesPost($path . '/taxonomy_vocabulary/getTree', array(
'vid' => $vid,
));
$vocabulary_tree_response = $response['body'];
$this
->assertEqual($vocabulary_tree, $vocabulary_tree_response, t('Vocabulary full tree received properly.'), 'TaxonomyVocabularyResource: getTree');
// Compare part tree.
$vocabulary_tree = taxonomy_get_tree($vid, $part_tree_parent);
$response = $this
->servicesPost($path . '/taxonomy_vocabulary/getTree', array(
'vid' => $vid,
'parent' => $part_tree_parent,
));
$vocabulary_tree_response = $response['body'];
$this
->assertEqual($vocabulary_tree, $vocabulary_tree_response, t('Vocabulary part tree received properly.'), 'TaxonomyVocabularyResource: getTree');
// Compare part tree with maxdepth.
$vocabulary_tree = taxonomy_get_tree($vid, $part_tree_parent, -1, 1);
$response = $this
->servicesPost($path . '/taxonomy_vocabulary/getTree', array(
'vid' => $vid,
'parent' => $part_tree_parent,
'maxdepth' => 1,
));
$vocabulary_tree_response = $response['body'];
$this
->assertEqual($vocabulary_tree, $vocabulary_tree_response, t('Vocabulary part tree with depth received properly.'), 'TaxonomyVocabularyResource: getTree');
}