コード例 #1
0
ファイル: TextTest.php プロジェクト: cargomedia/cm
 public function testValidateBadwords()
 {
     $badwordsList = new CM_Paging_ContentList_Badwords();
     $field = new CM_FormField_Text(['name' => 'foo', 'forbidBadwords' => true]);
     $environment = new CM_Frontend_Environment();
     $render = new CM_Frontend_Render();
     try {
         $field->validate($environment, 'foo');
     } catch (CM_Exception_FormFieldValidation $ex) {
         $this->fail('Expected value not to be a badword');
     }
     $badwordsList->add('foo');
     try {
         $field->validate($environment, 'foo');
         $this->fail('Expected value to be a badword');
     } catch (CM_Exception_FormFieldValidation $ex) {
         $this->assertContains('The word `foo` is not allowed', $ex->getMessagePublic($render));
     }
     $field = new CM_FormField_Text(['name' => 'foo', 'forbidBadwords' => false]);
     try {
         $field->validate($environment, 'foo');
     } catch (CM_Exception_FormFieldValidation $ex) {
         $this->fail('Badword-validation shouldn\'t be activated');
     }
 }
コード例 #2
0
ファイル: BadwordsTest.php プロジェクト: cargomedia/cm
 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()));
 }
コード例 #3
0
ファイル: BadwordsTest.php プロジェクト: NicolasSchmutz/cm
 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'));
 }
コード例 #4
0
ファイル: UsertextTest.php プロジェクト: cargomedia/cm
 public function testAllowBadwords()
 {
     $usertext = new CM_Usertext_Usertext();
     $usertext->setMode('escape', ['allowBadwords' => true]);
     $badwordList = new CM_Paging_ContentList_Badwords();
     $badWord = 'testBad';
     $badwordList->add($badWord);
     $sentString = 'Hello i am ' . $badWord . ' !';
     $this->assertSame($sentString, $usertext->transform($sentString, new CM_Frontend_Render()));
 }
コード例 #5
0
ファイル: BadwordsTest.php プロジェクト: NicolasSchmutz/cm
 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);
 }