Merge pull request #7302 from robbieaverill/pulls/4.0/has-class-returns-bool

API Make FormField::hasClass return a boolean instead of an int
This commit is contained in:
Damian Mooyman 2017-08-24 13:19:30 +12:00 committed by GitHub
commit d5b3280498
2 changed files with 16 additions and 6 deletions

View File

@ -1247,17 +1247,16 @@ class FormField extends RequestHandler
}
/**
* Returns whether the current field has the given class added
*
* @param string $class
*
* @return int
* @return bool
*/
public function hasClass($class)
{
$patten = '/' . strtolower($class) . '/i';
$subject = strtolower(static::class . ' ' . $this->extraClass());
return preg_match($patten, $subject);
$classes = explode(' ', strtolower($this->extraClass()));
return in_array(strtolower(trim($class)), $classes);
}
/**

View File

@ -373,4 +373,15 @@ class FormFieldTest extends SapphireTest
$schema['message']['value']
);
}
public function testHasClass()
{
$field = new FormField('Test');
$field->addExtraClass('foo BAr cool-banana');
$this->assertTrue($field->hasClass('foo'));
$this->assertTrue($field->hasClass('bAr'));
$this->assertFalse($field->hasClass('banana'));
$this->assertTrue($field->hasClass('cool-BAnana'));
}
}