|
|
@ -12,9 +12,7 @@ |
|
|
|
require_once dirname(__FILE__) . '/../../validator/iValidator.php'; |
|
|
|
require_once dirname(__FILE__) . '/../../validator/Validator.php'; |
|
|
|
require_once dirname(__FILE__) . '/../../validator/NotEmptyValidator.php'; |
|
|
|
require_once dirname(__FILE__) . '/../../validator/RegexValidator.php'; |
|
|
|
require_once dirname(__FILE__) . '/../../validator/EmailValidator.php'; |
|
|
|
require_once dirname(__FILE__) . '/../../form/Form.php'; |
|
|
|
require_once dirname(__FILE__) . '/../../form/FormField.php'; |
|
|
|
|
|
|
|
|
|
|
@ -22,8 +20,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase |
|
|
|
{ |
|
|
|
public function setUp() |
|
|
|
{ |
|
|
|
$this->ff = new TestFormForFormField; |
|
|
|
$this->obj_fields = $this->ff->getProp('fields'); |
|
|
|
/**/ |
|
|
|
} |
|
|
|
|
|
|
|
public function testSetRequired() |
|
|
@ -70,16 +67,11 @@ class FormFieldTest extends PHPUnit_Framework_TestCase |
|
|
|
'NotEmpty' => new NotEmptyValidator(), |
|
|
|
'Email' => new EmailValidator() |
|
|
|
); |
|
|
|
|
|
|
|
$this->assertInstanceOf('iValidator', $validator['NotEmpty']); |
|
|
|
$this->assertInstanceOf('iValidator', $validator['Email']); |
|
|
|
|
|
|
|
$tmp_form_field = new TmpFormField; |
|
|
|
|
|
|
|
$tmp_form_field = new FormField; |
|
|
|
$return_object = $tmp_form_field->addValidators($validator); |
|
|
|
|
|
|
|
$array = array('NotEmptyValidator'=>new NotEmptyValidator,'EmailValidator'=>new EmailValidator); |
|
|
|
|
|
|
|
$this->assertAttributeEquals($array, 'validators', $tmp_form_field); |
|
|
|
$this->assertSame($tmp_form_field, $return_object); |
|
|
|
} |
|
|
@ -88,27 +80,19 @@ class FormFieldTest extends PHPUnit_Framework_TestCase |
|
|
|
{ |
|
|
|
$validator = new NotEmptyValidator; |
|
|
|
$array = array('NotEmptyValidator'=>new NotEmptyValidator); |
|
|
|
|
|
|
|
$this->assertInstanceOf('iValidator', new NotEmptyValidator); |
|
|
|
|
|
|
|
$tmp_form_field = new TmpFormField; |
|
|
|
|
|
|
|
$tmp_form_field = new FormField; |
|
|
|
$return_object = $tmp_form_field->addValidator($validator); |
|
|
|
|
|
|
|
$this->assertAttributeEquals($array, 'validators', $tmp_form_field); |
|
|
|
$this->assertSame($tmp_form_field, $return_object); |
|
|
|
} |
|
|
|
|
|
|
|
public function testAddValidatorString() |
|
|
|
{ |
|
|
|
$tmp_form_field = new TmpFormField; |
|
|
|
|
|
|
|
$tmp_form_field = new FormField; |
|
|
|
$return_object = $tmp_form_field->addValidator('NotEmpty'); |
|
|
|
|
|
|
|
$this->assertInstanceOf('iValidator', new NotEmptyValidator); |
|
|
|
|
|
|
|
$array = array('NotEmptyValidator'=>new NotEmptyValidator); |
|
|
|
|
|
|
|
$this->assertAttributeEquals($array, 'validators', $tmp_form_field); |
|
|
|
$this->assertSame($tmp_form_field, $return_object); |
|
|
|
} |
|
|
@ -116,11 +100,8 @@ class FormFieldTest extends PHPUnit_Framework_TestCase |
|
|
|
public function testAddValidatorElse() |
|
|
|
{ |
|
|
|
$validator = true; |
|
|
|
|
|
|
|
$this->setExpectedException('Exception'); |
|
|
|
|
|
|
|
$tmp_form_field = new TmpFormField; |
|
|
|
|
|
|
|
$tmp_form_field = new FormField; |
|
|
|
$tmp_form_field->addValidator($validator); |
|
|
|
} |
|
|
|
|
|
|
@ -128,14 +109,10 @@ class FormFieldTest extends PHPUnit_Framework_TestCase |
|
|
|
public function testAddFilters() |
|
|
|
{ |
|
|
|
$array = array('loginFilter' => new loginFilter(),'passwordFilter' => new passwordFilter()); |
|
|
|
|
|
|
|
$this->assertInstanceOf('iFilter', $array['loginFilter']); |
|
|
|
$this->assertInstanceOf('iFilter', $array['passwordFilter']); |
|
|
|
|
|
|
|
$tmp_form_field = new TmpFormField; |
|
|
|
|
|
|
|
$tmp_form_field = new FormField; |
|
|
|
$return_object = $tmp_form_field->addFilters($array); |
|
|
|
|
|
|
|
$this->assertAttributeEquals($array, 'filters', $tmp_form_field); |
|
|
|
$this->assertSame($tmp_form_field, $return_object); |
|
|
|
} |
|
|
@ -143,28 +120,20 @@ class FormFieldTest extends PHPUnit_Framework_TestCase |
|
|
|
public function testAddFilterObject() |
|
|
|
{ |
|
|
|
$filter = new loginFilter; |
|
|
|
|
|
|
|
$array = array('loginFilter' => new loginFilter()); |
|
|
|
|
|
|
|
$this->assertInstanceOf('iFilter', new loginFilter); |
|
|
|
|
|
|
|
$tmp_form_field = new TmpFormField; |
|
|
|
|
|
|
|
$tmp_form_field = new FormField; |
|
|
|
$return_object = $tmp_form_field->addFilter($filter); |
|
|
|
|
|
|
|
$this->assertAttributeEquals($array, 'filters', $tmp_form_field); |
|
|
|
$this->assertSame($tmp_form_field, $return_object); |
|
|
|
} |
|
|
|
|
|
|
|
public function testAddFilterString() |
|
|
|
{ |
|
|
|
$tmp_form_field = new TmpFormField; |
|
|
|
$tmp_form_field = new FormField; |
|
|
|
$array = array('loginFilter' => new loginFilter()); |
|
|
|
|
|
|
|
$this->assertInstanceOf('iFilter', new loginFilter); |
|
|
|
|
|
|
|
$return_object = $tmp_form_field->addFilter('login'); |
|
|
|
|
|
|
|
$this->assertAttributeEquals($array, 'filters', $tmp_form_field); |
|
|
|
$this->assertSame($tmp_form_field, $return_object); |
|
|
|
} |
|
|
@ -172,30 +141,22 @@ class FormFieldTest extends PHPUnit_Framework_TestCase |
|
|
|
public function testAddFilterElse() |
|
|
|
{ |
|
|
|
$this->setExpectedException('Exception'); |
|
|
|
|
|
|
|
$filter = new NotEmptyValidator; |
|
|
|
|
|
|
|
$tmp_form_field = new TmpFormField; |
|
|
|
|
|
|
|
$tmp_form_field = new FormField; |
|
|
|
$tmp_form_field->addFilter($filter); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testGetValueArray() |
|
|
|
{ |
|
|
|
$form = new TestFormForFormField(); |
|
|
|
|
|
|
|
$form = new FormField(); |
|
|
|
$test_array = array( |
|
|
|
'login'=> 'login', |
|
|
|
'password'=> 'password' |
|
|
|
); |
|
|
|
|
|
|
|
$this->assertSame(1, $form->isValid($test_array)); |
|
|
|
|
|
|
|
$tmp_form_field = new TmpFormField; |
|
|
|
|
|
|
|
$this->assertTrue($form->isValid($test_array)); |
|
|
|
$tmp_form_field = new FormField; |
|
|
|
$this->assertTrue($tmp_form_field->isValid($test_array)); |
|
|
|
|
|
|
|
$this->assertAttributeInternalType('array', 'value', $tmp_form_field); |
|
|
|
$this->assertArrayHasKey('login', $tmp_form_field->getSourceValue()); |
|
|
|
} |
|
|
@ -206,12 +167,9 @@ class FormFieldTest extends PHPUnit_Framework_TestCase |
|
|
|
'login'=> 'login', |
|
|
|
'password'=> 'password' |
|
|
|
); |
|
|
|
|
|
|
|
$test_form_field = new FormField(); |
|
|
|
|
|
|
|
$this->assertTrue($test_form_field->isValid($test_array['login'])); |
|
|
|
$this->assertAttributeNotInternalType('array', 'value', $test_form_field); |
|
|
|
|
|
|
|
$this->assertEquals('login',$test_form_field->getSourceValue()); |
|
|
|
} |
|
|
|
|
|
|
@ -221,19 +179,15 @@ class FormFieldTest extends PHPUnit_Framework_TestCase |
|
|
|
$this->assertNotNull($test_form_field->getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
public function testIsValidMissing1() |
|
|
|
public function testIsValidMissingException() |
|
|
|
{ |
|
|
|
$test_array = array( |
|
|
|
'login'=> '', |
|
|
|
'password'=> '' |
|
|
|
); |
|
|
|
|
|
|
|
$test_form_field = new FormField(); |
|
|
|
|
|
|
|
$test_form_field->addValidator('NotEmpty'); |
|
|
|
|
|
|
|
$this->setExpectedException('Exception','Define default message for array fields'); |
|
|
|
|
|
|
|
$this->assertTrue($test_form_field->isValid($test_array)); |
|
|
|
} |
|
|
|
|
|
|
@ -243,37 +197,32 @@ class FormFieldTest extends PHPUnit_Framework_TestCase |
|
|
|
'login'=> '', |
|
|
|
'password'=> '' |
|
|
|
); |
|
|
|
|
|
|
|
$test_form_field = new FormField('ssssssss'); |
|
|
|
|
|
|
|
$return_object = $test_form_field->addValidator('NotEmpty'); |
|
|
|
|
|
|
|
$this->assertInstanceOf('iValidator', new NotEmptyValidator); |
|
|
|
|
|
|
|
$array = array('NotEmptyValidator'=>new NotEmptyValidator); |
|
|
|
|
|
|
|
$this->assertAttributeEquals($array, 'validators', $test_form_field); |
|
|
|
$this->assertSame($test_form_field, $return_object); |
|
|
|
|
|
|
|
$this->assertFalse($test_form_field->isValid($test_array)); |
|
|
|
} |
|
|
|
|
|
|
|
public function testIsValidMissing2() |
|
|
|
public function testIsValidMissingRequired() |
|
|
|
{ |
|
|
|
$form_field = new FormField; |
|
|
|
|
|
|
|
$form_field->setRequired(false); |
|
|
|
|
|
|
|
$this->assertTrue($form_field->isValid('')); |
|
|
|
} |
|
|
|
|
|
|
|
public function testIsValidMissing3() |
|
|
|
public function testIsValidMissingValid() |
|
|
|
{ |
|
|
|
$test_array = array( |
|
|
|
'login'=> 'login', |
|
|
|
'password'=> 'password' |
|
|
|
); |
|
|
|
$validator = new NotEmptyValidator(); |
|
|
|
$form_field = new FormField; |
|
|
|
$form_field->setRequired(false); |
|
|
|
$form_field->isValid(''); |
|
|
|
|
|
|
|
$this->assertFalse($form_field->isRequired()); |
|
|
|
$return_object = $form_field->addValidator($validator); |
|
|
|
$this->assertTrue($form_field->isValid($test_array)); |
|
|
|
} |
|
|
|
|
|
|
|
public function testFilterValue() |
|
|
@ -281,45 +230,11 @@ class FormFieldTest extends PHPUnit_Framework_TestCase |
|
|
|
$form_field = new FormField; |
|
|
|
$form_field->isValid('login'); |
|
|
|
$form_field->addFilter('login'); |
|
|
|
|
|
|
|
$lf = new loginFilter; |
|
|
|
|
|
|
|
$this->assertSame($form_field->getValue(), $lf->filter('login')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class TmpFormField extends FormField |
|
|
|
{ |
|
|
|
public function getProp($name) |
|
|
|
{ |
|
|
|
return $this->$name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class TestFormForFormField extends Form |
|
|
|
{ |
|
|
|
public function init() |
|
|
|
{ |
|
|
|
///*
|
|
|
|
$validator = new NotEmptyValidator(); |
|
|
|
$validator->setMessage('Enter login name.'); |
|
|
|
$this->addField('login')->addValidator($validator); |
|
|
|
|
|
|
|
// User password
|
|
|
|
$validator = new NotEmptyValidator(); |
|
|
|
$validator->setMessage('Enter your password.'); |
|
|
|
$this->addField('password')->addValidator($validator); |
|
|
|
} |
|
|
|
|
|
|
|
public function getProp($name) |
|
|
|
{ |
|
|
|
return $this->$name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface iFilter |
|
|
|
{ |
|
|
|
public function isValid($value, $context = null); |
|
|
|