示例#1
0
 /**
  * Ensures that the validator follows expected behavior
  *
  * @return void
  */
 public function testBasic()
 {
     $valuesExpected = array(array('b2a5334847b4328e7d19d9b41fd874dffa911c98', true), array('52a5334847b4328e7d19d9b41fd874dffa911c98', false), array(array('42a5334847b4328e7d19d9b41fd874dffa911c98', 'b2a5334847b4328e7d19d9b41fd874dffa911c98'), true), array(array('42a5334847b4328e7d19d9b41fd874dffa911c98', '72a5334847b4328e7d19d9b41fd874dffa911c98'), false));
     foreach ($valuesExpected as $element) {
         $validator = new File\Sha1($element[0]);
         $this->assertEquals($element[1], $validator->isValid(dirname(__FILE__) . '/_files/picture.jpg'), "Tested with " . var_export($element, 1));
     }
     $validator = new File\Sha1('b2a5334847b4328e7d19d9b41fd874dffa911c98');
     $this->assertFalse($validator->isValid(dirname(__FILE__) . '/_files/nofile.mo'));
     $this->assertTrue(array_key_exists('fileSha1NotFound', $validator->getMessages()));
     $files = array('name' => 'test1', 'type' => 'text', 'size' => 200, 'tmp_name' => 'tmp_test1', 'error' => 0);
     $validator = new File\Sha1('b2a5334847b4328e7d19d9b41fd874dffa911c98');
     $this->assertFalse($validator->isValid(dirname(__FILE__) . '/_files/nofile.mo', $files));
     $this->assertTrue(array_key_exists('fileSha1NotFound', $validator->getMessages()));
     $files = array('name' => 'testsize.mo', 'type' => 'text', 'size' => 200, 'tmp_name' => dirname(__FILE__) . '/_files/testsize.mo', 'error' => 0);
     $validator = new File\Sha1('b2a5334847b4328e7d19d9b41fd874dffa911c98');
     $this->assertTrue($validator->isValid(dirname(__FILE__) . '/_files/picture.jpg', $files));
     $files = array('name' => 'testsize.mo', 'type' => 'text', 'size' => 200, 'tmp_name' => dirname(__FILE__) . '/_files/testsize.mo', 'error' => 0);
     $validator = new File\Sha1('42a5334847b4328e7d19d9b41fd874dffa911c98');
     $this->assertFalse($validator->isValid(dirname(__FILE__) . '/_files/picture.jpg', $files));
     $this->assertTrue(array_key_exists('fileSha1DoesNotMatch', $validator->getMessages()));
 }
示例#2
0
 /**
  * @group ZF-11258
  */
 public function testZF11258()
 {
     $validator = new File\Sha1('12345');
     $this->assertFalse($validator->isValid(__DIR__ . '/_files/nofile.mo'));
     $this->assertTrue(array_key_exists('fileSha1NotFound', $validator->getMessages()));
     $this->assertContains("'nofile.mo'", current($validator->getMessages()));
 }
示例#3
0
 public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage()
 {
     $validator = new File\Sha1();
     $this->assertFalse($validator->isValid(''));
     $this->assertArrayHasKey(File\Sha1::NOT_FOUND, $validator->getMessages());
     $filesArray = array('name' => '', 'size' => 0, 'tmp_name' => '', 'error' => UPLOAD_ERR_NO_FILE, 'type' => '');
     $this->assertFalse($validator->isValid($filesArray));
     $this->assertArrayHasKey(File\Sha1::NOT_FOUND, $validator->getMessages());
 }