public function indexAction()
 {
     if (isset($_POST['username'])) {
         $data = [];
         $request = $this->getRequest();
         $username = $request->getPost('username');
         $age = $request->getPost('age');
         $emailAddress = $request->getPost('email');
         $digitsValidator = new Digits();
         $alphaValidator = new Alpha();
         $emailValidator = new EmailAddress();
         $data['age']['value'] = $age;
         $data['username']['value'] = $username;
         $data['email']['value'] = $emailAddress;
         if ($digitsValidator->isValid($age)) {
             $data['age']['message'] = 'Age = ' . $age . ' years old';
         } else {
             $data['age']['message'] = 'Age value invalid!';
         }
         if ($alphaValidator->isValid($username)) {
             $data['username']['message'] = 'Username = '******'username']['message'] = 'Username value invalid!';
         }
         if ($emailValidator->isValid($emailAddress)) {
             $data['email']['message'] = 'Email Address = ' . $emailAddress;
         } else {
             $data['email']['message'] = 'Email Address value invalid!';
         }
         $data['message'] = 'success';
     }
     return new ViewModel($data);
 }
Ejemplo n.º 2
0
 public function testMaximumErrorMessageLength()
 {
     $this->assertEquals(-1, AbstractValidator::getMessageLength());
     AbstractValidator::setMessageLength(10);
     $this->assertEquals(10, AbstractValidator::getMessageLength());
     $loader = new TestAsset\ArrayTranslator();
     $loader->translations = array(Alpha::INVALID => 'This is the translated message for %value%');
     $translator = new Translator\Translator();
     $translator->getPluginManager()->setService('default', $loader);
     $translator->addTranslationFile('default', null);
     $this->validator->setTranslator($translator);
     $this->assertFalse($this->validator->isValid(123));
     $messages = $this->validator->getMessages();
     $this->assertTrue(array_key_exists(Alpha::INVALID, $messages));
     $this->assertEquals('This is...', $messages[Alpha::INVALID]);
 }
Ejemplo n.º 3
0
 public function testMaximumErrorMessageLength()
 {
     if (!extension_loaded('intl')) {
         $this->markTestSkipped('ext/intl not enabled');
     }
     $this->assertEquals(-1, AbstractValidator::getMessageLength());
     AbstractValidator::setMessageLength(10);
     $this->assertEquals(10, AbstractValidator::getMessageLength());
     $loader = new TestAsset\ArrayTranslator();
     $loader->translations = array('Invalid type given. String expected' => 'This is the translated message for %value%');
     $translator = new TestAsset\Translator();
     $translator->getPluginManager()->setService('default', $loader);
     $translator->addTranslationFile('default', null);
     $this->validator->setTranslator($translator);
     $this->assertFalse($this->validator->isValid(123));
     $messages = $this->validator->getMessages();
     $this->assertTrue(array_key_exists(Alpha::INVALID, $messages));
     $this->assertEquals('This is...', $messages[Alpha::INVALID]);
 }
Ejemplo n.º 4
0
 /**
  * @ZF-4352
  */
 public function testNonStringValidation()
 {
     $this->assertFalse($this->validator->isValid(array(1 => 1)));
 }