| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace App\Tests\Functional\Controller; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 5 |  |  | class EmployeesControllerTest extends AbstractController | 
            
                                                                        
                            
            
                                    
            
            
                | 6 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     public function testGetEmployees() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |         $this->restRequest('/api/employees'); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 10 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     public function testGetEmployeesSlug() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         $slug = $this->getEm()->getRepository('App:Employee')->findOneBy([])->getSlug(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         $this->restRequest('/api/employees/'.$slug); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         $this->restRequest('/api/employees/nonexistent-slug', 'GET', 404); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 17 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public function testGetEmployeesSlugRoles() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $slug = $this->getEm()->getRepository('App:Employee')->findOneBy([])->getSlug(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $this->restRequest('/api/employees/'.$slug.'/roles'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $this->restRequest('/api/employees/nonexistent-slug/roles', 'GET', 404); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 24 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     public static function employeesGroupCount(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             ['actors', 37], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             ['art-core', 11], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             ['ballet', 8], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             ['administrative-accounting', 4], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             ['orchestra', 12], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             ['art-production', 15], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             ['deputies', 2], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             ['epoch', 4], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             ['', 95], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         ]; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      * @dataProvider employeesGroupCount | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     public function testGetEmployeesFilteredByGroup(string $group, int $count) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $this->restRequest('/api/employees?group='.$group); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $response = json_decode($this->getSessionClient()->getResponse()->getContent(), true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->assertCount($count, $response['employees']); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     public function testEmployeesResponseFields() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $this->restRequest('/api/employees'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $response = json_decode($this->getSessionClient()->getResponse()->getContent(), true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $firstEntity = array_shift($response['employees']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             count($this->getEntityFields()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             count(array_keys($firstEntity)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         foreach ($this->getEntityFields() as $field) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             $this->assertArrayHasKey($field, $firstEntity); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 65 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     private function getEntityFields(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             'locale', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             'first_name', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             'last_name', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             'dob', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             'position', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             'biography', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             'gallery', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             'slug', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             'avatar', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             'created_at', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             'updated_at', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             'staff', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         ]; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 83 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 84 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |  |