function TaxonomyAccessTestCase::createTerm in Taxonomy Access Control 7
Creates a new term in the specified vocabulary.
Parameters
string $machine_name: A machine-safe name.
object $vocab: A vocabulary object.
int|null $parent: (optional) The tid of the parent term, if any. Defaults to NULL.
Return value
object The taxonomy term object.
4 calls to TaxonomyAccessTestCase::createTerm()
- TaxonomyAccessConfigTest::setUp in ./
taxonomy_access.test - Sets up a Drupal site for running functional and integration tests.
- TaxonomyAccessConfigTest::testTermWithChildren in ./
taxonomy_access.test - Tests adding a term configuration with children.
- TaxonomyAccessNodeGrantTest::setUp in ./
taxonomy_access.test - Sets up a Drupal site for running functional and integration tests.
- TaxonomyAccessTermGrantTest::setUp in ./
taxonomy_access.test - Sets up a Drupal site for running functional and integration tests.
File
- ./
taxonomy_access.test, line 118 - Automated tests for the Taxonomy Access Control module.
Class
- TaxonomyAccessTestCase
- Provides a base test class and helper methods for automated tests.
Code
function createTerm($machine_name, $vocab, $parent = NULL) {
$term = new stdClass();
$term->name = $machine_name;
$term->description = $machine_name;
// Use the first available text format.
$term->format = db_query_range('SELECT format FROM {filter_format}', 0, 1)
->fetchField();
$term->vid = $vocab->vid;
$term->vocabulary_machine_name = $vocab->machine_name;
if (!is_null($parent)) {
$term->parent = $parent;
}
taxonomy_term_save($term);
return $term;
}