Exemplo n.º 1
0
 /**
  * Ensures that the validator follows expected behavior
  *
  * @return void
  */
 public function testBasic()
 {
     $valuesExpected = array(array('3f8d07e2', true), array('9f8d07e2', false), array(array('9f8d07e2', '3f8d07e2'), true), array(array('9f8d07e2', '7f8d07e2'), false));
     foreach ($valuesExpected as $element) {
         $validator = new File\Hash($element[0]);
         $this->assertEquals($element[1], $validator->isValid(__DIR__ . '/_files/picture.jpg'), "Tested with " . var_export($element, 1));
     }
     $valuesExpected = array(array(array('ed74c22109fe9f110579f77b053b8bc3', 'algorithm' => 'md5'), true), array(array('4d74c22109fe9f110579f77b053b8bc3', 'algorithm' => 'md5'), false), array(array('4d74c22109fe9f110579f77b053b8bc3', 'ed74c22109fe9f110579f77b053b8bc3', 'algorithm' => 'md5'), true), array(array('1d74c22109fe9f110579f77b053b8bc3', '4d74c22109fe9f110579f77b053b8bc3', 'algorithm' => 'md5'), false));
     foreach ($valuesExpected as $element) {
         $validator = new File\Hash($element[0]);
         $this->assertEquals($element[1], $validator->isValid(__DIR__ . '/_files/picture.jpg'), "Tested with " . var_export($element, 1));
     }
     $validator = new File\Hash('3f8d07e2');
     $this->assertFalse($validator->isValid(__DIR__ . '/_files/nofile.mo'));
     $this->assertTrue(array_key_exists('fileHashNotFound', $validator->getMessages()));
     $files = array('name' => 'test1', 'type' => 'text', 'size' => 200, 'tmp_name' => 'tmp_test1', 'error' => 0);
     $validator = new File\Hash('3f8d07e2');
     $this->assertFalse($validator->isValid(__DIR__ . '/_files/nofile.mo', $files));
     $this->assertTrue(array_key_exists('fileHashNotFound', $validator->getMessages()));
     $files = array('name' => 'testsize.mo', 'type' => 'text', 'size' => 200, 'tmp_name' => __DIR__ . '/_files/testsize.mo', 'error' => 0);
     $validator = new File\Hash('3f8d07e2');
     $this->assertTrue($validator->isValid(__DIR__ . '/_files/picture.jpg', $files));
     $files = array('name' => 'testsize.mo', 'type' => 'text', 'size' => 200, 'tmp_name' => __DIR__ . '/_files/testsize.mo', 'error' => 0);
     $validator = new File\Hash('9f8d07e2');
     $this->assertFalse($validator->isValid(__DIR__ . '/_files/picture.jpg', $files));
     $this->assertTrue(array_key_exists('fileHashDoesNotMatch', $validator->getMessages()));
 }
Exemplo n.º 2
0
 /**
  * @group ZF-11258
  */
 public function testZF11258()
 {
     $validator = new File\Hash('3f8d07e2');
     $this->assertFalse($validator->isValid(__DIR__ . '/_files/nofile.mo'));
     $this->assertTrue(array_key_exists('fileHashNotFound', $validator->getMessages()));
     $this->assertContains("'nofile.mo'", current($validator->getMessages()));
 }
Exemplo n.º 3
0
 public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage()
 {
     $validator = new File\Hash();
     $this->assertFalse($validator->isValid(''));
     $this->assertArrayHasKey(File\Hash::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\Hash::NOT_FOUND, $validator->getMessages());
 }