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