function FieldUnitTest::_testEmptyText

Tests the usage of the empty text.

1 call to FieldUnitTest::_testEmptyText()
FieldUnitTest::testEmpty in drupal/core/modules/views/lib/Drupal/views/Tests/Handler/FieldUnitTest.php
Tests everything related to empty output of a field.

File

drupal/core/modules/views/lib/Drupal/views/Tests/Handler/FieldUnitTest.php, line 467
Contains \Drupal\views\Tests\Handler\FieldUnitTest.

Class

FieldUnitTest
Tests the generic field handler.

Namespace

Drupal\views\Tests\Handler

Code

function _testEmptyText() {
  $view = views_get_view('test_view');
  $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']
    ->advancedRender($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']
    ->advancedRender($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']
    ->advancedRender($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']
    ->advancedRender($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']
    ->advancedRender($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.');
}