]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/Bug43368Test.php
Release 6.5.11
[Github/sugarcrm.git] / tests / service / Bug43368Test.php
1 <?php
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
7  *
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.
11  *
12  * Copyright (C) 2004-2013 SugarCRM Inc.  All rights reserved.
13  ********************************************************************************/
14
15
16 require_once('tests/service/RestTestCase.php');
17
18 /**
19  * @bug 43368 - Bad Content-Type on SugarCRM REST API Interface
20  */
21
22 class Bug43368Test extends RestTestCase
23 {
24
25     public function setUp()
26     {
27         global $current_user;
28         parent::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
35     }
36
37     public function tearDown()
38     {
39         parent::tearDown();
40         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
41         unset($GLOBALS['current_user']);
42     }
43
44      /**
45      * _makeRestCall
46      *
47      * This function helps wrap the REST call using the CURL libraries
48      *
49      * @param $method String name of the method to call
50      * @param $parameters Mixed array of arguments depending on the method call
51      *
52      * @return mixed JSON decoded response made from REST call
53      */
54     protected function _makeRESTCall($method)
55     {
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);
76         curl_close($curl);
77
78         // Convert the result from JSON format to a PHP array
79         return $return;
80     }
81
82     /**
83      * @group 41523
84      */
85     public function testRestReturnContentType()
86     {
87         $results = $this->_makeRESTCall('get_server_info');
88         $this->assertEquals('application/json; charset=UTF-8', $results['content_type']);
89
90     }
91 }