| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace DmFilemanTest\InputFilter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use DmFileman\InputFilter\DeleteFile; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use DmFileman\Form\DeleteFileForm as Form; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class DeleteFileTest extends \PHPUnit_Framework_TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     /** @var DeleteFile */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     protected $sut; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     protected function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         $this->sut = new DeleteFile(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $this->sut->init(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     private function fileDataProvider() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |                 ['isEmpty'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |                 Form::NAME | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                 false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                 ['isEmpty'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                 Form::NAME | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                 '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                 ['isEmpty'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                 Form::NAME | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                 'foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                 [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                 Form::NAME | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                 str_repeat('abcdefghij', 16), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                 [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                 Form::NAME | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 str_repeat('abcdefghij', 16) . 'a', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                 ['stringLengthTooLong'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                 Form::NAME | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     private function securityDataProvider() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 ['isEmpty'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                 Form::SECURITY | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                 false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                 ['isEmpty'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                 Form::SECURITY | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                 '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                 ['isEmpty'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                 Form::SECURITY | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                 'foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                 [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                 Form::SECURITY | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     public function inputDataProvider() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         return array_merge( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             $this->fileDataProvider(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             $this->securityDataProvider(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * @covers       DmFileman\InputFilter\DeleteFile | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * @dataProvider inputDataProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * @param mixed  $nameData | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * @param array  $expectedMessages | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * @param string $inputName | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 107 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 108 |  |  |     public function testValidation($nameData, array $expectedMessages, $inputName) | 
            
                                                        
            
                                    
            
            
                | 109 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 110 |  |  |         $this->sut->setData([$inputName => $nameData]); | 
            
                                                        
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 112 |  |  |         $this->sut->isValid(); | 
            
                                                        
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 114 |  |  |         $actualMessages = $this->sut->getMessages(); | 
            
                                                        
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 116 |  |  |         $this->assertInternalType('array', $actualMessages); | 
            
                                                        
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 118 |  |  |         if ($expectedMessages) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 119 |  |  |             $this->assertArrayHasKey($inputName, $actualMessages); | 
            
                                                        
            
                                    
            
            
                | 120 |  |  |             $this->assertInternalType('array', $actualMessages[$inputName]); | 
            
                                                        
            
                                    
            
            
                | 121 |  |  |             $message = 'Found message keys: ' . implode(', ', array_keys($actualMessages[$inputName])); | 
            
                                                        
            
                                    
            
            
                | 122 |  |  |             foreach ($expectedMessages as $expectedMessage) { | 
            
                                                        
            
                                    
            
            
                | 123 |  |  |                 $this->assertArrayHasKey($expectedMessage, $actualMessages[$inputName], $message); | 
            
                                                        
            
                                    
            
            
                | 124 |  |  |             } | 
            
                                                        
            
                                    
            
            
                | 125 |  |  |         } else { | 
            
                                                        
            
                                    
            
            
                | 126 |  |  |             $message = ''; | 
            
                                                        
            
                                    
            
            
                | 127 |  |  |             if (isset($actualMessages[$inputName])) { | 
            
                                                        
            
                                    
            
            
                | 128 |  |  |                 $message = 'Found message keys: ' . implode(', ', array_keys($actualMessages[$inputName])); | 
            
                                                        
            
                                    
            
            
                | 129 |  |  |             } | 
            
                                                        
            
                                    
            
            
                | 130 |  |  |             $this->assertArrayNotHasKey($inputName, $actualMessages, $message); | 
            
                                                        
            
                                    
            
            
                | 131 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 132 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 133 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 134 |  |  |  | 
            
                        
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.