| @@ 26-46 (lines=21) @@ | ||
| 23 | ->getMock(); | |
| 24 | } | |
| 25 | ||
| 26 | public function testValid() | |
| 27 |     { | |
| 28 | $uploadedFile = $this->getMockFileUpload(); | |
| 29 | $uploadedFile->expects($this->once()) | |
| 30 |                      ->method('getClientOriginalExtension') | |
| 31 | ->will( | |
| 32 |                          $this->returnValue('jpg') | |
| 33 | ); | |
| 34 | $uploadedFile->expects($this->once()) | |
| 35 |                      ->method('guessExtension') | |
| 36 | ->will( | |
| 37 |                          $this->returnValue('jpg') | |
| 38 | ); | |
| 39 | ||
| 40 | // Test the validator. | |
| 41 | $validator = new FileValidator(); | |
| 42 | ||
| 43 | $valid = $validator->validate($uploadedFile); | |
| 44 | ||
| 45 | $this->assertTrue($valid); | |
| 46 | } | |
| 47 | ||
| 48 | public function testUnsupportedFileType() | |
| 49 |     { | |
| @@ 48-68 (lines=21) @@ | ||
| 45 | $this->assertTrue($valid); | |
| 46 | } | |
| 47 | ||
| 48 | public function testUnsupportedFileType() | |
| 49 |     { | |
| 50 | $uploadedFile = $this->getMockFileUpload(); | |
| 51 | $uploadedFile->expects($this->once()) | |
| 52 |                      ->method('getClientOriginalExtension') | |
| 53 | ->will( | |
| 54 |                          $this->returnValue('doc') | |
| 55 | ); | |
| 56 | $uploadedFile->expects($this->once()) | |
| 57 |                      ->method('guessExtension') | |
| 58 | ->will( | |
| 59 |                          $this->returnValue('doc') | |
| 60 | ); | |
| 61 | ||
| 62 | // Test the validator. | |
| 63 | $validator = new FileValidator(); | |
| 64 | ||
| 65 | $valid = $validator->validate($uploadedFile); | |
| 66 | ||
| 67 | $this->assertFalse($valid); | |
| 68 | } | |
| 69 | ||
| 70 | public function testMimeAndExtensionDontMatch() | |
| 71 |     { | |
| @@ 70-90 (lines=21) @@ | ||
| 67 | $this->assertFalse($valid); | |
| 68 | } | |
| 69 | ||
| 70 | public function testMimeAndExtensionDontMatch() | |
| 71 |     { | |
| 72 | $uploadedFile = $this->getMockFileUpload(); | |
| 73 | $uploadedFile->expects($this->once()) | |
| 74 |                      ->method('getClientOriginalExtension') | |
| 75 | ->will( | |
| 76 |                          $this->returnValue('jpg') | |
| 77 | ); | |
| 78 | $uploadedFile->expects($this->once()) | |
| 79 |                      ->method('guessExtension') | |
| 80 | ->will( | |
| 81 |                          $this->returnValue('png') | |
| 82 | ); | |
| 83 | ||
| 84 | // Test the validator. | |
| 85 | $validator = new FileValidator(); | |
| 86 | ||
| 87 | $valid = $validator->validate($uploadedFile); | |
| 88 | ||
| 89 | $this->assertFalse($valid); | |
| 90 | } | |
| 91 | } | |
| 92 | ||