You are here

public function RestfulViewModeAndFormatterTestCase::testFormatterIntegration in RESTful 7

Same name and namespace in other branches
  1. 7.2 tests/RestfulViewModeAndFormatterTestCase.test \RestfulViewModeAndFormatterTestCase::testFormatterIntegration()

Test the field API formatter integration.

File

tests/RestfulViewModeAndFormatterTestCase.test, line 42
Contains RestfulViewModeFormatterTestCase

Class

RestfulViewModeAndFormatterTestCase
@file Contains RestfulViewModeFormatterTestCase

Code

public function testFormatterIntegration() {
  $handler = restful_get_restful_handler('articles', 1, 5);

  // Create node.
  $text = 'Some body with long text';
  $settings = array(
    'type' => 'article',
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $text,
        ),
      ),
    ),
  );
  $node = $this
    ->drupalCreateNode($settings);

  // Field with no formatter.
  $result = $handler
    ->get($node->nid);
  $this
    ->assertEqual(trim(strip_tags($result[0]['body'])), $text, 'Raw value passed without a formatter.');

  // Add formatter settings.
  $public_fields = $handler
    ->getPublicFields();
  $display = array(
    'type' => 'text_summary_or_trimmed',
    'settings' => array(
      'trim_length' => 10,
    ),
  );
  $public_fields['body']['formatter'] = $display;
  $handler
    ->setPublicFields($public_fields);
  $result = $handler
    ->get($node->nid);

  // Core's trim formatter also inclues the opening <p> tag in the calculation
  // of number of chars.
  $this
    ->assertEqual($result[0]['body'], '<p>Some bo</p>', 'Value trimmed by formatter.');
}