You are here

function HierarchicalTermFormatterTestCase::createNode in Hierarchical Term Formatter 7

1 call to HierarchicalTermFormatterTestCase::createNode()
HierarchicalTermFormatterTestCase::testVocabTerms in ./hierarchical_term_formatter.test
Test that vocab and terms are created.

File

./hierarchical_term_formatter.test, line 110
Tests for Field Multiple Limit, based on examples from field.test

Class

HierarchicalTermFormatterTestCase
Test the field formatter settings work.

Code

function createNode($random = FALSE) {
  $langcode = LANGUAGE_NONE;

  // Add a page with all or the the test terms selected.
  $this
    ->drupalGet('node/add/page');

  // Create node.
  $title_key = "title";
  $body_key = "body[{$langcode}][0][value]";
  $edit = array();
  $edit[$title_key] = $this
    ->randomName(8);
  $edit[$body_key] = $this
    ->randomName(16);

  // Add all our test terms.
  $this->random_terms = array();
  $terms = $this->terms['tids'];

  // For some tests we don't want all terms selected.
  if ($random) {
    foreach ($terms as $tid) {

      // Flip a coin to keep or unset term.
      if (rand(0, 1) === 1) {
        $this->random_terms[$tid] = $tid;
      }
    }
    $terms = $this->random_terms;
  }
  $edit["{$this->field_name}[{$langcode}][]"] = $terms;
  $this
    ->drupalPost('node/add/page', $edit, t('Save'));

  // Check that the test node exists in the database.
  $node = $this
    ->drupalGetNodeByTitle($edit[$title_key]);
  $this->node_id = $node->nid;
  $this
    ->assertTrue($node, 'Test node found in database.');
}