You are here

function FaqTestCase::setupTaxonomy in Frequently Asked Questions 7

Same name and namespace in other branches
  1. 6 faq.test \FaqTestCase::setupTaxonomy()
  2. 7.2 faq.test \FaqTestCase::setupTaxonomy()

Set up the taxonomy - all vocabularies and stuff Values also stored in protected variable $tax

1 call to FaqTestCase::setupTaxonomy()
FaqTestCase::setUp in ./faq.test
Implementation of setUp().

File

./faq.test, line 100
Test FAQ functionality Base test class. All tests inherits this one. Hugely based on code from the test file block.test by boombatower

Class

FaqTestCase
Base class that is extended by test cases

Code

function setupTaxonomy() {

  // Create vocabulary.
  $this->vocabulary = $vocabulary = new stdClass();
  $vocabulary->name = $this
    ->randomName(8);
  $vocabulary->description = $this
    ->randomName(64);
  $vocabulary->machine_name = drupal_strtolower($this
    ->randomName());
  $vocabulary->help = '';
  $vocabulary->nodes = array(
    'faq' => 'faq',
  );
  $vocabulary->weight = mt_rand(0, 10);
  taxonomy_vocabulary_save($vocabulary);
  $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);
}