| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Tests\AppBundle\Controller\Api; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | class SurveyControllerTest extends WebTestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     public function testList() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |         exec('./bin/console d:d:c --env=test'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |         exec('./bin/console d:s:c --env=test'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |         exec('./bin/console h:f:l -n --env=test'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         $client = static::createClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $client->request('GET', '/api/surveys'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $this->assertEquals(401, $client->getResponse()->getStatusCode()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $client->request( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |             'GET', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             '/api/surveys', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |             array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             array('HTTP_X-AUTH-TOKEN' => '1') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $this->assertTrue( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             $client->getResponse()->headers->contains( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |                 'Content-Type', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                 'application/json' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             'the "Content-Type" header is "application/json"' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->assertTrue($client->getResponse()->isSuccessful(), 'response status is 2xx'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     public function testShow() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $client = static::createClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $client->request('GET', '/api/surveys/1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->assertEquals(401, $client->getResponse()->getStatusCode()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $client->request( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             'GET', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             '/api/surveys', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             array('HTTP_X-AUTH-TOKEN' => '1') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $this->assertTrue( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             $client->getResponse()->headers->contains( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 'Content-Type', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                 'application/json' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             'the "Content-Type" header is "application/json"' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $this->assertTrue($client->getResponse()->isSuccessful(), 'response status is 2xx'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 65 |  |  |     public function testEdit() | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |         $client = static::createClient(); | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |         $client->request('PUT', '/api/surveys/1'); | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |         $this->assertEquals(401, $client->getResponse()->getStatusCode()); | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |         $client->request( | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |             'PUT', | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |             '/api/surveys/2', | 
            
                                                        
            
                                    
            
            
                | 76 |  |  |             array(), | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |             array(), | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |             array('CONTENT_TYPE' => 'application/json', | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |                   'HTTP_X-AUTH-TOKEN' => '2', ), | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |             $content = '{"answers":[{"questionId": 1,"content": "John"},{"questionId": 2,"content": "Title" | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |                          },{"questionId": 3,"content": "Site"},{"questionId": 4,"content": "10"},{"questionId": 5, | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |                          "content": "5"}]}' | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |         ); | 
            
                                                        
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |         $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 
            
                                                        
            
                                    
            
            
                | 86 |  |  |         exec('./bin/console d:d:d --force --env=test'); | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 88 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |  |