Ejemplo n.º 1
0
 /**
  * Ensures that the validator follows expected behavior
  *
  * @return void
  */
 public function testBasic()
 {
     $valuesExpected = array(array(array('minwidth' => 0, 'minheight' => 10, 'maxwidth' => 1000, 'maxheight' => 2000), true), array(array('minwidth' => 0, 'minheight' => 0, 'maxwidth' => 200, 'maxheight' => 200), true), array(array('minwidth' => 150, 'minheight' => 150, 'maxwidth' => 200, 'maxheight' => 200), false), array(array('minwidth' => 80, 'minheight' => 0, 'maxwidth' => 80, 'maxheight' => 200), true), array(array('minwidth' => 0, 'minheight' => 0, 'maxwidth' => 60, 'maxheight' => 200), false), array(array('minwidth' => 90, 'minheight' => 0, 'maxwidth' => 200, 'maxheight' => 200), false), array(array('minwidth' => 0, 'minheight' => 0, 'maxwidth' => 200, 'maxheight' => 80), false), array(array('minwidth' => 0, 'minheight' => 110, 'maxwidth' => 200, 'maxheight' => 140), false));
     foreach ($valuesExpected as $element) {
         $validator = new File\ImageSize($element[0]);
         $this->assertEquals($element[1], $validator->isValid(__DIR__ . '/_files/picture.jpg'), "Tested with " . var_export($element, 1));
     }
     $validator = new File\ImageSize(array('minwidth' => 0, 'minheight' => 10, 'maxwidth' => 1000, 'maxheight' => 2000));
     $this->assertEquals(false, $validator->isValid(__DIR__ . '/_files/nofile.jpg'));
     $failures = $validator->getMessages();
     $this->assertContains('is not readable', $failures['fileImageSizeNotReadable']);
     $file['name'] = 'TestName';
     $validator = new File\ImageSize(array('minwidth' => 0, 'minheight' => 10, 'maxwidth' => 1000, 'maxheight' => 2000));
     $this->assertEquals(false, $validator->isValid(__DIR__ . '/_files/nofile.jpg', $file));
     $failures = $validator->getMessages();
     $this->assertContains('TestName', $failures['fileImageSizeNotReadable']);
     $validator = new File\ImageSize(array('minwidth' => 0, 'minheight' => 10, 'maxwidth' => 1000, 'maxheight' => 2000));
     $this->assertEquals(false, $validator->isValid(__DIR__ . '/_files/badpicture.jpg'));
     $failures = $validator->getMessages();
     $this->assertContains('could not be detected', $failures['fileImageSizeNotDetected']);
 }
Ejemplo n.º 2
0
 /**
  * @group ZF-11258
  */
 public function testZF11258()
 {
     $validator = new File\ImageSize(array('minWidth' => 100, 'minHeight' => 1000, 'maxWidth' => 10000, 'maxHeight' => 100000));
     $this->assertFalse($validator->isValid(__DIR__ . '/_files/nofile.mo'));
     $this->assertTrue(array_key_exists('fileImageSizeNotReadable', $validator->getMessages()));
     $this->assertContains("'nofile.mo'", current($validator->getMessages()));
 }
Ejemplo n.º 3
0
 public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage()
 {
     $validator = new File\ImageSize();
     $this->assertFalse($validator->isValid(''));
     $this->assertArrayHasKey(File\ImageSize::NOT_READABLE, $validator->getMessages());
     $filesArray = array('name' => '', 'size' => 0, 'tmp_name' => '', 'error' => UPLOAD_ERR_NO_FILE, 'type' => '');
     $this->assertFalse($validator->isValid($filesArray));
     $this->assertArrayHasKey(File\ImageSize::NOT_READABLE, $validator->getMessages());
 }