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\Crc32($element[0]);
         $this->assertEquals($element[1], $validator->isValid(__DIR__ . '/_files/picture.jpg'), "Tested with " . var_export($element, 1));
     }
     $validator = new File\Crc32('3f8d07e2');
     $this->assertFalse($validator->isValid(__DIR__ . '/_files/nofile.mo'));
     $this->assertTrue(array_key_exists('fileCrc32NotFound', $validator->getMessages()));
     $files = array('name' => 'test1', 'type' => 'text', 'size' => 200, 'tmp_name' => 'tmp_test1', 'error' => 0);
     $validator = new File\Crc32('3f8d07e2');
     $this->assertFalse($validator->isValid(__DIR__ . '/_files/nofile.mo', $files));
     $this->assertTrue(array_key_exists('fileCrc32NotFound', $validator->getMessages()));
     $files = array('name' => 'testsize.mo', 'type' => 'text', 'size' => 200, 'tmp_name' => __DIR__ . '/_files/testsize.mo', 'error' => 0);
     $validator = new File\Crc32('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\Crc32('9f8d07e2');
     $this->assertFalse($validator->isValid(__DIR__ . '/_files/picture.jpg', $files));
     $this->assertTrue(array_key_exists('fileCrc32DoesNotMatch', $validator->getMessages()));
 }
Exemplo n.º 2
0
 public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage()
 {
     $validator = new File\Crc32();
     $this->assertFalse($validator->isValid(''));
     $this->assertArrayHasKey(File\Crc32::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\Crc32::NOT_FOUND, $validator->getMessages());
 }
Exemplo n.º 3
0
 /**
  * @group ZF-11258
  */
 public function testZF11258()
 {
     $validator = new File\Crc32('3f8d07e2');
     $this->assertFalse($validator->isValid(__DIR__ . '/_files/nofile.mo'));
     $this->assertTrue(array_key_exists('fileCrc32NotFound', $validator->getMessages()));
     $this->assertContains("does not exist", current($validator->getMessages()));
 }