You are here

protected function ServicesWebTestCase::servicesPut in Services 7.3

Same name and namespace in other branches
  1. 6.3 tests/functional/ServicesWebTestCase.php \ServicesWebTestCase::servicesPut()

Perform PUT request.

13 calls to ServicesWebTestCase::servicesPut()
ServicesResourceCommentTests::testCommentUpdate in tests/functional/ServicesResourceCommentTests.test
Test update method.
ServicesResourceCommentTests::testCommentUpdateLegacy in tests/functional/ServicesResourceCommentTests.test
Test update method.
ServicesResourceNodetests::testEndpointResourceNodeUpdateLegacy in tests/functional/ServicesResourceNodeTests.test
Testing node_resource Update (Legacy).
ServicesResourceNodetests::testEndpointResourceNodeUpdateMissingTitle in tests/functional/ServicesResourceNodeTests.test
testing node_resource Update verify missing title
ServicesResourceNodetests::testEndpointResourceNodeUpdatePermFail in tests/functional/ServicesResourceNodeTests.test
testing node_resource Update fail with no permissions

... See full list

File

tests/services.test, line 141

Class

ServicesWebTestCase

Code

protected function servicesPut($url, $data = NULL, $headers = array(), $call_type = 'php') {
  $this
    ->addCSRFHeader($headers);
  switch ($call_type) {
    case 'php':

      // Add .php to get serialized response.
      $url = $this
        ->getAbsoluteUrl($url) . '.php';

      // Otherwise Services will reject arguments.
      $headers[] = "Content-type: application/x-www-form-urlencoded";

      // Prepare arguments.
      $post = drupal_http_build_query($data, '', '&');
      break;
    case 'json':

      // Add .json to get json encoded response.
      $url = $this
        ->getAbsoluteUrl($url) . '.json';

      // Set proper headers.
      $headers[] = "Content-type: application/json";

      // Prepare arguments.
      $post = json_encode($data);
      break;
  }

  // Emulate file.
  $putData = fopen('php://temp', 'rw+');
  fwrite($putData, $post);
  fseek($putData, 0);
  $content = $this
    ->curlExec(array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_PUT => TRUE,
    CURLOPT_HEADER => TRUE,
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_INFILE => $putData,
    CURLOPT_INFILESIZE => drupal_strlen($post),
  ));
  fclose($putData);

  // Parse response.
  list($info, $header, $status, $code, $body) = $this
    ->parseHeader($content, $call_type);
  $this
    ->verbose('PUT request to: ' . $url . '<hr />Arguments: ' . highlight_string('<?php ' . var_export($data, TRUE), TRUE) . '<hr />Raw POST body: ' . $post . '<hr />Response: ' . highlight_string('<?php ' . var_export($body, TRUE), TRUE) . '<hr />Curl info: ' . highlight_string('<?php ' . var_export($info, TRUE), TRUE) . '<hr />Raw response: ' . $content);
  return array(
    'header' => $header,
    'status' => $status,
    'code' => $code,
    'body' => $body,
  );
}