Redaxscript\Controller\Comment::process PHP Method

process() public method

process the class
Since: 3.0.0
public process ( ) : string
return string
    public function process()
    {
        $specialFilter = new Filter\Special();
        $emailFilter = new Filter\Email();
        $urlFilter = new Filter\Url();
        $htmlFilter = new Filter\Html();
        /* process post */
        $postArray = ['author' => $specialFilter->sanitize($this->_request->getPost('author')), 'email' => $emailFilter->sanitize($this->_request->getPost('email')), 'url' => $urlFilter->sanitize($this->_request->getPost('url')), 'text' => $htmlFilter->sanitize($this->_request->getPost('text')), 'article' => $specialFilter->sanitize($this->_request->getPost('article')), 'task' => $this->_request->getPost('task'), 'solution' => $this->_request->getPost('solution')];
        $route = build_route('articles', $postArray['article']);
        /* handle error */
        $messageArray = $this->_validate($postArray);
        if ($messageArray) {
            return $this->_error(['route' => $route, 'message' => $messageArray]);
        }
        /* handle success */
        $createArray = ['author' => $postArray['author'], 'email' => $postArray['email'], 'url' => $postArray['url'], 'text' => $postArray['text'], 'language' => Db::forTablePrefix('articles')->whereIdIs($postArray['article'])->findOne()->language, 'article' => $postArray['article'], 'status' => Db::getSetting('verification') ? 0 : 1];
        $mailArray = ['email' => $postArray['email'], 'url' => $postArray['url'], 'route' => $route, 'author' => $postArray['author'], 'text' => $postArray['text'], 'article' => Db::forTablePrefix('articles')->whereIdIs($postArray['article'])->findOne()->title];
        /* create and mail */
        if ($this->_create($createArray) && $this->_mail($mailArray)) {
            return $this->_success(['route' => $route, 'timeout' => Db::getSetting('notification') ? 2 : 0, 'message' => Db::getSetting('moderation') ? $this->_language->get('comment_moderation') : $this->_language->get('comment_sent')]);
        }
        return $this->_error(['route' => $route, 'message' => $this->_language->get('something_wrong')]);
    }

Usage Example

Example #1
0
 /**
  * testProcess
  *
  * @since 3.0.0
  *
  * @param array $postArray
  * @param array $hashArray
  * @param array $settingArray
  * @param string $expect
  *
  * @dataProvider providerProcess
  */
 public function testProcess($postArray = [], $hashArray = [], $settingArray = [], $expect = null)
 {
     /* setup */
     Db::setSetting('notification', $settingArray['notification']);
     Db::setSetting('moderation', $settingArray['moderation']);
     $this->_request->set('post', $postArray);
     $this->_request->setPost('solution', function_exists('password_verify') ? $hashArray[0] : $hashArray[1]);
     $commentController = new Controller\Comment($this->_registry, $this->_language, $this->_request);
     /* actual */
     $actual = $commentController->process();
     /* compare */
     $this->assertEquals($expect, $actual);
 }