| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * ProxyControllerTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | namespace Graviton\ProxyBundle\Tests\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Graviton\TestBundle\Client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Graviton\TestBundle\Test\RestTestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * functional test for /3rdparty/{api} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @author  List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @license http://opensource.org/licenses/gpl-license.php GNU Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @link    http://swisscom.ch | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | class ProxyControllerTest extends RestTestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     const REQUEST_URL = "/3rdparty/graviton/core/app"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * test post request with the proxy Action | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     public function testProxyAction() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $client = static::createRestClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $headers = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             'Content_Type'  => 'application/json', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $testApp = new \stdClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $testApp->id = "testapp"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $testApp->showInMenu = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $testApp->order = 33; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $testApp->name = new \stdClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $testApp->name->en = "testapp"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $client->request( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             'PUT', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             self::REQUEST_URL.'/'.$testApp->id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             $headers, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             json_encode($testApp) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $response = $client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $this->assertEquals(204, $response->getStatusCode()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $this->assertEmpty($response->getContent()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $client->request( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             'GET', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             self::REQUEST_URL.'/'.$testApp->id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $response = $client->getResponse(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 66 |  |  |         $content = json_decode($response->getContent()); | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |         $this->assertEquals(200, $response->getStatusCode()); | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |         $this->assertEquals($testApp, $content); | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |         $client->request( | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |             'DELETE', | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |             self::REQUEST_URL.'/'.$testApp->id, | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |             array(), | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |             array(), | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |             $headers | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |         $response = $client->getResponse(); | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |         $this->assertEquals(204, $response->getStatusCode()); | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |         $this->assertEmpty($response->getContent()); | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * test the schema proxy Action | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     public function testSchemaProxyAction() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $client = static::createRestClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $client->request( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             'GET', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             '/schema'.self::REQUEST_URL.'/item' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 96 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 97 |  |  |  |