public function OptionsFormattersTest::testFormatter

Tests the formatters.

File

drupal/core/modules/options/lib/Drupal/options/Tests/OptionsFormattersTest.php, line 36
Contains \Drupal\options\Tests\OptionsFormattersTest.

Class

OptionsFormattersTest
Tests the formatters provided by the options module.

Namespace

Drupal\options\Tests

Code

public function testFormatter() {
  $entity = entity_create('entity_test', array());
  $entity->{$this->fieldName}->value = 1;
  $build = field_view_field($entity, $this->fieldName, array());
  $this
    ->assertEqual($build['#formatter'], 'list_default', 'Ensure to fall back to the default formatter.');
  $this
    ->assertEqual($build[0]['#markup'], 'One');
  $build = field_view_field($entity, $this->fieldName, array(
    'type' => 'list_key',
  ));
  $this
    ->assertEqual($build['#formatter'], 'list_key', 'The chosen formatter is used.');
  $this
    ->assertEqual($build[0]['#markup'], 1);
}