1 views_handler_field.test ViewsHandlerFieldTest::_testEmptyText()

Tests the usage of the empty text.

File

core/modules/views/tests/handlers/views_handler_field.test, line 256
Definition of ViewsHandlerFieldTest.

Class

ViewsHandlerFieldTest
Tests the generic field handler

Code

function _testEmptyText() {
  $view = $this->getBasicView();
  $view->init_display();
  $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.');
}