function Faq_AskTestCase::setupTaxonomy in FAQ_Ask 7
Set up the taxonomy - all vocabularies and stuff Values also stored in protected variable $tax
2 calls to Faq_AskTestCase::setupTaxonomy()
- Faq_AskAccessTestClass::testFaqAccess in ./
faq_ask.test - Faq_AskTestCase::setUp in ./
faq_ask.test - Implementation of setUp(). Array of additional modules to be installed are passed as parameter
File
- ./
faq_ask.test, line 234 - Test Faq_Ask functionality Base test class. All tests inherits this one Hugely based on code from the test file block.test by boombatower
Class
- Faq_AskTestCase
- Base class that is extended by test cases
Code
function setupTaxonomy() {
$old_vocab = '';
if (isset($this->vocabulary) && $this->vocabulary) {
$old_vocab = $this->vocabulary;
}
// Create vocabulary.
$this->vocabulary = $vocabulary = new stdClass();
$vocabulary->name = $this
->randomName(8);
$vocabulary->description = $this
->randomName(64);
$vocabulary->machine_name = drupal_strtolower($vocabulary->name);
$vocabulary->help = '';
$vocabulary->nodes = array(
'faq' => 'faq',
);
$vocabulary->weight = mt_rand(0, 10);
taxonomy_vocabulary_save($vocabulary);
$this
->pass('<pre>' . print_r($vocabulary, TRUE) . '</pre>');
$field = array(
'field_name' => 'taxonomy_' . $this->vocabulary->machine_name,
'type' => 'taxonomy_term_reference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $this->vocabulary->machine_name,
'parent' => 0,
),
),
),
);
field_create_field($field);
$this->instance = array(
'field_name' => 'taxonomy_' . $this->vocabulary->machine_name,
'bundle' => 'faq',
'entity_type' => 'node',
'widget' => array(
'type' => 'taxonomy_autocomplete',
),
'display' => array(
'default' => array(
'type' => 'taxonomy_term_reference_link',
),
),
);
field_create_instance($this->instance);
// Add term
// Click the last occurrence of the link.
$this->term = $term = new stdClass();
$term->name = $this
->randomName(8);
$term->description = $this
->randomName(64);
// Use the first available text format.
$term->format = db_query_range('SELECT format FROM {filter_format}', 0, 1)
->fetchField();
$term->vid = $vocabulary->vid;
taxonomy_term_save($term);
$this->term1 = new stdClass();
$this->term1->name = 'term1-' . $this
->randomName(8);
// Create taxonomy vocabulary name
$this->term1->description = $this
->randomName(64);
$this->term1->format = $term->format;
$this->term1->vid = $vocabulary->vid;
taxonomy_term_save($this->term1);
$this->term2 = new stdClass();
$this->term2->name = 'term2-' . $this
->randomName(8);
// Create taxonomy vocabulary name
$this->term2->description = $this
->randomName(64);
$this->term2->format = $term->format;
$this->term2->vid = $vocabulary->vid;
taxonomy_term_save($this->term1);
}