public function FieldTemplateTest::testDsFieldTemplate5 in Display Suite 8.2
Tests on field templates.
File
- src/
Tests/ FieldTemplateTest.php, line 259
Class
- FieldTemplateTest
- Tests for display of nodes and fields.
Namespace
Drupal\ds\TestsCode
public function testDsFieldTemplate5() {
// Get a node.
$node = $this
->entitiesTestSetup('hidden');
$body_field = $node->body->value;
// With field item div wrapper.
$edit = array(
'fields[body][settings_edit_form][third_party_settings][ds][ft][id]' => 'expert',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi]' => '1',
);
$this
->dsEditFormatterSettings($edit);
drupal_flush_all_caches();
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="group-right"]');
$this
->assertTrimEqual($xpath[0]->div->p, $body_field);
// With field item span wrapper.
$edit = array(
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi]' => '1',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi-el]' => 'span',
);
$this
->dsEditFormatterSettings($edit);
drupal_flush_all_caches();
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="group-right"]');
$this
->assertTrimEqual($xpath[0]->span->p, $body_field);
// With field item span wrapper and class.
$edit = array(
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi]' => '1',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi-el]' => 'span',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi-cl]' => 'fi-class',
);
$this
->dsEditFormatterSettings($edit);
drupal_flush_all_caches();
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="group-right"]/span[@class="fi-class"]');
$this
->assertTrimEqual($xpath[0]->p, $body_field);
// With fis and fi.
$edit = array(
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fis]' => '1',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fis-el]' => 'div',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fis-cl]' => 'fi-class-2',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi]' => '1',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi-el]' => 'div',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi-cl]' => 'fi-class',
);
$this
->dsEditFormatterSettings($edit);
drupal_flush_all_caches();
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="fi-class-2"]/div[@class="fi-class"]');
$this
->assertTrimEqual($xpath[0]->p, $body_field);
// With all wrappers.
$edit = array(
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow]' => '1',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-el]' => 'div',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-cl]' => 'ow-class',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fis]' => '1',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fis-el]' => 'div',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fis-cl]' => 'fi-class-2',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi]' => '1',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi-el]' => 'span',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi-cl]' => 'fi-class',
);
$this
->dsEditFormatterSettings($edit);
drupal_flush_all_caches();
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="ow-class"]/div[@class="fi-class-2"]/span[@class="fi-class"]');
$this
->assertTrimEqual($xpath[0]->p, $body_field);
// With all wrappers and attributes.
$edit = array(
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow]' => '1',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-el]' => 'div',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-cl]' => 'ow-class',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-at]' => 'name="ow-att"',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fis]' => '1',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fis-el]' => 'div',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fis-cl]' => 'fi-class-2',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fis-at]' => 'name="fis-att"',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi]' => '1',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi-el]' => 'span',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi-cl]' => 'fi-class',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi-at]' => 'name="fi-at"',
);
$this
->dsEditFormatterSettings($edit);
drupal_flush_all_caches();
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="ow-class" and @name="ow-att"]/div[@class="fi-class-2" and @name="fis-att"]/span[@class="fi-class" and @name="fi-at"]');
$this
->assertTrimEqual($xpath[0]->p, $body_field);
// Remove attributes.
$edit = array(
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow]' => '1',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-el]' => 'div',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-cl]' => 'ow-class',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-at]' => '',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fis]' => '1',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fis-el]' => 'div',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fis-cl]' => 'fi-class-2',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fis-at]' => '',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi]' => '1',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi-el]' => 'span',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi-cl]' => 'fi-class',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi-at]' => '',
);
$this
->dsEditFormatterSettings($edit);
// Label tests with custom function.
$this
->entitiesSetLabelClass('above', 'body');
drupal_flush_all_caches();
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="ow-class"]/div[@class="field-label-above"]');
$this
->assertTrimEqual($xpath[0], 'Body');
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="ow-class"]/div[@class="fi-class-2"]/span[@class="fi-class"]');
$this
->assertTrimEqual($xpath[0]->p, $body_field);
$this
->entitiesSetLabelClass('inline', 'body');
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="ow-class"]/div[@class="field-label-inline"]');
$this
->assertTrimEqual($xpath[0], 'Body');
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="ow-class"]/div[@class="fi-class-2"]/span[@class="fi-class"]');
$this
->assertTrimEqual($xpath[0]->p, $body_field);
$this
->entitiesSetLabelClass('above', 'body', 'My body');
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="ow-class"]/div[@class="field-label-above"]');
$this
->assertTrimEqual($xpath[0], 'My body');
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="ow-class"]/div[@class="fi-class-2"]/span[@class="fi-class"]');
$this
->assertTrimEqual($xpath[0]->p, $body_field);
$this
->entitiesSetLabelClass('inline', 'body', 'My body');
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="ow-class"]/div[@class="field-label-inline"]');
$this
->assertTrimEqual($xpath[0], 'My body');
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="ow-class"]/div[@class="fi-class-2"]/span[@class="fi-class"]');
$this
->assertTrimEqual($xpath[0]->p, $body_field);
$this
->entitiesSetLabelClass('inline', 'body', 'My body', '', TRUE);
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="ow-class"]/div[@class="field-label-inline"]');
$this
->assertTrimEqual($xpath[0], 'My body:');
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="ow-class"]/div[@class="fi-class-2"]/span[@class="fi-class"]');
$this
->assertTrimEqual($xpath[0]->p, $body_field);
$this
->entitiesSetLabelClass('hidden', 'body');
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="ow-class"]/div[@class="fi-class-2"]/span[@class="fi-class"]');
$this
->assertTrimEqual($xpath[0]->p, $body_field);
// Test default classes on outer wrapper.
// @todo figure out a way to actually test this as the default cases don't
// have classes anymore.
$edit = array(
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow]' => '1',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-el]' => 'div',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-cl]' => 'ow-class',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-def-cl]' => '1',
);
$this
->dsEditFormatterSettings($edit);
drupal_flush_all_caches();
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="ow-class"]/div[@class="fi-class-2"]/span[@class="fi-class"]');
$this
->assertTrimEqual($xpath[0]->p, $body_field);
// Test default attributes on field item.
$edit = array(
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow]' => '1',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-el]' => 'div',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-cl]' => 'ow-class',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-def-at]' => '1',
);
$this
->dsEditFormatterSettings($edit);
drupal_flush_all_caches();
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="group-right"]/div[@class="ow-class" and @data-quickedit-field-id="node/1/body/en/full"]/div[@class="fi-class-2"]/span[@class="fi-class"]');
$this
->assertTrimEqual($xpath[0]->p, $body_field);
// 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][settings_edit_form][third_party_settings][ds][ft][id]' => 'ds_test_template',
);
$this
->dsEditFormatterSettings($edit);
drupal_flush_all_caches();
$this
->drupalGet('node/' . $node
->id());
$xpath = $this
->xpath('//div[@class="group-right"]');
$this
->assertTrimEqual($xpath[0], 'Testing field output through custom function');
}