Exemple #1
0
 /**
  * @group ZF-11267
  * If we pass in a validator instance that has a preset custom message, this
  * message should be used.
  */
 function testIfCustomMessagesOnValidatorInstancesCanBeUsed()
 {
     // test with a Digits validator
     require_once 'Zend/Validate/Digits.php';
     require_once 'Zend/Validate/NotEmpty.php';
     $data = array('field1' => 'invalid data');
     $customMessage = 'Hey, that\'s not a Digit!!!';
     $validator = new Zend_Validate_Digits();
     $validator->setMessage($customMessage, 'notDigits');
     $this->assertFalse($validator->isValid('foo'), 'standalone validator thinks \'foo\' is a valid digit');
     $messages = $validator->getMessages();
     $this->assertSame($messages['notDigits'], $customMessage, 'stanalone validator does not have custom message');
     $validators = array('field1' => $validator);
     $input = new Zend_Filter_Input(null, $validators, $data);
     $this->assertFalse($input->isValid(), 'invalid input is valid');
     $messages = $input->getMessages();
     $this->assertSame($messages['field1']['notDigits'], $customMessage, 'The custom message is not used');
     // test with a NotEmpty validator
     $data = array('field1' => '');
     $customMessage = 'You should really supply a value...';
     $validator = new Zend_Validate_NotEmpty();
     $validator->setMessage($customMessage, 'isEmpty');
     $this->assertFalse($validator->isValid(''), 'standalone validator thinks \'\' is not empty');
     $messages = $validator->getMessages();
     $this->assertSame($messages['isEmpty'], $customMessage, 'stanalone NotEmpty validator does not have custom message');
     $validators = array('field1' => $validator);
     $input = new Zend_Filter_Input(null, $validators, $data);
     $this->assertFalse($input->isValid(), 'invalid input is valid');
     $messages = $input->getMessages();
     $this->assertSame($messages['field1']['isEmpty'], $customMessage, 'For the NotEmpty validator the custom message is not used');
 }
Exemple #2
0
 /**
  * validate the body
  *
  * @param string  $body
  * @return boolean
  */
 private function validateBody($body)
 {
     $notEmptyValidator = new \Zend_Validate_NotEmpty();
     if (!$notEmptyValidator->isValid($body)) {
         $messages = array_values($notEmptyValidator->getMessages());
         $this->addError(new Error('body', $body, $messages));
         return false;
     }
     return true;
 }
 /**
  * Ensures that getMessages() returns expected default value
  *
  * @return void
  */
 public function testGetMessages()
 {
     $this->assertEquals(array(), $this->_validator->getMessages());
 }
 /**
  * set a specific search location
  * examples:
  * +47°54’53.10”, 11° 10’ 56.76”
  * 47°54’53.10;11°10’56.76”
  * 47.914750,11.182533
  * +47.914750 ; +11.1824
  * Darmstadt
  * Berlin
  *
  * @param string $where
  * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters
  */
 public function setWhere($where)
 {
     require_once 'Zend/Validate/NotEmpty.php';
     $validator = new Zend_Validate_NotEmpty();
     if (!$validator->isValid($where)) {
         $message = $validator->getMessages();
         require_once 'Zend/Service/DeveloperGarden/LocalSearch/Exception.php';
         throw new Zend_Service_DeveloperGarden_LocalSearch_Exception(current($message));
     }
     $this->_parameters['where'] = $where;
     return $this;
 }
 /**
  * Validate data.
  * If fails validation, then this method returns false, and
  * getErrors() will return an array of errors that explain why the
  * validation failed.
  *
  * @param array $data
  * @param bool $isPartial
  * @return bool
  */
 public function isValidData(array $data, $isPartial = false)
 {
     $isValid = true;
     // required fields
     if (!$isPartial && count($this->_requiredFields) > 0) {
         $notEmptyValidator = new Zend_Validate_NotEmpty();
         foreach ($this->_requiredFields as $requiredField) {
             if (!$notEmptyValidator->isValid(isset($data[$requiredField]) ? $data[$requiredField] : null)) {
                 $isValid = false;
                 foreach ($notEmptyValidator->getMessages() as $message) {
                     $this->_addError(sprintf('%s: %s', $requiredField, $message));
                 }
             }
         }
     }
     // fields rules
     foreach ($data as $field => $value) {
         if (isset($this->_validators[$field])) {
             /* @var $validator Zend_Validate_Interface */
             $validator = $this->_validators[$field];
             if (!$validator->isValid($value)) {
                 $isValid = false;
                 foreach ($validator->getMessages() as $message) {
                     $this->_addError(sprintf('%s: %s', $field, $message));
                 }
             }
         }
     }
     return $isValid;
 }
Exemple #6
0
 /**
  * @ZF-8767
  *
  * @return void
  */
 public function testZF8767()
 {
     $valid = new Zend_Validate_NotEmpty(Zend_Validate_NotEmpty::STRING);
     $this->assertFalse($valid->isValid(''));
     $messages = $valid->getMessages();
     $this->assertTrue(array_key_exists('isEmpty', $messages));
     $this->assertContains("can't be empty", $messages['isEmpty']);
 }
 /**
  * LogBook modify Record action
  *
  */
 function modifyAction()
 {
     $this->view->title = $this->view->translate->_("Logbook: modify record");
     $this->view->wblogbook = new Wblogbook();
     $this->view->amessages = array();
     // ****************************** UPDATE record **********************************
     if ($this->_request->isPost() && $this->_request->getPost('hiddenModify') && $this->_request->getPost('act') == 'update') {
         $logid = trim($this->_request->getPost('logid'));
         // ********************* validate datetime
         $validator_datetime = new MyClass_Validate_Datetime();
         $logDateCreate = trim($this->_request->getPost('logDateCreate'));
         if (!$validator_datetime->isValid($logDateCreate)) {
             $this->view->amessages = array_merge($this->view->amessages, $validator_datetime->getMessages());
         }
         // ********************* validate text
         // This filter returns the input string, with all HTML and PHP tags stripped from it,
         // except those that have been explicitly allowed.
         Zend_Loader::loadClass('Zend_Filter_StripTags');
         // allow :
         // construct($tagsAllowed = null, $attributesAllowed = null, $commentsAllowed = false)
         $strip_tags = new Zend_Filter_StripTags($this->aAllowedTags, $this->aAllowedAttrs, false);
         $logTxt = trim($strip_tags->filter($this->_request->getPost('logTxt')));
         $validator_nonempty = new Zend_Validate_NotEmpty();
         if (!$validator_nonempty->isValid($logTxt)) {
             $this->view->amessages = array_merge($this->view->amessages, $validator_nonempty->getMessages());
         }
         // *** validate pseudo tag BACULA_JOBID
         $validator_baculajobid = new MyClass_Validate_BaculaJobId();
         if (!$validator_baculajobid->isValid($logTxt)) {
             $this->view->amessages = array_merge($this->view->amessages, $validator_baculajobid->getMessages());
         }
         // *** validate pseudo tag LOGBOOK_ID
         $validator_logbookid = new MyClass_Validate_LogbookId();
         if (!$validator_logbookid->isValid($logTxt)) {
             $this->view->amessages = array_merge($this->view->amessages, $validator_logbookid->getMessages());
         }
         // ********************* final
         // update record into database
         if (empty($this->view->amessages)) {
             // validation is OK. add record into logbook
             $table = new wbLogBook();
             $data = array('logDateCreate' => $logDateCreate, 'logDateLast' => date('Y-m-d H:i:s', time()), 'logTypeId' => (int) trim($this->_request->getPost('logTypeId')), 'logTxt' => $logTxt, 'logIsDel' => (int) trim($this->_request->getPost('isdel')));
             $where = $table->getAdapter()->quoteInto('logId = ?', $logid);
             $res = $table->update($data, $where);
             // send email
             if ($res) {
                 $email = new MyClass_SendEmail();
                 // $from_email, $from_name, $to_email, $to_name, $subj, $body
                 $email->mySendEmail($this->view->config->webacula->email->from, $this->view->translate->_('Webacula Logbook'), $this->view->config->webacula->email->to_admin, $this->view->translate->_('Webacula admin'), $this->view->translate->_('Webacula Logbook Update record'), $this->view->translate->_('Create record :') . ' ' . $data['logDateCreate'] . "\n" . $this->view->translate->_('Update record :') . ' ' . $data['logDateLast'] . "\n" . $this->view->translate->_('Type record :') . ' ' . $data['logTypeId'] . "\n" . $this->view->translate->_("Text :") . "\n-------\n" . $data['logTxt'] . "\n-------\n\n");
             }
             $this->_redirect('/wblogbook/index');
             return;
         }
         // ********************* save user input for correct this
         $this->view->wblogbook->logTxt = $strip_tags->filter($this->_request->getPost('logTxt'));
         $this->view->wblogbook->logTypeId = $this->_request->getPost('logTypeId');
     }
     // ****************************** DELETE record **********************************
     if ($this->_request->isPost() && $this->_request->getPost('hiddenModify') && $this->_request->getPost('act') == 'delete') {
         $logid = trim($this->_request->getPost('logid'));
         $table = new wbLogBook();
         $data = array('logIsDel' => '1');
         $where = $table->getAdapter()->quoteInto('logId = ?', $logid);
         $res = $table->update($data, $where);
         // send email
         if ($res) {
             $email = new MyClass_SendEmail();
             // $from_email, $from_name, $to_email, $to_name, $subj, $body
             $email->mySendEmail($this->view->config->webacula->email->from, $this->view->translate->_('Webacula Logbook'), $this->view->config->webacula->email->to_admin, $this->view->translate->_('Webacula admin'), $this->view->translate->_('Webacula Logbook Delete record'), $this->view->translate->_("LogId record :") . " " . $logid . "\n");
         }
         $this->_redirect('/wblogbook/index');
         return;
     }
     // ****************************** UNDELETE record **********************************
     if ($this->_request->isPost() && $this->_request->getPost('hiddenModify') && $this->_request->getPost('act') == 'undelete') {
         $logid = trim($this->_request->getPost('logid'));
         $table = new wbLogBook();
         $data = array('logIsDel' => '0');
         $where = $table->getAdapter()->quoteInto('logId = ?', $logid);
         $res = $table->update($data, $where);
         // send email
         if ($res) {
             $email = new MyClass_SendEmail();
             // $from_email, $from_name, $to_email, $to_name, $subj, $body
             $email->mySendEmail($this->view->config->webacula->email->from, $this->view->translate->_('Webacula Logbook'), $this->view->config->webacula->email->to_admin, $this->view->translate->_('Webacula admin'), $this->view->translate->_('Webacula Logbook UnDelete record'), $this->view->translate->_("LogId record :") . " " . $logid . "\n");
         }
         $this->_redirect('/wblogbook/index');
         return;
     }
     // ********************* READ ORIGINAL RECORD from database ****************
     if ($this->_request->isPost()) {
         $logid = trim($this->_request->getPost('logid'));
         // get data from table
         $logs = new wbLogBook();
         $where = $logs->getAdapter()->quoteInto('logId = ?', $logid);
         $row = $logs->fetchRow($where);
         if ($row) {
             $this->view->wblogbook->logId = $row->logid;
             $this->view->wblogbook->logDateCreate = $row->logdatecreate;
             $this->view->wblogbook->logTxt = $row->logtxt;
             $this->view->wblogbook->logTypeId = $row->logtypeid;
             $this->view->wblogbook->logIsDel = $row->logisdel;
         }
     }
     // for draw form
     Zend_Loader::loadClass('Wblogtype');
     // get data from wbLogType
     $typs = new Wblogtype();
     $this->view->typs = $typs->fetchAll();
     // common fileds
     $this->view->wblogbook->logDateLast = date('Y-m-d H:i:s', time());
     $this->view->hiddenModify = 1;
     $this->view->aAllowedTags = $this->aAllowedTags;
 }
Exemple #8
0
 /**
  * @param  mixed $width
  * @param  mixed $height
  * @return boolean
  */
 private function validateBothMaxIconValuesAreSet($width, $height)
 {
     $maxIconValidator = new NotEmptyValidator(NotEmptyValidator::NULL);
     if ($maxIconValidator->isValid($width) && !$maxIconValidator->isValid($height)) {
         $maxIconValidator->setMessage("'maxiconheight' can not be empty when 'maxiconwidth' is set", NotEmptyValidator::IS_EMPTY);
         $messages = array_values($maxIconValidator->getMessages());
         $this->addError(new Error('maxiconheight', $height, $messages));
         return false;
     }
     if (!$maxIconValidator->isValid($width) && $maxIconValidator->isValid($height)) {
         $maxIconValidator->setMessage("'maxiconwidth' can not be empty when 'maxiconheight' is set", NotEmptyValidator::IS_EMPTY);
         $messages = array_values($maxIconValidator->getMessages());
         $this->addError(new Error('maxiconwidth', $width, $messages));
         return false;
     }
     return true;
 }