You are here

function dsNodeTests::testDSFieldTemplate in Display Suite 7

Same name and namespace in other branches
  1. 7.2 tests/ds.entities.test \dsNodeTests::testDSFieldTemplate()

Tests on field templates.

File

tests/ds.entities.test, line 299
Entities tests

Class

dsNodeTests
@file Entities tests

Code

function testDSFieldTemplate() {

  // Get a node.
  $node = $this
    ->entitiesTestSetup('hidden');
  $body_field = $node->body[$node->language][0]['value'];

  // -------------------------
  // Default theming function.
  // -------------------------
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"field field-name-body field-type-text-with-summary field-label-hidden\"><div class=\"field-items\"><div class=\"field-item even\" property=\"content:encoded\"><p>" . $body_field . "</p>\n</div></div></div>");
  $this
    ->entitiesSetLabelClass('above');
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"field field-name-body field-type-text-with-summary field-label-above\"><div class=\"field-label\">Body:&nbsp;</div><div class=\"field-items\"><div class=\"field-item even\" property=\"content:encoded\"><p>" . $body_field . "</p>\n</div></div></div>");
  $this
    ->entitiesSetLabelClass('above', 'My body');
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"field field-name-body field-type-text-with-summary field-label-above\"><div class=\"field-label\">My body:&nbsp;</div><div class=\"field-items\"><div class=\"field-item even\" property=\"content:encoded\"><p>" . $body_field . "</p>\n</div></div></div>");
  $this
    ->entitiesSetLabelClass('hidden', '', 'test_field_class');
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"field field-name-body field-type-text-with-summary field-label-hidden test_field_class\"><div class=\"field-items\"><div class=\"field-item even\" property=\"content:encoded\"><p>" . $body_field . "</p>\n</div></div></div>");
  $this
    ->entitiesClearFieldSettings();

  // -----------------------
  // Reset theming function.
  // -----------------------
  $edit = array(
    'additional_settings[fs1][ft-default]' => 'theme_ds_field_reset',
  );
  $this
    ->drupalPost('admin/structure/ds/extras', $edit, t('Save configuration'));
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <p>" . $body_field . "</p>");
  $this
    ->entitiesSetLabelClass('above');
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"label-above\">Body:&nbsp;</div><p>" . $body_field . "</p>");
  $this
    ->entitiesSetLabelClass('inline');
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"label-inline\">Body:&nbsp;</div><p>" . $body_field . "</p>");
  $this
    ->entitiesSetLabelClass('above', 'My body');
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"label-above\">My body:&nbsp;</div><p>" . $body_field . "</p>");
  $this
    ->entitiesSetLabelClass('inline', 'My body');
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"label-inline\">My body:&nbsp;</div><p>" . $body_field . "</p>");
  variable_set('ft-kill-colon', TRUE);
  $this
    ->refreshVariables();
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"label-inline\">My body</div><p>" . $body_field . "</p>");
  $this
    ->entitiesSetLabelClass('hidden');
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <p>" . $body_field . "</p>");
  $this
    ->entitiesClearFieldSettings();

  // ----------------------
  // Custom field function.
  // ----------------------
  // With outer wrapper.
  $edit = array(
    'fields[body][format][ft][function]' => 'theme_ds_field_expert',
    'fields[body][format][ft][ow]' => '1',
    'fields[body][format][ft][ow-el]' => 'div',
  );
  $this
    ->dsConfigureUI($edit);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div><p>" . $body_field . "</p>\n</div>    </div>");

  // With outer div wrapper and class.
  $edit = array(
    'fields[body][format][ft][ow]' => '1',
    'fields[body][format][ft][ow-el]' => 'div',
    'fields[body][format][ft][ow-cl]' => 'ow-class',
  );
  $this
    ->dsConfigureUI($edit);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"ow-class\"><p>" . $body_field . "</p>\n</div>    </div>");

  // With outer span wrapper and class.
  $edit = array(
    'fields[body][format][ft][ow]' => '1',
    'fields[body][format][ft][ow-el]' => 'span',
    'fields[body][format][ft][ow-cl]' => 'ow-class-2',
  );
  $this
    ->dsConfigureUI($edit);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <span class=\"ow-class-2\"><p>" . $body_field . "</p>\n</span>    </div>");

  // Clear field settings.
  $this
    ->entitiesClearFieldSettings();

  // With outer wrapper and field items wrapper.
  $edit = array(
    'fields[body][format][ft][function]' => 'theme_ds_field_expert',
    'fields[body][format][ft][ow]' => '1',
    'fields[body][format][ft][ow-el]' => 'div',
    'fields[body][format][ft][fis]' => '1',
    'fields[body][format][ft][fis-el]' => 'div',
  );
  $this
    ->dsConfigureUI($edit);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div><div><p>" . $body_field . "</p>\n</div></div>    </div>");

  // With outer wrapper and field items div wrapper with class.
  $edit = array(
    'fields[body][format][ft][ow]' => '1',
    'fields[body][format][ft][ow-el]' => 'div',
    'fields[body][format][ft][ow-el]' => 'div',
    'fields[body][format][ft][fis]' => '1',
    'fields[body][format][ft][fis-el]' => 'div',
    'fields[body][format][ft][fis-cl]' => 'fi-class',
  );
  $this
    ->dsConfigureUI($edit);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div><div class=\"fi-class\"><p>" . $body_field . "</p>\n</div></div>    </div>");

  // With outer wrapper and field items span wrapper and class.
  $edit = array(
    'fields[body][format][ft][ow]' => '1',
    'fields[body][format][ft][ow-el]' => 'div',
    'fields[body][format][ft][fis]' => '1',
    'fields[body][format][ft][fis-el]' => 'span',
    'fields[body][format][ft][fis-cl]' => 'fi-class',
  );
  $this
    ->dsConfigureUI($edit);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div><span class=\"fi-class\"><p>" . $body_field . "</p>\n</span></div>    </div>");

  // With outer wrapper class and field items span wrapper and class.
  $edit = array(
    'fields[body][format][ft][ow]' => '1',
    'fields[body][format][ft][ow-el]' => 'div',
    'fields[body][format][ft][ow-cl]' => 'ow-class',
    'fields[body][format][ft][fis]' => '1',
    'fields[body][format][ft][fis-el]' => 'span',
    'fields[body][format][ft][fis-cl]' => 'fi-class',
  );
  $this
    ->dsConfigureUI($edit);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"ow-class\"><span class=\"fi-class\"><p>" . $body_field . "</p>\n</span></div>    </div>");

  // With outer wrapper span class and field items span wrapper and class.
  $edit = array(
    'fields[body][format][ft][ow]' => '1',
    'fields[body][format][ft][ow-el]' => 'span',
    'fields[body][format][ft][ow-cl]' => 'ow-class',
    'fields[body][format][ft][fis]' => '1',
    'fields[body][format][ft][fis-el]' => 'span',
    'fields[body][format][ft][fis-cl]' => 'fi-class-2',
  );
  $this
    ->dsConfigureUI($edit);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <span class=\"ow-class\"><span class=\"fi-class-2\"><p>" . $body_field . "</p>\n</span></span>    </div>");

  // Clear field settings.
  $this
    ->entitiesClearFieldSettings();

  // With field item div wrapper.
  $edit = array(
    'fields[body][format][ft][function]' => 'theme_ds_field_expert',
    'fields[body][format][ft][fi]' => '1',
  );
  $this
    ->dsConfigureUI($edit);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"even\"><p>" . $body_field . "</p>\n</div>    </div>");

  // With field item span wrapper.
  $edit = array(
    'fields[body][format][ft][fi]' => '1',
    'fields[body][format][ft][fi-el]' => 'span',
  );
  $this
    ->dsConfigureUI($edit);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <span class=\"even\"><p>" . $body_field . "</p>\n</span>    </div>");

  // With field item span wrapper and class.
  $edit = array(
    'fields[body][format][ft][fi]' => '1',
    'fields[body][format][ft][fi-el]' => 'span',
    'fields[body][format][ft][fi-cl]' => 'fi-class',
  );
  $this
    ->dsConfigureUI($edit);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <span class=\"even fi-class\"><p>" . $body_field . "</p>\n</span>    </div>");

  // With fis and fi.
  $edit = array(
    'fields[body][format][ft][fis]' => '1',
    'fields[body][format][ft][fis-el]' => 'div',
    'fields[body][format][ft][fis-cl]' => 'fi-class-2',
    'fields[body][format][ft][fi]' => '1',
    'fields[body][format][ft][fi-el]' => 'div',
    'fields[body][format][ft][fi-cl]' => 'fi-class',
  );
  $this
    ->dsConfigureUI($edit);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"fi-class-2\"><div class=\"even fi-class\"><p>" . $body_field . "</p>\n</div></div>    </div>");

  // With all
  $edit = array(
    'fields[body][format][ft][ow]' => '1',
    'fields[body][format][ft][ow-el]' => 'div',
    'fields[body][format][ft][ow-cl]' => 'ow-class',
    'fields[body][format][ft][fis]' => '1',
    'fields[body][format][ft][fis-el]' => 'div',
    'fields[body][format][ft][fis-cl]' => 'fi-class-2',
    'fields[body][format][ft][fi]' => '1',
    'fields[body][format][ft][fi-el]' => 'span',
    'fields[body][format][ft][fi-cl]' => 'fi-class',
  );
  $this
    ->dsConfigureUI($edit);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"ow-class\"><div class=\"fi-class-2\"><span class=\"even fi-class\"><p>" . $body_field . "</p>\n</span></div></div>    </div>");

  // Label tests with custom function.
  $this
    ->entitiesSetLabelClass('above');
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"ow-class\"><div class=\"label-above\">Body:&nbsp;</div><div class=\"fi-class-2\"><span class=\"even fi-class\"><p>" . $body_field . "</p>\n</span></div></div>    </div>");
  $this
    ->entitiesSetLabelClass('inline');
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"ow-class\"><div class=\"label-inline\">Body:&nbsp;</div><div class=\"fi-class-2\"><span class=\"even fi-class\"><p>" . $body_field . "</p>\n</span></div></div>    </div>");
  $this
    ->entitiesSetLabelClass('above', 'My body');
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"ow-class\"><div class=\"label-above\">My body:&nbsp;</div><div class=\"fi-class-2\"><span class=\"even fi-class\"><p>" . $body_field . "</p>\n</span></div></div>    </div>");
  $this
    ->entitiesSetLabelClass('inline', 'My body');
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"ow-class\"><div class=\"label-inline\">My body:&nbsp;</div><div class=\"fi-class-2\"><span class=\"even fi-class\"><p>" . $body_field . "</p>\n</span></div></div>    </div>");
  $this
    ->entitiesSetLabelClass('inline', 'My body', '', TRUE);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"ow-class\"><div class=\"label-inline\">My body</div><div class=\"fi-class-2\"><span class=\"even fi-class\"><p>" . $body_field . "</p>\n</span></div></div>    </div>");
  $this
    ->entitiesSetLabelClass('hidden');
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      <div class=\"ow-class\"><div class=\"fi-class-2\"><span class=\"even fi-class\"><p>" . $body_field . "</p>\n</span></div></div>    </div>");

  // Use the test field theming function to test that this function is
  // registered in the theme registry through ds_extras_theme().
  $edit = array(
    'fields[body][format][ft][function]' => 'ds_test_theming_function',
  );
  $this
    ->dsConfigureUI($edit);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw("<div class=\"group-right\">\n      Testing field output through custom function    </div>");
}