Added more tests for the forms.

This commit is contained in:
Dmitry Khomutov 2018-02-16 16:59:36 +07:00
commit 09cee5a5df
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
2 changed files with 46 additions and 20 deletions

View file

@ -68,6 +68,19 @@ class FormTest extends TestCase
self::assertTrue(is_callable($f->getValidator()));
}
public function testInputCreate()
{
$text = Form\Element\Text::create(
'input-name',
'input-label',
true
);
self::assertEquals('input-name', $text->getName());
self::assertEquals('input-label', $text->getLabel());
self::assertTrue($text->getRequired());
}
public function testInputValidation()
{
$f = new Form\Element\Text();
@ -98,6 +111,16 @@ class FormTest extends TestCase
self::assertFalse($f->validate());
}
public function testInputValidationWithCustomError()
{
$f = new Form\Element\Text();
$f->setRequired(true);
$f->setValue('input-value');
$f->setError('Error!');
self::assertFalse($f->validate());
}
public function testFieldSetBasics()
{
$f = new Form\FieldSet();
@ -188,5 +211,8 @@ class FormTest extends TestCase
$e = new Form\Element\Url();
self::assertTrue(strpos($e->render(), 'url') !== false);
$e = new Form\Element\Password();
self::assertTrue(strpos($e->render(), 'password') !== false);
}
}