mmm... that test should fail but no

This commit is contained in:
Arandi Lopez 2017-06-21 11:13:36 -05:00
parent f046206e3b
commit d396cb076e
2 changed files with 17 additions and 39 deletions

View File

@ -34,6 +34,7 @@ return [
'sex', 'sex',
'shit', 'shit',
'slut', 'slut',
'sucker',
'titties', 'titties',
'twat', 'twat',
'vagina', 'vagina',

View File

@ -6,27 +6,28 @@ use \Mockery as m;
class ProfaneValidatorTest extends PHPUnit_Framework_TestCase class ProfaneValidatorTest extends PHPUnit_Framework_TestCase
{ {
public function setUp()
{
parent::setUp();
$this->mockConfigs();
}
public function tearDown() public function tearDown()
{ {
parent::tearDown(); parent::tearDown();
m::close(); m::close();
} }
public function test_can_validate_a_word() public function test_can_validate_a_word_with_numbers()
{ {
$this->mockConfigs();
$attribute = 'username'; $attribute = 'username';
$word = 'culero23'; $word = 'culero23';
$parameters = ['es']; $parameters = ['es'];
$profane = new ProfaneValidator(); $profane = new ProfaneValidator();
$this->assertFalse($profane->validate($attribute, $word, $parameters)); $this->assertFalse($profane->validate($attribute, $word, $parameters));
} }
public function test_can_validate_a_text() public function test_can_validate_a_text()
{ {
$this->mockConfigs();
$attribute = 'description'; $attribute = 'description';
$text = 'fck you bitch. 幹!'; $text = 'fck you bitch. 幹!';
$parameters = ['es', 'en' , 'zh-tw']; $parameters = ['es', 'en' , 'zh-tw'];
@ -39,71 +40,58 @@ class ProfaneValidatorTest extends PHPUnit_Framework_TestCase
public function test_can_evaluate_profanity_of_a_word() public function test_can_evaluate_profanity_of_a_word()
{ {
$word = 'fuck'; $word = 'fuck';
$this->mockConfigs();
$profane = new ProfaneValidator(); $profane = new ProfaneValidator();
$this->assertTrue($profane->isProfane($word)); $this->assertTrue($profane->isProfane($word));
} }
public function test_can_evaluate_profanity_of_a_sentence() public function test_can_evaluate_profanity_of_a_sentence()
{ {
$word = 'fuck you if you read this'; $word = 'fuck you if you read this';
$this->mockConfigs();
$profane = new ProfaneValidator(); $profane = new ProfaneValidator();
$this->assertTrue($profane->isProfane($word)); $this->assertTrue($profane->isProfane($word));
} }
public function test_can_evaluate_profanity_of_a_html_string() public function test_can_evaluate_profanity_of_a_html_string()
{ {
$word = '<b>fuck</b> you if you read this.'; $word = '<b>fuck</b> you if you read this.';
$this->mockConfigs();
$profane = new ProfaneValidator(); $profane = new ProfaneValidator();
$this->assertTrue($profane->isProfane($word)); $this->assertTrue($profane->isProfane($word));
} }
public function test_can_evaluate_as_caseless_mode() public function test_can_evaluate_as_caseless_mode()
{ {
$word = '<b>FUCK</b> you BITCH if you read this.'; $word = '<b>FUCK</b> you BITCH if you read this.';
$this->mockConfigs();
$profane = new ProfaneValidator(); $profane = new ProfaneValidator();
$this->assertTrue($profane->isProfane($word)); $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() public function test_can_set_dictionary_when_you_pass_a_locale()
{ {
$this->mockConfigs();
$profane = new ProfaneValidator(); $profane = new ProfaneValidator();
$profane->setDictionary('es'); $profane->setDictionary('es');
$expected = include __DIR__.'/../src/dict/es.php'; $expected = include __DIR__.'/../src/dict/es.php';
$this->assertEquals($profane->getBadwords(), $expected); $this->assertEquals($profane->getBadwords(), $expected);
} }
public function test_can_set_dictionary_when_you_pass_a_file() public function test_can_set_dictionary_when_you_pass_a_file()
{ {
$this->mockConfigs();
$profane = new ProfaneValidator(); $profane = new ProfaneValidator();
$profane->setDictionary(__DIR__.'/../src/dict/es.php'); $profane->setDictionary(__DIR__.'/../src/dict/es.php');
$expected = include __DIR__.'/../src/dict/es.php'; $expected = include __DIR__.'/../src/dict/es.php';
$this->assertEquals($profane->getBadwords(), $expected); $this->assertEquals($profane->getBadwords(), $expected);
} }
public function test_can_set_dictionary_when_you_pass_an_array_of_files() public function test_can_set_dictionary_when_you_pass_an_array_of_files()
{ {
$this->mockConfigs();
$profane = new ProfaneValidator(); $profane = new ProfaneValidator();
$profane->setDictionary([__DIR__.'/../src/dict/es.php', __DIR__.'/../src/dict/en.php']); $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() public function test_can_set_dictionary_when_you_pass_an_array_of_locales()
{ {
$this->mockConfigs();
$profane = new ProfaneValidator(); $profane = new ProfaneValidator();
$profane->setDictionary(['es', 'en', 'it', 'zh-tw']); $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'); $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); $this->assertEquals($profane->getBadwords(), $expected);
} }
public function test_can_validate_a_bad_word_with_accent() public function test_can_validate_a_bad_word_with_accent()
{ {
$this->mockConfigs();
$profane = new ProfaneValidator(); $profane = new ProfaneValidator();
$profane->setDictionary('sk'); $profane->setDictionary('sk');
$word = "piča"; $word = "piča";
$this->assertTrue( $profane->isProfane($word) ); $this->assertTrue( $profane->isProfane($word) );
} }
public function test_enie_in_spanish_is_evaluated() public function test_enie_in_spanish_is_evaluated()
{ {
$this->mockConfigs();
$profane = new ProfaneValidator(); $profane = new ProfaneValidator();
$profane->setDictionary('es'); $profane->setDictionary('es');
$word = "coño"; $word = "coño";
// in spanish coño =! cono
$this->assertTrue( $profane->isProfane($word) ); $this->assertTrue( $profane->isProfane($word) );
} }