function ServicesResourceTaxonomyTests::testVocabularyGetTree in Services 7.3
Same name and namespace in other branches
- 6.3 tests/functional/ServicesResourceTaxonomyTests.test \ServicesResourceTaxonomyTests::testVocabularyGetTree()
Test taxonomy vocabulary getTree method.
File
- tests/
functional/ ServicesResourceTaxonomyTests.test, line 282 - Call the endpoint tests when no authentication is being used.
Class
- ServicesResourceTaxonomyTests
- Taxonomy resource test class.
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++) {
$query = db_select('taxonomy_term_data', 'td')
->fields('td', array(
'tid',
))
->condition('td.vid', $vid)
->orderRandom()
->range(0, 1);
$tid = $query
->execute()
->fetchField();
$parent = rand(0, 1) * $tid;
$edit = (object) array(
'name' => $this
->randomName(),
'parent' => $parent,
'vid' => $vid,
);
taxonomy_term_save($edit);
if (!empty($parent)) {
$part_tree_parent = $parent;
}
}
// Add term as grandchild to test maxdepth.
$children = taxonomy_get_children($part_tree_parent);
$edit = (object) array(
'name' => $this
->randomName(),
'parent' => key($children),
'vid' => $vid,
);
taxonomy_term_save($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, 'Vocabulary full tree received properly.', 'TaxonomyVocabularyResource: getTree');
// Compare full tree with loading of full entities.
$vocabulary_tree = taxonomy_get_tree($vid, 0, NULL, TRUE);
$response = $this
->servicesPost($path . '/taxonomy_vocabulary/getTree', array(
'vid' => $vid,
'load_entities' => 1,
));
$vocabulary_tree_response = $response['body'];
$this
->assertEqual($vocabulary_tree, $vocabulary_tree_response, 'Vocabulary full tree with loaded entities 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, 'Vocabulary part tree received properly.', 'TaxonomyVocabularyResource: getTree');
// Compare part tree with maxdepth = 1.
$vocabulary_tree = taxonomy_get_tree($vid, $part_tree_parent, 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, 'Vocabulary part tree with depth received properly.', 'TaxonomyVocabularyResource: getTree');
// Compare part tree with maxdepth = 1 and loading of full entities.
$vocabulary_tree = taxonomy_get_tree($vid, $part_tree_parent, 1, TRUE);
$response = $this
->servicesPost($path . '/taxonomy_vocabulary/getTree', array(
'vid' => $vid,
'parent' => $part_tree_parent,
'maxdepth' => 1,
'load_entities' => 1,
));
$vocabulary_tree_response = $response['body'];
$this
->assertEqual($vocabulary_tree, $vocabulary_tree_response, 'Vocabulary part tree with depth and loaded entities received properly.', 'TaxonomyVocabularyResource: getTree');
}