You are here

function FieldTokensGeneralTestCase::testHiddenFields in Field tokens 7

Test that hidden fields alongside a Field tokens rendered field do not cause errors to be thrown.

See also

#2543548

File

tests/field_tokens.test, line 62
Tests for the Field tokens module.

Class

FieldTokensGeneralTestCase
Class FieldTokensGeneralTestCase

Code

function testHiddenFields() {

  // Create a second image field.
  $field_name = strtolower($this
    ->randomName());
  $this
    ->createImageField($field_name, $this->content_type);

  // Set second image field to hidden.
  $edit = array(
    "fields[{$field_name}][type]" => 'hidden',
  );
  $this
    ->drupalPost("admin/structure/types/manage/{$this->content_type}/display", $edit, t('Save'));

  // Create node with two images attached.
  $test_image = current($this
    ->drupalGetTestFiles('image'));
  $edit = array(
    'title' => $this
      ->randomName(),
  );
  $edit['files[' . $this->field_name . '_' . LANGUAGE_NONE . '_0]'] = drupal_realpath($test_image->uri);
  $edit['files[' . $field_name . '_' . LANGUAGE_NONE . '_0]'] = drupal_realpath($test_image->uri);
  $this
    ->drupalPost('node/add/' . $this->content_type, $edit, t('Save'));

  // Retrieve ID of the newly created node from the current URL.
  $matches = array();
  preg_match('/node\\/([0-9]+)/', $this
    ->getUrl(), $matches);
  $nid = $matches[1];

  // Execute token_replace() with a Field token.
  $node = node_load($nid);
  $token = "[node:{$this->field_name}-formatted:0:image]";
  token_replace($token, array(
    'node' => $node,
  ));
}