Merge branch '2015.11' into 2015.11-develop
[tine20] / tests / tine20 / Tinebase / Server / Plugin / JsonTests.php
1 <?php
2 /**
3  * Tine 2.0 - http://www.tine20.org
4  * 
5  * @package     Tinebase
6  * @subpackage  Server
7  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
8  * @copyright   Copyright (c) 2015-2015 Metaways Infosystems GmbH (http://www.metaways.de)
9  * @author      Lars Kneschke <l.kneschke@metaways.de>
10  */
11
12 /**
13  * Test class for Tinebase_Server_Plugin_Json
14  * 
15  * @package     Tinebase
16  * @subpackage  Server
17  */
18 class Tinebase_Server_Plugin_JsonTests extends TestCase
19 {
20     /**
21      * test with ContentType header set to application/json
22      */
23     public function testServerContentType()
24     {
25         $request = \Zend\Http\PhpEnvironment\Request::fromString(<<<EOS
26 POST /index.php HTTP/1.1\r
27 Host: localhost\r
28 Content-Type: application/json\r
29 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120824 Thunderbird/15.0 Lightning/1.7\r
30 EOS
31         );
32         
33         $server = Tinebase_Core::getDispatchServer($request);
34         
35         $this->assertInstanceOf('Tinebase_Server_Json', $server);
36     }
37     
38     /**
39      * test with ACCESS-CONTROL-REQUEST-METHOD header set
40      */
41     public function testServerCORSHeader()
42     {
43         $request = \Zend\Http\PhpEnvironment\Request::fromString(<<<EOS
44 OPTIONS /index.php HTTP/1.1\r
45 Host: localhost\r
46 ACCESS-CONTROL-REQUEST-METHOD: application/json\r
47 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120824 Thunderbird/15.0 Lightning/1.7\r
48 EOS
49         );
50         
51         $server = Tinebase_Core::getDispatchServer($request);
52         
53         $this->assertInstanceOf('Tinebase_Server_Json', $server);
54     }
55     
56     /**
57      * test with post parameter requestType set to JSON
58      */
59     public function testServerPostParameter()
60     {
61         $request = \Zend\Http\PhpEnvironment\Request::fromString(<<<EOS
62 POST /index.php?requestType=JSON HTTP/1.1\r
63 Host: localhost\r
64 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120824 Thunderbird/15.0 Lightning/1.7\r
65 EOS
66         );
67         
68         $request->setPost(new Zend\Stdlib\Parameters(array('requestType' => 'JSON')));
69         
70         $server = Tinebase_Core::getDispatchServer($request);
71         
72         $this->assertInstanceOf('Tinebase_Server_Json', $server);
73     }
74 }