public function validate(CM_Frontend_Environment $environment, $userInput) { if (isset($this->_options['lengthMax']) && mb_strlen($userInput) > $this->_options['lengthMax']) { throw new CM_Exception_FormFieldValidation(new CM_I18n_Phrase('Too long')); } if (isset($this->_options['lengthMin']) && mb_strlen($userInput) < $this->_options['lengthMin']) { throw new CM_Exception_FormFieldValidation(new CM_I18n_Phrase('Too short')); } if (!empty($this->_options['forbidBadwords'])) { $badwordList = new CM_Paging_ContentList_Badwords(); if ($badword = $badwordList->getMatch($userInput)) { throw new CM_Exception_FormFieldValidation(new CM_I18n_Phrase('The word `{$badword}` is not allowed', ['badword' => $badword])); } } return $userInput; }
public function testGetMatch() { $this->assertSame('bad.com', $this->_paging->getMatch('bad.com')); $this->assertSame('bad.com', $this->_paging->getMatch('BAD.com')); $this->assertSame('bad.com', $this->_paging->getMatch('sub.bad.com')); $this->assertSame('bad.com', $this->_paging->getMatch('bad.com-foo.de')); $this->assertFalse($this->_paging->getMatch('evil.com')); $this->assertSame('foobar', $this->_paging->getMatch('foo-bar')); $this->assertSame('foobar', $this->_paging->getMatch('hallo foo-bar world.')); $this->assertSame('zoo', $this->_paging->getMatch('test zoo test')); $this->assertFalse($this->_paging->getMatch('testzoo')); $this->assertFalse($this->_paging->getMatch('testzootest')); $this->assertFalse($this->_paging->getMatch('test zootest')); $this->_paging->add('evil.com'); $this->assertSame('evil.com', $this->_paging->getMatch('evil.com')); }