2 /*********************************************************************************
3 * By installing or using this file, you are confirming on behalf of the entity
4 * subscribed to the SugarCRM Inc. product ("Company") that Company is bound by
5 * the SugarCRM Inc. Master Subscription Agreement (“MSA”), which is viewable at:
6 * http://www.sugarcrm.com/master-subscription-agreement
8 * If Company is not bound by the MSA, then by installing or using this file
9 * you are agreeing unconditionally that Company will be bound by the MSA and
10 * certifying that you have authority to bind Company accordingly.
12 * Copyright (C) 2004-2013 SugarCRM Inc. All rights reserved.
13 ********************************************************************************/
16 require_once('tests/service/RestTestCase.php');
19 * @bug 43368 - Bad Content-Type on SugarCRM REST API Interface
22 class Bug43368Test extends RestTestCase
25 public function setUp()
29 //Create an anonymous user for login purposes/
30 $current_user = SugarTestUserUtilities::createAnonymousUser();
31 $current_user->status = 'Active';
32 $current_user->is_admin = 1;
33 $current_user->save();
34 $GLOBALS['db']->commit(); // Making sure we commit any changes before continuing
37 public function tearDown()
40 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
41 unset($GLOBALS['current_user']);
47 * This function helps wrap the REST call using the CURL libraries
49 * @param $method String name of the method to call
50 * @param $parameters Mixed array of arguments depending on the method call
52 * @return mixed JSON decoded response made from REST call
54 protected function _makeRESTCall($method)
56 // specify the REST web service to interact with
57 $url = $GLOBALS['sugar_config']['site_url'].'/service/v4/rest.php';
58 // Open a curl session for making the call
59 $curl = curl_init($url);
60 // set URL and other appropriate options
61 curl_setopt($curl, CURLOPT_URL, $url);
62 curl_setopt($curl, CURLOPT_POST, 1);
63 curl_setopt($curl, CURLOPT_HEADER, 0);
64 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
65 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
66 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
67 curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 );
68 // build the request URL
69 $json = json_encode(array());
70 $postArgs = "method=$method&input_type=JSON&response_type=JSON&rest_data=$json";
71 curl_setopt($curl, CURLOPT_POSTFIELDS, $postArgs);
72 // Make the REST call, returning the result
73 $response = curl_exec($curl);
74 // Close the connection
75 $return = curl_getinfo($curl);
78 // Convert the result from JSON format to a PHP array
85 public function testRestReturnContentType()
87 $results = $this->_makeRESTCall('get_server_info');
88 $this->assertEquals('application/json; charset=UTF-8', $results['content_type']);