function FieldTest::_testEmptyText in Views (for Drupal 7) 8.3
Tests the usage of the empty text.
1 call to FieldTest::_testEmptyText()
- FieldTest::testEmpty in lib/
Drupal/ views/ Tests/ Handler/ FieldTest.php - Tests everything related to empty output of a field.
File
- lib/
Drupal/ views/ Tests/ Handler/ FieldTest.php, line 911 - Definition of Drupal\views\Tests\Handler\FieldTest.
Class
- FieldTest
- Tests the generic field handler.
Namespace
Drupal\views\Tests\HandlerCode
function _testEmptyText() {
$view = $this
->getView();
$view
->initDisplay();
$this
->executeView($view);
$column_map_reversed = array_flip($this->column_map);
$view->row_index = 0;
$empty_text = $view->field['name']->options['empty'] = $this
->randomName();
$view->result[0]->{$column_map_reversed['name']} = "";
$render = $view->field['name']
->advanced_render($view->result[0]);
$this
->assertIdentical($render, $empty_text, 'If a field is empty, the empty text should be used for the output.');
$view->result[0]->{$column_map_reversed['name']} = "0";
$render = $view->field['name']
->advanced_render($view->result[0]);
$this
->assertIdentical($render, "0", 'If a field is 0 and empty_zero is not checked, the empty text should not be used for the output.');
$view->result[0]->{$column_map_reversed['name']} = "0";
$view->field['name']->options['empty_zero'] = TRUE;
$render = $view->field['name']
->advanced_render($view->result[0]);
$this
->assertIdentical($render, $empty_text, 'If a field is 0 and empty_zero is checked, the empty text should be used for the output.');
$view->result[0]->{$column_map_reversed['name']} = "";
$view->field['name']->options['alter']['alter_text'] = TRUE;
$alter_text = $view->field['name']->options['alter']['text'] = $this
->randomName();
$view->field['name']->options['hide_alter_empty'] = FALSE;
$render = $view->field['name']
->advanced_render($view->result[0]);
$this
->assertIdentical($render, $alter_text, 'If a field is empty, some rewrite text exists, but hide_alter_empty is not checked, render the rewrite text.');
$view->field['name']->options['hide_alter_empty'] = TRUE;
$render = $view->field['name']
->advanced_render($view->result[0]);
$this
->assertIdentical($render, $empty_text, 'If a field is empty, some rewrite text exists, and hide_alter_empty is checked, use the empty text.');
}