Esempio n. 1
0
 public function testTransformCustomReplacement()
 {
     $filter = new CM_Usertext_Filter_Badwords('---');
     $badwords = new CM_Paging_ContentList_Badwords();
     $badwords->add('foo');
     $this->assertSame('--- bar', $filter->transform('foo bar', new CM_Frontend_Render()));
 }
Esempio n. 2
0
 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'])) {
         $badwordFilter = new CM_Usertext_Filter_Badwords();
         if ($badword = $badwordFilter->getMatch($userInput)) {
             throw new CM_Exception_FormFieldValidation(new CM_I18n_Phrase('The word `{$badword}` is not allowed', ['badword' => $badword]));
         }
     }
     return $userInput;
 }
Esempio n. 3
0
 public function testProcess()
 {
     $replace = '…';
     $badwords = new CM_Paging_ContentList_Badwords();
     $filter = new CM_Usertext_Filter_Badwords();
     $render = new CM_Frontend_Render();
     $actual = $filter->transform("hello foo there", $render);
     $this->assertSame("hello foo there", $actual);
     $badwords->add('foo');
     $badwords->add('x … x');
     $badwords->add('f(o-].)o');
     $badwords->add('bar');
     $badwords->add('foobar');
     $badwords->add('zoo*far');
     CMTest_TH::clearCache();
     $actual = $filter->transform("hello foo there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello x foo x there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello Foo there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello foot there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello f(o-].)o there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello bar there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello bart there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello bar3 there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello bartender there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello bar.de there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello bar. there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello foobar there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello XfoobarX there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello mayo.foobar.ran there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello zoofar there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello zoo!!far there", $render);
     $this->assertSame("hello {$replace} there", $actual);
     $actual = $filter->transform("hello zoo far there", $render);
     $this->assertSame("hello {$replace} there", $actual);
 }