Ilya Sigunov 13 years ago
parent
commit
30559c6195
  1. 95
      tests/form/FormFieldTest.php

95
tests/form/FormFieldTest.php

@ -22,28 +22,36 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
{ {
public function setUp() public function setUp()
{ {
$this->ff = new NotEmptyFormField;
$this->ff = new TestFormForFormField;
$this->obj_fields = $this->ff->getProp('fields'); $this->obj_fields = $this->ff->getProp('fields');
} }
public function testSetRequired() public function testSetRequired()
{ {
$this->assertNotNull($this->obj_fields['login']->setRequired(1));
$form_field = new FormField;
$this->assertNotNull($form_field->setRequired(1));
} }
public function testSetIgnored() public function testSetIgnored()
{ {
$this->assertNotNull($this->obj_fields['login']->setIgnored(1));
$form_field = new FormField;
$this->assertNotNull($form_field->setIgnored(1));
} }
public function testIsIgnored() public function testIsIgnored()
{ {
$this->assertNotNull($this->obj_fields['login']->isIgnored());
$form_field = new FormField;
$this->assertNotNull($form_field->isIgnored());
} }
public function testIsRequired() public function testIsRequired()
{ {
$this->assertNotNull($this->obj_fields['login']->isRequired());
$form_field = new FormField;
$this->assertNotNull($form_field->isRequired());
} }
public function testAddValidators() public function testAddValidators()
@ -56,7 +64,14 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
$this->assertInstanceOf('iValidator', $fields['NotEmpty']); $this->assertInstanceOf('iValidator', $fields['NotEmpty']);
$this->assertInstanceOf('iValidator', $fields['Email']); $this->assertInstanceOf('iValidator', $fields['Email']);
$this->obj_fields['login']->addValidators($fields);
$tmp_form_field = new TmpFormField;
$tmp_form_field->addValidators($fields);
$array = $tmp_form_field->getProp('validators');
$this->assertArrayHasKey('NotEmptyValidator', $array);
$this->assertArrayHasKey('EmailValidator', $array);
} }
public function testAddValidatorObject() public function testAddValidatorObject()
@ -65,16 +80,26 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
$this->assertInstanceOf('iValidator', new NotEmptyValidator); $this->assertInstanceOf('iValidator', new NotEmptyValidator);
$this->obj_fields['login']->addValidator($validator);
$tmp_form_field = new TmpFormField;
$tmp_form_field->addValidator($validator);
$array = $tmp_form_field->getProp('validators');
$this->assertArrayHasKey('NotEmptyValidator', $array);
} }
public function testAddValidatorString() public function testAddValidatorString()
{ {
$validator = 'NotEmpty'; $validator = 'NotEmpty';
$this->obj_fields['login']->addValidator($validator);
$tmp_form_field = new TmpFormField;
$tmp_form_field->addValidator($validator);
$this->assertAttributeContainsOnly($validator . 'Validator', 'validators', $this->obj_fields['login']);
$array = $tmp_form_field->getProp('validators');
$this->assertArrayHasKey('NotEmptyValidator', $array);
} }
public function testAddValidatorElse() public function testAddValidatorElse()
@ -83,7 +108,13 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
$this->setExpectedException('Exception'); $this->setExpectedException('Exception');
$this->obj_fields['login']->addValidator($validator);
$tmp_form_field = new TmpFormField;
$tmp_form_field->addValidator($validator);
$array = $tmp_form_field->getProp('validators');
$this->assertArrayHasKey('NotEmptyValidator', $array);
} }
@ -97,7 +128,13 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
$this->assertInstanceOf('iFilter', $fields['fff2']); $this->assertInstanceOf('iFilter', $fields['fff2']);
$this->obj_fields['login']->addFilters($fields);
$tmp_form_field = new TmpFormField;
$tmp_form_field->addFilters($fields);
$array = $tmp_form_field->getProp('filters');
$this->assertArrayHasKey('loginFilter', $array);
} }
public function testAddFilterObject() public function testAddFilterObject()
@ -106,14 +143,24 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
$this->assertInstanceOf('iFilter', $filter); $this->assertInstanceOf('iFilter', $filter);
$this->obj_fields['login']->addFilter($filter);
$tmp_form_field = new TmpFormField;
$tmp_form_field->addFilter($filter);
$array = $tmp_form_field->getProp('filters');
$this->assertArrayHasKey('loginFilter', $array);
} }
public function testAddFilterString() public function testAddFilterString()
{ {
$this->obj_fields['login']->addFilter('login');
$tmp_form_field = new TmpFormField;
$this->assertAttributeContainsOnly('loginFilter', 'filters', $this->obj_fields['login']);
$tmp_form_field->addFilter('login');
$array = $tmp_form_field->getProp('filters');
$this->assertArrayHasKey('loginFilter', $array);
} }
public function testAddFilterElse() public function testAddFilterElse()
@ -121,13 +168,20 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
$this->setExpectedException('Exception'); $this->setExpectedException('Exception');
$filter = new NotEmptyValidator; $filter = new NotEmptyValidator;
$this->obj_fields['login']->addFilter($filter);
$tmp_form_field = new TmpFormField;
$tmp_form_field->addFilter($filter);
$array = $tmp_form_field->getProp('filters');
$this->assertArrayHasKey('NotEmptyValidator', $array);
} }
public function testGetValueArray() public function testGetValueArray()
{ {
$form = new NotEmptyFormField();
$form = new TestFormForFormField();
$test_array = array( $test_array = array(
'login'=> 'login', 'login'=> 'login',
@ -213,9 +267,16 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
} }
class TmpFormField extends FormField
{
public function getProp($name)
{
return $this->$name;
}
}
class NotEmptyFormField extends Form
class TestFormForFormField extends Form
{ {
public function init() public function init()
{ {

Loading…
Cancel
Save