| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace gotakk\ViewModelBundle\Tests\ViewModel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use gotakk\ViewModelBundle\ViewModel\ViewModelAssembler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use gotakk\ViewModelBundle\ViewModel\ViewModelNode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class ViewModelAssemblerTestClass extends ViewModelAssembler {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class ViewModelAssemblerTest extends \PHPUnit_Framework_TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     public function testValidateViewModelBySkel() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         $vm = new ViewModelNode(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         $assembler = new ViewModelAssemblerTestClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $this->assertTrue($assembler->validateViewModelBySkel($vm)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $vm = new ViewModelNode(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |             'date' => '1970-01-01', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |             'authors' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |                 'gotakk', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             'contactInfos' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |                 'tel' => '+1-202-555-0123', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |                 'fax' => '+1-202-555-0181', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |                 'mail' => '[email protected]', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             'movies' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                 array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |                     'title' => "The Lord of the Rings: The Fellowship of the Ring", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                     'resume' => "In the Second Age of Middle Earth, the Dark Lord Sauron forges the One Ring in Mount Doom to conquer the land. An alliance of men and elves battle Sauron’s forces in Mordor, where Isildur destroys Sauron by chopping off the Ring from his body. However, the Ring’s power corrupts Isildur to prevent its destruction. Isildur is assassinated by Orcs, but the Ring is lost for 2500 years until discovered by Sméagol who is consumed by the Ring and later named Gollum. After 500 years, it abandons him, only to be unexpectedly recovered by a Hobbit named Bilbo Baggins.", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $this->assertTrue($assembler->validateViewModelBySkel($vm, array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             'date', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             'authors' => array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             'contactInfos' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                 'tel', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                 'fax', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                 'mail', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             'movies' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                 array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                     'title', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                     'resume', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         ))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @expectedException        InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @expectedExceptionMessage date not exists | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 58 |  | View Code Duplication |     public function testValidateViewModelBySkelExceptionOne() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $assembler = new ViewModelAssemblerTestClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $assembler->validateViewModelBySkel(new ViewModelNode(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             'authors' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                 'gotakk', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                 'nickname' => 'gotakk', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         )), array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             'date', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             'authors' => array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @expectedException        InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @expectedExceptionMessage authors not exists | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 75 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |     public function testValidateViewModelBySkelExceptionTwo() | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |         $assembler = new ViewModelAssemblerTestClass(); | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |         $assembler->validateViewModelBySkel(new ViewModelNode(array( | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |             'date' => '2015-09-15', | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |         )), array( | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |             'date', | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |             'authors' => array(), | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |         )); | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @expectedException        InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @expectedExceptionMessage contactInfos not exists | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     public function testValidateViewModelBySkelExceptionThree() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $assembler = new ViewModelAssemblerTestClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $assembler->validateViewModelBySkel(new ViewModelNode(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             'date' => '2015-09-15', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             'authors' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                 'gotakk', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         )), array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             'date', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             'authors' => array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             'contactInfos' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                 'tel', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                 'fax', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                 'mail', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * @expectedException        InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * @expectedExceptionMessage authors is not sequential array. Contains not numeric key (nickname) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 114 |  | View Code Duplication |     public function testValidateViewModelBySkelExceptionSequentialArray() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         $assembler = new ViewModelAssemblerTestClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         $assembler->validateViewModelBySkel(new ViewModelNode(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             'date' => '2015-09-01', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |             'authors' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |                 'gotakk', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |                 'nickname' => 'gotakk', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         )), array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             'date', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             'authors' => array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 128 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 129 |  |  |  |