public function DoubleFieldFormatter::getFormatterValidators in Double Field 7.2
Confirm that the formatter is being displayed.
File
- tests/
double_field_formatter.inc, line 222 - The file contains a class that assists to test Double field formatter types.
Class
- DoubleFieldFormatter
- Helper class to test Double field formatters.
Code
public function getFormatterValidators($field_name, $items) {
$cardinality = count($items);
$prefix = "//div[contains(@class, 'field-name-{$field_name}')]/div[contains(@class, 'field-items')]";
$validators[] = $prefix;
switch ($this->type) {
case 'double_field_unformatted_list':
if ($this->settings['style'] == 'link') {
for ($delta = 0; $delta < $cardinality; $delta++) {
$text = $this->settings['first']['prefix'] . $items[$delta]['first'] . $this->settings['first']['suffix'];
$href = check_plain(url($this->settings['second']['prefix'] . $items[$delta]['second'] . $this->settings['second']['suffix']));
$validators[] = "//a[@href='{$href}' and text()='{$text}']";
}
}
elseif ($this->settings['style'] == 'simple') {
for ($delta = 0; $delta < $cardinality; $delta++) {
$text = $this->settings['first']['prefix'] . $items[$delta]['first'] . $this->settings['first']['suffix'];
$text .= $this->settings['second']['prefix'] . $items[$delta]['second'] . $this->settings['second']['suffix'];
$validators[] = "//div[contains(@class, 'field-item') and text()='{$text}']";
}
}
else {
$class = $this->settings['style'] == 'block' ? 'clearfix' : 'container-inline';
for ($delta = 0; $delta < $cardinality; $delta++) {
foreach (array(
'first',
'second',
) as $subfield) {
$text = $this->settings[$subfield]['prefix'] . $items[$delta][$subfield] . $this->settings[$subfield]['suffix'];
$validators[] = "//div[@class='{$class}']/div[@class='double-field-{$subfield}' and text()='{$text}']";
}
}
}
break;
case 'double_field_html_list':
// Check definition list markup.
if ($this->settings['list_type'] == 'dl') {
$prefix .= "//div[@class='double-field-definition-list']/dl";
$validators[] = $prefix;
for ($delta = 0; $delta < $cardinality; $delta++) {
$text = $this->settings['first']['prefix'] . $items[$delta]['first'] . $this->settings['first']['suffix'];
$validators[] = "{$prefix}/dt[text()='{$text}']";
$text = $this->settings['second']['prefix'] . $items[$delta]['second'] . $this->settings['second']['suffix'];
$validators[] = "{$prefix}/dd[text()='{$text}']";
}
}
else {
$prefix .= "//div[contains(@class, 'item-list')]/{$this->settings['list_type']}/li";
if ($this->settings['style'] == 'link') {
for ($delta = 0; $delta < $cardinality; $delta++) {
$text = $this->settings['first']['prefix'] . $items[$delta]['first'] . $this->settings['first']['suffix'];
$href = check_plain(url($this->settings['second']['prefix'] . $items[$delta]['second'] . $this->settings['second']['suffix']));
$validators[] = "{$prefix}/a[@href='{$href}' and text()='{$text}']";
}
}
elseif ($this->settings['style'] == 'simple') {
for ($delta = 0; $delta < $cardinality; $delta++) {
$text = $this->settings['first']['prefix'] . $items[$delta]['first'] . $this->settings['first']['suffix'];
$text .= $this->settings['second']['prefix'] . $items[$delta]['second'] . $this->settings['second']['suffix'];
$validators[] = "{$prefix}[text()='{$text}']";
}
}
else {
$class = $this->settings['style'] == 'block' ? 'clearfix' : 'container-inline';
for ($delta = 0; $delta < $cardinality; $delta++) {
foreach (array(
'first',
'second',
) as $subfield) {
$text = $this->settings[$subfield]['prefix'] . $items[$delta][$subfield] . $this->settings[$subfield]['suffix'];
$validators[] = "{$prefix}/div[@class='{$class}']/div[@class='double-field-{$subfield}' and text()='{$text}']";
}
}
}
}
break;
case 'double_field_fieldset':
$collapsible = $this->settings['collapsible'] ? "contains(@class,'collapsible')" : "not(contains(@class,'collapsible'))";
$prefix .= "//fieldset[{$collapsible}]";
for ($delta = 0; $delta < $cardinality; $delta++) {
$text = $this->settings['first']['prefix'] . $items[$delta]['first'] . $this->settings['first']['suffix'];
$validators[] = "{$prefix}/legend/span[text()='{$text}']";
$text = $this->settings['second']['prefix'] . $items[$delta]['second'] . $this->settings['second']['suffix'];
$validators[] = "{$prefix}/div[@class='fieldset-wrapper' and text()='{$text}']";
}
break;
case 'double_field_table':
$prefix .= "//table";
if ($this->settings['table']['first']['column_label'] || $this->settings['table']['second']['column_label']) {
if ($this->settings['table']['number_column']) {
$text = $this->settings['table']['number_column_label'];
$validators[] = "{$prefix}/thead/tr/th[position()=1 and text()='{$text}']";
}
foreach (array(
'first',
'second',
) as $subfield) {
if ($text = $this->settings['table'][$subfield]['column_label']) {
$validators[] = "{$prefix}/thead/tr/th[text()='{$text}']";
}
else {
// Column label can be empty.
$validators[] = "{$prefix}/thead/tr/th[not(text())]";
}
}
}
else {
// Verify that table head doesn't exist.
$validators[] = "{$prefix}/*[position()=1 and not(name()='thead')]";
}
for ($delta = 0; $delta < $cardinality; $delta++) {
$position = $this->settings['table']['number_column'] ? 2 : 1;
if ($this->settings['table']['number_column']) {
$text = $delta + 1;
$validators[] = "{$prefix}/tbody/tr/td[position()=1 and text()='{$text}']";
}
foreach (array(
'first',
'second',
) as $subfield) {
$text = $this->settings[$subfield]['prefix'] . $items[$delta][$subfield] . $this->settings[$subfield]['suffix'];
$validators[] = "{$prefix}/tbody/tr/td[position()={$position} and text()='{$text}']";
$position++;
}
}
break;
case 'double_field_accordion':
$prefix .= "//div[contains(@class, 'double-field-accordion')]";
for ($delta = 0; $delta < $cardinality; $delta++) {
$text = $this->settings['first']['prefix'] . $items[$delta]['first'] . $this->settings['first']['suffix'];
$validators[] = "{$prefix}/h3/a[text()='{$text}']";
$text = $this->settings['second']['prefix'] . $items[$delta]['second'] . $this->settings['second']['suffix'];
$validators[] = "{$prefix}/div[not(@class)]";
}
$validators[] = "//head/script[contains(@src,'jquery.ui.accordion.min')]";
$validators[] = "//head/script[not(@src) and contains(text(), 'jQuery(document).ready(function(){jQuery(\".double-field-accordion\").accordion({ collapsible: true, active: false });});')]";
break;
case 'double_field_tabs':
$prefix .= "//div[contains(@class, 'double-field-tabs')]";
$label_prefix = "//div[contains(@class, 'item-list')]/ul";
for ($delta = 0; $delta < $cardinality; $delta++) {
$id = "tabs-1-{$delta}";
$tab_label = $this->settings['first']['prefix'] . $items[$delta]['first'] . $this->settings['first']['suffix'];
$validators[] = "{$label_prefix}/li/a[@href='#{$id}' and text()='{$tab_label}']";
$tab_value = $this->settings['second']['prefix'] . $items[$delta]['second'] . $this->settings['second']['suffix'];
$validators[] = "{$prefix}/div[@id='{$id}' and text()='{$tab_value}']";
}
$validators[] = "//head/script[contains(@src,'jquery.ui.tabs.min')]";
$validators[] = "//head/script[not(@src) and contains(text(), 'jQuery(document).ready(function(){jQuery(\".double-field-tabs\").tabs();});')]";
break;
case 'double_field_dialog':
for ($delta = 0; $delta < $cardinality; $delta++) {
$title = $this->settings['first']['prefix'] . $items[$delta]['first'] . $this->settings['first']['suffix'];
$text = $this->settings['second']['prefix'] . $items[$delta]['second'] . $this->settings['second']['suffix'];
$validators[] = "{$prefix}//div[@class='double-field-dialog' and @title='{$title}' and text()='{$text}']";
}
$validators[] = "//head/script[contains(@src,'jquery.ui.dialog.min')]";
$validators[] = "//head/script[not(@src) and contains(text(), 'jQuery(document).ready(function(){jQuery(\".double-field-dialog\").dialog();});')]";
break;
}
return $validators;
}