You are here

public function RangeUnitTestCase::testRangeFormatterViewSeparateValues in Range 7

Test separate values formatter.

File

tests/range.unit.test, line 100
Unit tests for Range module.

Class

RangeUnitTestCase
Unit tests for Range.

Code

public function testRangeFormatterViewSeparateValues() {
  $from_value = 12345;
  $to_value = 67890;
  $instance_settings = array(
    'from' => array(
      'prefix' => 'from_prefix-',
      'suffix' => '-from_suffix',
    ),
    'to' => array(
      'prefix' => 'to_prefix-',
      'suffix' => '-to_suffix',
    ),
  );

  // Test with disabled prefix and suffix.
  $settings = array(
    'from_prefix_suffix' => FALSE,
    'to_prefix_suffix' => FALSE,
    'range_separator' => '=',
  );
  $result = _range_field_formatter_view_separate_values($from_value, $to_value, $settings, $instance_settings);
  $this
    ->assertEqual($result, '12345=67890', format_string('No suffix or prefix has been added: <strong>@output<strong>', array(
    '@output' => var_export($result, TRUE),
  )));

  // Test with enabled prefix only.
  $settings = array(
    'from_prefix_suffix' => TRUE,
    'to_prefix_suffix' => FALSE,
    'range_separator' => '=',
  );
  $result = _range_field_formatter_view_separate_values($from_value, $to_value, $settings, $instance_settings);
  $this
    ->assertEqual($result, 'from_prefix-12345-from_suffix=67890', format_string('FROM value prefix and suffix have been added: <strong>@output<strong>', array(
    '@output' => var_export($result, TRUE),
  )));

  // Test with enabled suffix only.
  $settings = array(
    'from_prefix_suffix' => FALSE,
    'to_prefix_suffix' => TRUE,
    'range_separator' => '=',
  );
  $result = _range_field_formatter_view_separate_values($from_value, $to_value, $settings, $instance_settings);
  $this
    ->assertEqual($result, '12345=to_prefix-67890-to_suffix', format_string('TO value prefix and suffix have been added: <strong>@output<strong>', array(
    '@output' => var_export($result, TRUE),
  )));

  // Test with enabled prefix and suffix.
  $settings = array(
    'from_prefix_suffix' => TRUE,
    'to_prefix_suffix' => TRUE,
    'range_separator' => '=',
  );
  $result = _range_field_formatter_view_separate_values($from_value, $to_value, $settings, $instance_settings);
  $this
    ->assertEqual($result, 'from_prefix-12345-from_suffix=to_prefix-67890-to_suffix', format_string('FROM and TO values prefixes and suffixes have been added: <strong>@output<strong>', array(
    '@output' => var_export($result, TRUE),
  )));
}