/** * testUrl * * @since 2.2.0 * * @param string $url * @param integer $expect * * @dataProvider providerValidatorUrl */ public function testUrl($url = null, $expect = null) { /* setup */ $validator = new Validator\Url(); /* result */ $result = $validator->validate($url); /* compare */ $this->assertEquals($expect, $result); }
/** * process * * @since 2.6.0 */ public static function _process() { $specialFilter = new Filter\Special(); $emailFilter = new Filter\Email(); $urlFilter = new Filter\Url(); $htmlFilter = new Filter\Html(); $emailValidator = new Validator\Email(); $urlValidator = new Validator\Url(); $captchaValidator = new Validator\Captcha(); /* process post */ $postData = array('author' => $specialFilter->sanitize(Request::getPost('author')), 'email' => $emailFilter->sanitize(Request::getPost('email')), 'url' => $urlFilter->sanitize(Request::getPost('url')), 'text' => nl2br($htmlFilter->sanitize(Request::getPost('text'))), 'task' => Request::getPost('task'), 'solution' => Request::getPost('solution')); /* validate post */ if (!$postData['author']) { $errorData['author'] = Language::get('author_empty'); } if (!$postData['email']) { $errorData['email'] = Language::get('email_empty'); } else { if ($emailValidator->validate($postData['email']) === Validator\ValidatorInterface::FAILED) { $errorData['email'] = Language::get('email_incorrect'); } } if ($errorData['url'] && $urlValidator->validate($postData['url']) === Validator\ValidatorInterface::FAILED) { $errorData['url'] = Language::get('url_incorrect'); } if (!$postData['text']) { $errorData['text'] = Language::get('message_empty'); } if ($captchaValidator->validate($postData['task'], $postData['solution']) === Validator\ValidatorInterface::FAILED) { $errorData['captcha'] = Language::get('captcha_incorrect'); } /* handle error */ if ($errorData) { notification(Language::get('error_occurred'), $errorData, Language::get('home'), Registry::get('root')); } else { notification(Language::get('operation_completed'), Language::get('message_sent', '_contact'), Language::get('home'), Registry::get('root')); self::_send($postData); } }
/** * validate * * @since 3.0.0 * * @param array $postArray array of the post * * @return array */ protected function _validate($postArray = []) { $emailValidator = new Validator\Email(); $captchaValidator = new Validator\Captcha(); $urlValidator = new Validator\Url(); /* validate post */ $messageArray = []; if (!$postArray['author']) { $messageArray[] = $this->_language->get('author_empty'); } if (!$postArray['email']) { $messageArray[] = $this->_language->get('email_empty'); } else { if ($emailValidator->validate($postArray['email']) === Validator\ValidatorInterface::FAILED) { $messageArray[] = $this->_language->get('email_incorrect'); } } if ($postArray['url'] && $urlValidator->validate($postArray['url']) === Validator\ValidatorInterface::FAILED) { $messageArray[] = $this->_language->get('url_incorrect'); } if (!$postArray['text']) { $messageArray[] = $this->_language->get('comment_empty'); } if (!$postArray['article']) { $messageArray[] = $this->_language->get('input_incorrect'); } if (Db::getSetting('captcha') > 0 && $captchaValidator->validate($postArray['task'], $postArray['solution']) === Validator\ValidatorInterface::FAILED) { $messageArray[] = $this->_language->get('captcha_incorrect'); } return $messageArray; }