You are here

public function ServicesRESTServerTests::testRender in Services 7.3

Test for render() method.

File

servers/rest_server/tests/ServicesRESTServerTests.test, line 339

Class

ServicesRESTServerTests
Unit tests for RESTServer class.

Code

public function testRender() {
  $factory_args = $this
    ->getDefaultFactoryArguments();
  $rest_server = $this
    ->getRESTSever($factory_args);
  $formatters = array(
    'xml' => array(
      'mime types' => array(
        'application/xml',
        'text/xml',
      ),
      'formatter class' => 'ServicesXMLFormatter',
    ),
    'json' => array(
      'mime types' => array(
        'application/json',
      ),
      'formatter class' => 'ServicesJSONFormatter',
    ),
    'php' => array(
      'mime types' => array(
        'application/vnd.php.serialized',
      ),
      'formatter class' => 'ServicesPHPFormatter',
    ),
  );
  $result = array(
    'a' => 'b',
    1,
    FALSE,
  );
  $xml_formatter = $formatters['xml'];
  $formatted_output = $rest_server
    ->protectedRender($xml_formatter, $result);
  $expected_formatted_output = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . '<result><a>b</a><item>1</item><item></item></result>' . "\n";
  $this
    ->assertEqual($formatted_output, $expected_formatted_output, 'XML formatter encoded correctly.');
  $json_formatter = $formatters['json'];
  $formatted_output = $rest_server
    ->protectedRender($json_formatter, $result);
  $this
    ->assertEqual($formatted_output, '{"a":"b","0":1,"1":false}', 'JSON formatter encoded correctly.');
  $php_formatter = $formatters['php'];
  $formatted_output = $rest_server
    ->protectedRender($php_formatter, $result);
  $this
    ->assertEqual($formatted_output, 'a:3:{s:1:"a";s:1:"b";i:0;i:1;i:1;b:0;}', 'PHP formatter encoded correctly.');
}