You are here

function FaqTestCase::setupTaxonomy in Frequently Asked Questions 6

Same name and namespace in other branches
  1. 7.2 faq.test \FaqTestCase::setupTaxonomy()
  2. 7 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
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…

File

./faq.test, line 94
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->taxonomy = array();
  $this->taxonomy['name'] = $this
    ->randomName(8);

  // Create taxonomy vocabulary name
  $this->taxonomy['description'] = $this
    ->randomName(64);
  $this->taxonomy['nodes[faq]'] = '1';

  // Assign vocab to FAQ node types
  $this->taxonomy['tags'] = '1';

  // Users may create tags
  $this->taxonomy['multiple'] = '1';

  // may have more than one tag
  $this->taxonomy['required'] = '1';

  // but minimum 1 tag
  $this
    ->drupalPost('admin/content/taxonomy/add/vocabulary', $this->taxonomy, t('Save'));
  $this
    ->assertText(t('Created new vocabulary @name', array(
    '@name' => $this->taxonomy['name'],
  )));
  $this
    ->assertText(t('FAQ'));

  // Add term
  // Click the last occurrence of the link.
  $this
    ->clickLink(t('add terms'), substr_count($this
    ->drupalGetContent(), 'add terms') - 1);
  $this
    ->assertText(t('Add term to @name', array(
    '@name' => $this->taxonomy['name'],
  )));
  $url = parse_url($this
    ->getUrl());
  if (empty($url['query'])) {
    $array = split('/', $url['path']);
    $this->taxonomy['id'] = $array[4];
  }
  else {
    $array = split('/', $url['query']);
    $this->taxonomy['id'] = $array[3];
  }
  $this
    ->pass(var_export($array, TRUE));
  $url = $this
    ->getUrl();
  $this->term = array();
  $this->term['name'] = $this
    ->randomName(8);

  // Create taxonomy vocabulary name
  $this->term['description'] = $this
    ->randomName(64);
  $this
    ->drupalPost($url, $this->term, t('Save'));
  $this
    ->assertText(t('Created new term @name', array(
    '@name' => $this->term['name'],
  )));
}