Identation... If your are using a non supported locale, it wont try to loaded
This commit is contained in:
parent
076cde1a1b
commit
81082f9a07
|
|
@ -7,23 +7,23 @@ use Illuminate\Support\Facades\Lang;
|
||||||
|
|
||||||
class ProfaneServiceProvider extends ServiceProvider
|
class ProfaneServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
$this->loadTranslationsFrom(__DIR__.'/lang', 'laravel-profane');
|
$this->loadTranslationsFrom(__DIR__.'/lang', 'laravel-profane');
|
||||||
|
|
||||||
$this->publishes([
|
$this->publishes([
|
||||||
__DIR__.'/lang' => resource_path('lang/vendor/laravel-profane'),
|
__DIR__.'/lang' => resource_path('lang/vendor/laravel-profane'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Validator::extend('profane', 'LaravelProfane\ProfaneValidator@validate', Lang::get('laravel-profane::validation.profane'));
|
Validator::extend('profane', 'LaravelProfane\ProfaneValidator@validate', Lang::get('laravel-profane::validation.profane'));
|
||||||
|
|
||||||
Validator::replacer('profane', function($message, $attribute, $rule, $parameters) {
|
Validator::replacer('profane', function($message, $attribute, $rule, $parameters) {
|
||||||
return str_replace(':attribute', $attribute, $message);
|
return str_replace(':attribute', $attribute, $message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
// code...
|
// code...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,90 +8,92 @@ use Illuminate\Contracts\Validation\Validator;
|
||||||
class ProfaneValidator
|
class ProfaneValidator
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $badwords = [];
|
protected $badwords = [];
|
||||||
|
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
// Get default locale string in laravel project
|
// Get default locale string in laravel project
|
||||||
// and set it as default dictionary
|
// and set it as default dictionary
|
||||||
$locale_dict = Config::has('app.locale') ? Config::get('app.locale') : 'en';
|
$locale_dict = Config::has('app.locale') ? Config::get('app.locale') : 'en';
|
||||||
|
|
||||||
$this->setDictionary($locale_dict);
|
$this->setDictionary($locale_dict);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to extends to Validator
|
|
||||||
* @param string $attribute
|
|
||||||
* @param midex $value
|
|
||||||
* @param array $parameters
|
|
||||||
* @param \Illuminate\Contracts\Validation\Validator $validator [description]
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function validate($attribute, $value, $parameters)
|
|
||||||
{
|
|
||||||
if ($parameters) {
|
|
||||||
$this->setDictionary($parameters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return !$this->isProfane($value);
|
/**
|
||||||
}
|
* Method to extends to Validator
|
||||||
|
* @param string $attribute
|
||||||
/**
|
* @param midex $value
|
||||||
* Check profanity of text
|
* @param array $parameters
|
||||||
* @param string $text
|
* @param \Illuminate\Contracts\Validation\Validator $validator [description]
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isProfane($text)
|
public function validate($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
return Str::containsCaseless($text, $this->badwords);
|
if ($parameters) {
|
||||||
}
|
$this->setDictionary($parameters);
|
||||||
|
|
||||||
public function getBadwords()
|
|
||||||
{
|
|
||||||
return $this->badwords;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the dictionary to use
|
|
||||||
* @param array|string $dictionary
|
|
||||||
*/
|
|
||||||
public function setDictionary($dictionary)
|
|
||||||
{
|
|
||||||
$this->badwords = $this->readDictionary($dictionary);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function readDictionary($dictionary)
|
|
||||||
{
|
|
||||||
$badwords = [];
|
|
||||||
$baseDictPath = $this->getBaseDictPath();
|
|
||||||
if (is_array($dictionary)) {
|
|
||||||
foreach ($dictionary as $file) {
|
|
||||||
if (file_exists($baseDictPath.$file.'.php')) {
|
|
||||||
$dict = include($baseDictPath.$file.'.php');
|
|
||||||
$badwords = array_merge($badwords, $dict);
|
|
||||||
} else {
|
|
||||||
// if the file isn't in the dict directory,
|
|
||||||
// it's probably a custom user library
|
|
||||||
$dict = include($file);
|
|
||||||
$badwords = array_merge($badwords, $dict);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// just a single string, not an array
|
return !$this->isProfane($value);
|
||||||
} elseif (is_string($dictionary)) {
|
|
||||||
if (file_exists($baseDictPath.$dictionary.'.php')) {
|
|
||||||
$dict = include($baseDictPath.$dictionary.'.php');
|
|
||||||
$badwords = array_merge($badwords, $dict);
|
|
||||||
} else {
|
|
||||||
$dict = include($dictionary);
|
|
||||||
$badwords = array_merge($badwords, $dict);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $badwords;
|
/**
|
||||||
}
|
* Check profanity of text
|
||||||
|
* @param string $text
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isProfane($text)
|
||||||
|
{
|
||||||
|
return Str::containsCaseless($text, $this->badwords);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getBaseDictPath()
|
public function getBadwords()
|
||||||
{
|
{
|
||||||
return property_exists($this, 'baseDictPath') ? $this->baseDictPath : __DIR__ . DIRECTORY_SEPARATOR .'dict/';
|
return $this->badwords;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the dictionary to use
|
||||||
|
* @param array|string $dictionary
|
||||||
|
*/
|
||||||
|
public function setDictionary($dictionary)
|
||||||
|
{
|
||||||
|
$this->badwords = $this->readDictionary($dictionary);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function readDictionary($dictionary)
|
||||||
|
{
|
||||||
|
$badwords = [];
|
||||||
|
$baseDictPath = $this->getBaseDictPath();
|
||||||
|
if (is_array($dictionary)) {
|
||||||
|
foreach ($dictionary as $file) {
|
||||||
|
if (file_exists($baseDictPath.$file.'.php')) {
|
||||||
|
$dict = include($baseDictPath.$file.'.php');
|
||||||
|
$badwords = array_merge($badwords, $dict);
|
||||||
|
} else {
|
||||||
|
// if the file isn't in the dict directory,
|
||||||
|
// it's probably a custom user library
|
||||||
|
$dict = include($file);
|
||||||
|
$badwords = array_merge($badwords, $dict);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// just a single string, not an array
|
||||||
|
} elseif (is_string($dictionary)) {
|
||||||
|
if (file_exists($baseDictPath.$dictionary.'.php')) {
|
||||||
|
$dict = include($baseDictPath.$dictionary.'.php');
|
||||||
|
$badwords = array_merge($badwords, $dict);
|
||||||
|
} else {
|
||||||
|
if (file_exists($dictionary)) {
|
||||||
|
$dict = include($dictionary);
|
||||||
|
$badwords = array_merge($badwords, $dict);
|
||||||
|
} // else nothing is merged
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $badwords;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getBaseDictPath()
|
||||||
|
{
|
||||||
|
return property_exists($this, 'baseDictPath') ? $this->baseDictPath : __DIR__ . DIRECTORY_SEPARATOR .'dict/';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
src/Str.php
14
src/Str.php
|
|
@ -5,13 +5,13 @@ namespace LaravelProfane;
|
||||||
class Str
|
class Str
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Taken from Illuminate\Support\Str
|
* Taken from Illuminate\Support\Str
|
||||||
* Determine if a given string contains a given word with case insensitive match.
|
* Determine if a given string contains a given word with case insensitive match.
|
||||||
*
|
*
|
||||||
* @param string $haystack
|
* @param string $haystack
|
||||||
* @param string|array $needles
|
* @param string|array $needles
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function containsCaseless($haystack, $needles)
|
public static function containsCaseless($haystack, $needles)
|
||||||
{
|
{
|
||||||
foreach ((array) $needles as $needle) {
|
foreach ((array) $needles as $needle) {
|
||||||
|
|
|
||||||
152
src/dict/en.php
152
src/dict/en.php
|
|
@ -1,80 +1,80 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'anal',
|
'anal',
|
||||||
'anus',
|
'anus',
|
||||||
'ass',
|
'ass',
|
||||||
'bastard',
|
'bastard',
|
||||||
'bitch',
|
'bitch',
|
||||||
'boob',
|
'boob',
|
||||||
'cock',
|
'cock',
|
||||||
'cum',
|
'cum',
|
||||||
'cunt',
|
'cunt',
|
||||||
'dick',
|
'dick',
|
||||||
'dildo',
|
'dildo',
|
||||||
'dyke',
|
'dyke',
|
||||||
'fag',
|
'fag',
|
||||||
'faggot',
|
'faggot',
|
||||||
'fuck',
|
'fuck',
|
||||||
'fuk',
|
'fuk',
|
||||||
'handjob',
|
'handjob',
|
||||||
'homo',
|
'homo',
|
||||||
'jizz',
|
'jizz',
|
||||||
'kike',
|
'kike',
|
||||||
'kunt',
|
'kunt',
|
||||||
'muff',
|
'muff',
|
||||||
'nigger',
|
'nigger',
|
||||||
'penis',
|
'penis',
|
||||||
'piss',
|
'piss',
|
||||||
'poop',
|
'poop',
|
||||||
'pussy',
|
'pussy',
|
||||||
'queer',
|
'queer',
|
||||||
'rape',
|
'rape',
|
||||||
'semen',
|
'semen',
|
||||||
'sex',
|
'sex',
|
||||||
'shit',
|
'shit',
|
||||||
'slut',
|
'slut',
|
||||||
'titties',
|
'titties',
|
||||||
'twat',
|
'twat',
|
||||||
'vagina',
|
'vagina',
|
||||||
'vulva',
|
'vulva',
|
||||||
'wank',
|
'wank',
|
||||||
'abortion',
|
'abortion',
|
||||||
'anus',
|
'anus',
|
||||||
'beastiality',
|
'beastiality',
|
||||||
'bestiality',
|
'bestiality',
|
||||||
'bewb',
|
'bewb',
|
||||||
'blow',
|
'blow',
|
||||||
'blumpkin',
|
'blumpkin',
|
||||||
'cawk',
|
'cawk',
|
||||||
'choad',
|
'choad',
|
||||||
'cooter',
|
'cooter',
|
||||||
'cornhole',
|
'cornhole',
|
||||||
'dong',
|
'dong',
|
||||||
'douche',
|
'douche',
|
||||||
'fart',
|
'fart',
|
||||||
'foreskin',
|
'foreskin',
|
||||||
'gangbang',
|
'gangbang',
|
||||||
'gook',
|
'gook',
|
||||||
'hell',
|
'hell',
|
||||||
'honkey',
|
'honkey',
|
||||||
'humping',
|
'humping',
|
||||||
'jiz',
|
'jiz',
|
||||||
'labia',
|
'labia',
|
||||||
'nutsack',
|
'nutsack',
|
||||||
'pen1s',
|
'pen1s',
|
||||||
'poon',
|
'poon',
|
||||||
'punani',
|
'punani',
|
||||||
'queef',
|
'queef',
|
||||||
'quim',
|
'quim',
|
||||||
'rectal',
|
'rectal',
|
||||||
'rectum',
|
'rectum',
|
||||||
'rimjob',
|
'rimjob',
|
||||||
'spick',
|
'spick',
|
||||||
'spoo',
|
'spoo',
|
||||||
'spooge',
|
'spooge',
|
||||||
'taint',
|
'taint',
|
||||||
'titty',
|
'titty',
|
||||||
'vag',
|
'vag',
|
||||||
'whore'
|
'whore'
|
||||||
];
|
];
|
||||||
|
|
|
||||||
166
src/dict/es.php
166
src/dict/es.php
|
|
@ -1,87 +1,87 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'bollera',
|
'bollera',
|
||||||
'cabron',
|
'cabron',
|
||||||
'cabrón',
|
'cabrón',
|
||||||
'cabrona',
|
'cabrona',
|
||||||
'cabronazo',
|
'cabronazo',
|
||||||
'capulla',
|
'capulla',
|
||||||
'capullo',
|
'capullo',
|
||||||
'chichi',
|
'chichi',
|
||||||
'chinga',
|
'chinga',
|
||||||
'chingo',
|
'chingo',
|
||||||
'chingon',
|
'chingon',
|
||||||
'chingona',
|
'chingona',
|
||||||
'chingatumadre',
|
'chingatumadre',
|
||||||
'chinga tu madre',
|
'chinga tu madre',
|
||||||
'chingada',
|
'chingada',
|
||||||
'chingado',
|
'chingado',
|
||||||
'chocho',
|
'chocho',
|
||||||
'cojon',
|
'cojon',
|
||||||
'cojón',
|
'cojón',
|
||||||
'cojones',
|
'cojones',
|
||||||
'comepollas',
|
'comepollas',
|
||||||
// 'cono',
|
// 'cono',
|
||||||
'coño',
|
'coño',
|
||||||
'culero',
|
'culero',
|
||||||
'culera',
|
'culera',
|
||||||
'culo',
|
'culo',
|
||||||
'follar',
|
'follar',
|
||||||
'follen',
|
'follen',
|
||||||
'furcia',
|
'furcia',
|
||||||
'gilipollas',
|
'gilipollas',
|
||||||
'hijaputa',
|
'hijaputa',
|
||||||
'hijo puta',
|
'hijo puta',
|
||||||
'hijo de puta',
|
'hijo de puta',
|
||||||
'hijodeputa',
|
'hijodeputa',
|
||||||
'hijoputa',
|
'hijoputa',
|
||||||
'hostia',
|
'hostia',
|
||||||
'joder',
|
'joder',
|
||||||
'jodete',
|
'jodete',
|
||||||
'jódete',
|
'jódete',
|
||||||
'joputa',
|
'joputa',
|
||||||
'mamada',
|
'mamada',
|
||||||
'mamon',
|
'mamon',
|
||||||
'mamón',
|
'mamón',
|
||||||
'mamona',
|
'mamona',
|
||||||
'marica',
|
'marica',
|
||||||
'maricon',
|
'maricon',
|
||||||
'maricón',
|
'maricón',
|
||||||
'maricona',
|
'maricona',
|
||||||
'mariconazo',
|
'mariconazo',
|
||||||
'nazi',
|
'nazi',
|
||||||
'ojete',
|
'ojete',
|
||||||
'ostia',
|
'ostia',
|
||||||
'pajillero',
|
'pajillero',
|
||||||
'pendon',
|
'pendon',
|
||||||
'pendón',
|
'pendón',
|
||||||
'pendejo',
|
'pendejo',
|
||||||
'pendejos',
|
'pendejos',
|
||||||
'pendeja',
|
'pendeja',
|
||||||
'pendejas',
|
'pendejas',
|
||||||
'pendejada',
|
'pendejada',
|
||||||
'pendejadas',
|
'pendejadas',
|
||||||
'pedo',
|
'pedo',
|
||||||
'pedorra',
|
'pedorra',
|
||||||
'pedorro',
|
'pedorro',
|
||||||
'pedorron',
|
'pedorron',
|
||||||
'pedorrón',
|
'pedorrón',
|
||||||
'picha',
|
'picha',
|
||||||
'pito',
|
'pito',
|
||||||
'pelana',
|
'pelana',
|
||||||
'polla',
|
'polla',
|
||||||
'pollon',
|
'pollon',
|
||||||
'pollón',
|
'pollón',
|
||||||
'polvo',
|
'polvo',
|
||||||
'potorro',
|
'potorro',
|
||||||
'puta',
|
'puta',
|
||||||
'puto',
|
'puto',
|
||||||
'putona',
|
'putona',
|
||||||
'puton',
|
'puton',
|
||||||
'putón',
|
'putón',
|
||||||
'tortillera',
|
'tortillera',
|
||||||
'weputa',
|
'weputa',
|
||||||
'zorron',
|
'zorron',
|
||||||
'zorrón'
|
'zorrón'
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'profane' => 'The :attribute contains vulgar content'
|
'profane' => 'The :attribute contains vulgar content'
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'profane' => 'El :attribute contiene palabras vulgares'
|
'profane' => 'El :attribute contiene palabras vulgares'
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -6,134 +6,134 @@ use \Mockery as m;
|
||||||
|
|
||||||
class ProfaneValidatorTest extends PHPUnit_Framework_TestCase
|
class ProfaneValidatorTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
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()
|
||||||
{
|
{
|
||||||
$this->mockConfigs();
|
$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();
|
$this->mockConfigs();
|
||||||
$attribute = 'description';
|
$attribute = 'description';
|
||||||
$text = 'fck you bitch';
|
$text = 'fck you bitch';
|
||||||
$parameters = ['es', 'en'];
|
$parameters = ['es', 'en'];
|
||||||
|
|
||||||
$profane = new ProfaneValidator();
|
$profane = new ProfaneValidator();
|
||||||
|
|
||||||
$this->assertFalse($profane->validate($attribute, $text, $parameters));
|
$this->assertFalse($profane->validate($attribute, $text, $parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_can_evaluate_profanity_of_a_word()
|
public function test_can_evaluate_profanity_of_a_word()
|
||||||
{
|
{
|
||||||
$word = 'fuck';
|
$word = 'fuck';
|
||||||
$this->mockConfigs();
|
$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();
|
$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();
|
$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();
|
$this->mockConfigs();
|
||||||
|
|
||||||
$profane = new ProfaneValidator();
|
$profane = new ProfaneValidator();
|
||||||
|
|
||||||
$this->assertTrue($profane->isProfane($word));
|
$this->assertTrue($profane->isProfane($word));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_can_set_dictionary_when_you_pass_a_locale()
|
public function test_can_set_dictionary_when_you_pass_a_locale()
|
||||||
{
|
{
|
||||||
$this->mockConfigs();
|
$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();
|
$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();
|
$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']);
|
||||||
|
|
||||||
$expected = array_merge(include __DIR__.'/../src/dict/es.php', include __DIR__.'/../src/dict/en.php');
|
$expected = array_merge(include __DIR__.'/../src/dict/es.php', include __DIR__.'/../src/dict/en.php');
|
||||||
|
|
||||||
$this->assertEquals($profane->getBadwords(), $expected);
|
$this->assertEquals($profane->getBadwords(), $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
$this->mockConfigs();
|
||||||
|
|
||||||
$profane = new ProfaneValidator();
|
$profane = new ProfaneValidator();
|
||||||
$profane->setDictionary(['es', 'en']);
|
$profane->setDictionary(['es', 'en']);
|
||||||
|
|
||||||
$expected = array_merge(include __DIR__.'/../src/dict/es.php', include __DIR__.'/../src/dict/en.php');
|
$expected = array_merge(include __DIR__.'/../src/dict/es.php', include __DIR__.'/../src/dict/en.php');
|
||||||
|
|
||||||
$this->assertEquals($profane->getBadwords(), $expected);
|
$this->assertEquals($profane->getBadwords(), $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function mockConfigs()
|
private function mockConfigs()
|
||||||
{
|
{
|
||||||
Config::shouldReceive('get')
|
Config::shouldReceive('get')
|
||||||
->once()
|
->once()
|
||||||
->with('app.locale')
|
->with('app.locale')
|
||||||
->andReturn('en');
|
->andReturn('en');
|
||||||
|
|
||||||
Config::shouldReceive('has')
|
Config::shouldReceive('has')
|
||||||
->once()
|
->once()
|
||||||
->with('app.locale')
|
->with('app.locale')
|
||||||
->andReturn(true);
|
->andReturn(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue