From d396cb076e78f3ee1b71420dd97690cc50905323 Mon Sep 17 00:00:00 2001 From: Arandi Lopez Date: Wed, 21 Jun 2017 11:13:36 -0500 Subject: [PATCH] mmm... that test should fail but no --- src/dict/en.php | 1 + tests/ProfaneValidatorTest.php | 55 ++++++++++------------------------ 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/src/dict/en.php b/src/dict/en.php index b2f33ae..e8eb72d 100644 --- a/src/dict/en.php +++ b/src/dict/en.php @@ -34,6 +34,7 @@ return [ 'sex', 'shit', 'slut', + 'sucker', 'titties', 'twat', 'vagina', diff --git a/tests/ProfaneValidatorTest.php b/tests/ProfaneValidatorTest.php index 63ce3d1..c37d145 100644 --- a/tests/ProfaneValidatorTest.php +++ b/tests/ProfaneValidatorTest.php @@ -6,27 +6,28 @@ use \Mockery as m; class ProfaneValidatorTest extends PHPUnit_Framework_TestCase { + public function setUp() + { + parent::setUp(); + $this->mockConfigs(); + } public function tearDown() { parent::tearDown(); m::close(); } - public function test_can_validate_a_word() + public function test_can_validate_a_word_with_numbers() { - $this->mockConfigs(); $attribute = 'username'; $word = 'culero23'; $parameters = ['es']; - $profane = new ProfaneValidator(); - $this->assertFalse($profane->validate($attribute, $word, $parameters)); } public function test_can_validate_a_text() { - $this->mockConfigs(); $attribute = 'description'; $text = 'fck you bitch. 幹!'; $parameters = ['es', 'en' , 'zh-tw']; @@ -39,71 +40,58 @@ class ProfaneValidatorTest extends PHPUnit_Framework_TestCase public function test_can_evaluate_profanity_of_a_word() { $word = 'fuck'; - $this->mockConfigs(); - $profane = new ProfaneValidator(); - $this->assertTrue($profane->isProfane($word)); } public function test_can_evaluate_profanity_of_a_sentence() { $word = 'fuck you if you read this'; - $this->mockConfigs(); - $profane = new ProfaneValidator(); - $this->assertTrue($profane->isProfane($word)); } public function test_can_evaluate_profanity_of_a_html_string() { $word = 'fuck you if you read this.'; - $this->mockConfigs(); - $profane = new ProfaneValidator(); - $this->assertTrue($profane->isProfane($word)); } public function test_can_evaluate_as_caseless_mode() { $word = 'FUCK you BITCH if you read this.'; - $this->mockConfigs(); - $profane = new ProfaneValidator(); - $this->assertTrue($profane->isProfane($word)); } + public function test_match_exact_word() + { + $profane = new ProfaneValidator(); + // it thinks class ~= ass + $this->assertTrue($profane->isProfane('class')); + // but this should be profane + $this->assertTrue($profane->isProfane('sucker96')); + } + public function test_can_set_dictionary_when_you_pass_a_locale() { - $this->mockConfigs(); - $profane = new ProfaneValidator(); $profane->setDictionary('es'); - $expected = include __DIR__.'/../src/dict/es.php'; - $this->assertEquals($profane->getBadwords(), $expected); } public function test_can_set_dictionary_when_you_pass_a_file() { - $this->mockConfigs(); - $profane = new ProfaneValidator(); $profane->setDictionary(__DIR__.'/../src/dict/es.php'); - $expected = include __DIR__.'/../src/dict/es.php'; - $this->assertEquals($profane->getBadwords(), $expected); } public function test_can_set_dictionary_when_you_pass_an_array_of_files() { - $this->mockConfigs(); - $profane = new ProfaneValidator(); $profane->setDictionary([__DIR__.'/../src/dict/es.php', __DIR__.'/../src/dict/en.php']); @@ -114,37 +102,26 @@ class ProfaneValidatorTest extends PHPUnit_Framework_TestCase public function test_can_set_dictionary_when_you_pass_an_array_of_locales() { - $this->mockConfigs(); - $profane = new ProfaneValidator(); $profane->setDictionary(['es', 'en', 'it', 'zh-tw']); - $expected = array_merge(include __DIR__.'/../src/dict/es.php', include __DIR__.'/../src/dict/en.php', include __DIR__.'/../src/dict/it.php', include __DIR__.'/../src/dict/zh-tw.php'); - $this->assertEquals($profane->getBadwords(), $expected); } public function test_can_validate_a_bad_word_with_accent() { - $this->mockConfigs(); - $profane = new ProfaneValidator(); $profane->setDictionary('sk'); - $word = "piča"; - $this->assertTrue( $profane->isProfane($word) ); } public function test_enie_in_spanish_is_evaluated() { - $this->mockConfigs(); - $profane = new ProfaneValidator(); $profane->setDictionary('es'); - $word = "coño"; - + // in spanish coño =! cono $this->assertTrue( $profane->isProfane($word) ); }