Browse Source

format2

master
Ilya Sigunov 13 years ago
parent
commit
8aa83f5124
  1. 60
      tests/form/FormFieldTest.php
  2. 5
      tests/form/FormTest.php
  3. 10
      tests/form/FormViewHelperTest.php

60
tests/form/FormFieldTest.php

@ -25,7 +25,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
public function testSetRequired() public function testSetRequired()
{ {
$form_field = new FormField;
$form_field = new FormField();
$this->assertTrue($form_field->isRequired()); $this->assertTrue($form_field->isRequired());
$return_object = $form_field->setRequired(false); $return_object = $form_field->setRequired(false);
$this->assertInstanceOf('FormField', $return_object); $this->assertInstanceOf('FormField', $return_object);
@ -35,7 +35,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
public function testSetIgnored() public function testSetIgnored()
{ {
$form_field = new FormField;
$form_field = new FormField();
$this->assertFalse($form_field->isIgnored()); $this->assertFalse($form_field->isIgnored());
$return_object = $form_field->setIgnored(true); $return_object = $form_field->setIgnored(true);
$this->assertInstanceOf('FormField', $return_object); $this->assertInstanceOf('FormField', $return_object);
@ -46,7 +46,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
public function testIsIgnored() public function testIsIgnored()
{ {
$class_name = 'FormField'; $class_name = 'FormField';
$form_field = new $class_name;
$form_field = new $class_name();
$this->assertFalse($form_field->isIgnored()); $this->assertFalse($form_field->isIgnored());
$form_field->setIgnored(true); $form_field->setIgnored(true);
$this->assertTrue($form_field->isIgnored()); $this->assertTrue($form_field->isIgnored());
@ -55,7 +55,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
public function testIsRequired() public function testIsRequired()
{ {
$class_name = 'FormField'; $class_name = 'FormField';
$form_field = new $class_name;
$form_field = new $class_name();
$this->assertTrue($form_field->isRequired()); $this->assertTrue($form_field->isRequired());
$form_field->setRequired(false); $form_field->setRequired(false);
$this->assertFalse($form_field->isRequired()); $this->assertFalse($form_field->isRequired());
@ -69,19 +69,19 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
); );
$this->assertInstanceOf('iValidator', $validator['NotEmpty']); $this->assertInstanceOf('iValidator', $validator['NotEmpty']);
$this->assertInstanceOf('iValidator', $validator['Email']); $this->assertInstanceOf('iValidator', $validator['Email']);
$tmp_form_field = new FormField;
$tmp_form_field = new FormField();
$return_object = $tmp_form_field->addValidators($validator); $return_object = $tmp_form_field->addValidators($validator);
$array = array('NotEmptyValidator'=>new NotEmptyValidator,'EmailValidator'=>new EmailValidator);
$array = array('NotEmptyValidator'=>new NotEmptyValidator(),'EmailValidator'=>new EmailValidator());
$this->assertAttributeEquals($array, 'validators', $tmp_form_field); $this->assertAttributeEquals($array, 'validators', $tmp_form_field);
$this->assertSame($tmp_form_field, $return_object); $this->assertSame($tmp_form_field, $return_object);
} }
public function testAddValidatorObject() public function testAddValidatorObject()
{ {
$validator = new NotEmptyValidator;
$array = array('NotEmptyValidator'=>new NotEmptyValidator);
$this->assertInstanceOf('iValidator', new NotEmptyValidator);
$tmp_form_field = new FormField;
$validator = new NotEmptyValidator();
$array = array('NotEmptyValidator'=>new NotEmptyValidator());
$this->assertInstanceOf('iValidator', new NotEmptyValidator());
$tmp_form_field = new FormField();
$return_object = $tmp_form_field->addValidator($validator); $return_object = $tmp_form_field->addValidator($validator);
$this->assertAttributeEquals($array, 'validators', $tmp_form_field); $this->assertAttributeEquals($array, 'validators', $tmp_form_field);
$this->assertSame($tmp_form_field, $return_object); $this->assertSame($tmp_form_field, $return_object);
@ -89,10 +89,10 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
public function testAddValidatorString() public function testAddValidatorString()
{ {
$tmp_form_field = new FormField;
$tmp_form_field = new FormField();
$return_object = $tmp_form_field->addValidator('NotEmpty'); $return_object = $tmp_form_field->addValidator('NotEmpty');
$this->assertInstanceOf('iValidator', new NotEmptyValidator);
$array = array('NotEmptyValidator'=>new NotEmptyValidator);
$this->assertInstanceOf('iValidator', new NotEmptyValidator());
$array = array('NotEmptyValidator'=>new NotEmptyValidator());
$this->assertAttributeEquals($array, 'validators', $tmp_form_field); $this->assertAttributeEquals($array, 'validators', $tmp_form_field);
$this->assertSame($tmp_form_field, $return_object); $this->assertSame($tmp_form_field, $return_object);
} }
@ -101,7 +101,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
{ {
$validator = true; $validator = true;
$this->setExpectedException('Exception'); $this->setExpectedException('Exception');
$tmp_form_field = new FormField;
$tmp_form_field = new FormField();
$tmp_form_field->addValidator($validator); $tmp_form_field->addValidator($validator);
} }
@ -111,7 +111,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
$array = array('loginFilter' => new loginFilter(),'passwordFilter' => new passwordFilter()); $array = array('loginFilter' => new loginFilter(),'passwordFilter' => new passwordFilter());
$this->assertInstanceOf('iFilter', $array['loginFilter']); $this->assertInstanceOf('iFilter', $array['loginFilter']);
$this->assertInstanceOf('iFilter', $array['passwordFilter']); $this->assertInstanceOf('iFilter', $array['passwordFilter']);
$tmp_form_field = new FormField;
$tmp_form_field = new FormField();
$return_object = $tmp_form_field->addFilters($array); $return_object = $tmp_form_field->addFilters($array);
$this->assertAttributeEquals($array, 'filters', $tmp_form_field); $this->assertAttributeEquals($array, 'filters', $tmp_form_field);
$this->assertSame($tmp_form_field, $return_object); $this->assertSame($tmp_form_field, $return_object);
@ -119,10 +119,10 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
public function testAddFilterObject() public function testAddFilterObject()
{ {
$filter = new loginFilter;
$filter = new loginFilter();
$array = array('loginFilter' => new loginFilter()); $array = array('loginFilter' => new loginFilter());
$this->assertInstanceOf('iFilter', new loginFilter);
$tmp_form_field = new FormField;
$this->assertInstanceOf('iFilter', new loginFilter());
$tmp_form_field = new FormField();
$return_object = $tmp_form_field->addFilter($filter); $return_object = $tmp_form_field->addFilter($filter);
$this->assertAttributeEquals($array, 'filters', $tmp_form_field); $this->assertAttributeEquals($array, 'filters', $tmp_form_field);
$this->assertSame($tmp_form_field, $return_object); $this->assertSame($tmp_form_field, $return_object);
@ -130,9 +130,9 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
public function testAddFilterString() public function testAddFilterString()
{ {
$tmp_form_field = new FormField;
$tmp_form_field = new FormField();
$array = array('loginFilter' => new loginFilter()); $array = array('loginFilter' => new loginFilter());
$this->assertInstanceOf('iFilter', new loginFilter);
$this->assertInstanceOf('iFilter', new loginFilter());
$return_object = $tmp_form_field->addFilter('login'); $return_object = $tmp_form_field->addFilter('login');
$this->assertAttributeEquals($array, 'filters', $tmp_form_field); $this->assertAttributeEquals($array, 'filters', $tmp_form_field);
$this->assertSame($tmp_form_field, $return_object); $this->assertSame($tmp_form_field, $return_object);
@ -141,8 +141,8 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
public function testAddFilterElse() public function testAddFilterElse()
{ {
$this->setExpectedException('Exception'); $this->setExpectedException('Exception');
$filter = new NotEmptyValidator;
$tmp_form_field = new FormField;
$filter = new NotEmptyValidator();
$tmp_form_field = new FormField();
$tmp_form_field->addFilter($filter); $tmp_form_field->addFilter($filter);
} }
@ -155,7 +155,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
'password'=> 'password' 'password'=> 'password'
); );
$this->assertTrue($form->isValid($test_array)); $this->assertTrue($form->isValid($test_array));
$tmp_form_field = new FormField;
$tmp_form_field = new FormField();
$this->assertTrue($tmp_form_field->isValid($test_array)); $this->assertTrue($tmp_form_field->isValid($test_array));
$this->assertAttributeInternalType('array', 'value', $tmp_form_field); $this->assertAttributeInternalType('array', 'value', $tmp_form_field);
$this->assertArrayHasKey('login', $tmp_form_field->getSourceValue()); $this->assertArrayHasKey('login', $tmp_form_field->getSourceValue());
@ -170,7 +170,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
$test_form_field = new FormField(); $test_form_field = new FormField();
$this->assertTrue($test_form_field->isValid($test_array['login'])); $this->assertTrue($test_form_field->isValid($test_array['login']));
$this->assertAttributeNotInternalType('array', 'value', $test_form_field); $this->assertAttributeNotInternalType('array', 'value', $test_form_field);
$this->assertEquals('login',$test_form_field->getSourceValue());
$this->assertEquals('login', $test_form_field->getSourceValue());
} }
public function testGetMessage() public function testGetMessage()
@ -199,8 +199,8 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
); );
$test_form_field = new FormField('ssssssss'); $test_form_field = new FormField('ssssssss');
$return_object = $test_form_field->addValidator('NotEmpty'); $return_object = $test_form_field->addValidator('NotEmpty');
$this->assertInstanceOf('iValidator', new NotEmptyValidator);
$array = array('NotEmptyValidator'=>new NotEmptyValidator);
$this->assertInstanceOf('iValidator', new NotEmptyValidator());
$array = array('NotEmptyValidator'=>new NotEmptyValidator());
$this->assertAttributeEquals($array, 'validators', $test_form_field); $this->assertAttributeEquals($array, 'validators', $test_form_field);
$this->assertSame($test_form_field, $return_object); $this->assertSame($test_form_field, $return_object);
$this->assertFalse($test_form_field->isValid($test_array)); $this->assertFalse($test_form_field->isValid($test_array));
@ -208,7 +208,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
public function testIsValidMissingRequired() public function testIsValidMissingRequired()
{ {
$form_field = new FormField;
$form_field = new FormField();
$form_field->setRequired(false); $form_field->setRequired(false);
$this->assertTrue($form_field->isValid('')); $this->assertTrue($form_field->isValid(''));
} }
@ -220,17 +220,17 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
'password'=> 'password' 'password'=> 'password'
); );
$validator = new NotEmptyValidator(); $validator = new NotEmptyValidator();
$form_field = new FormField;
$form_field = new FormField();
$return_object = $form_field->addValidator($validator); $return_object = $form_field->addValidator($validator);
$this->assertTrue($form_field->isValid($test_array)); $this->assertTrue($form_field->isValid($test_array));
} }
public function testFilterValue() public function testFilterValue()
{ {
$form_field = new FormField;
$form_field = new FormField();
$form_field->isValid('login'); $form_field->isValid('login');
$form_field->addFilter('login'); $form_field->addFilter('login');
$lf = new loginFilter;
$lf = new loginFilter();
$this->assertSame($form_field->getValue(), $lf->filter('login')); $this->assertSame($form_field->getValue(), $lf->filter('login'));
} }
} }

5
tests/form/FormTest.php

@ -192,9 +192,4 @@ class NotEmptyForm extends Form
$validator->setMessage('Enter your password.'); $validator->setMessage('Enter your password.');
$this->addField('password')->addValidator($validator); $this->addField('password')->addValidator($validator);
} }
public function getProp($name)
{
return $this->$name;
}
} }

10
tests/form/FormViewHelperTest.php

@ -34,33 +34,33 @@ class FormViewHelperTest extends PHPUnit_Framework_TestCase
public function testForm2() public function testForm2()
{ {
$this->assertNull($this->assertAttributeEquals(null,'data',$this->form));
$this->assertNull($this->assertAttributeEquals(null, 'data', $this->form));
$this->setExpectedException('Exception'); $this->setExpectedException('Exception');
$this->form->form(null); $this->form->form(null);
} }
public function testForm1() public function testForm1()
{ {
$this->assertNull($this->assertAttributeEquals(null,'data',$this->form)); //аналог getProp
$this->assertNull($this->assertAttributeEquals(null, 'data', $this->form)); //аналог getProp
$this->form->form('path'); $this->form->form('path');
} }
public function testValueIsset() public function testValueIsset()
{ {
$this->form->form('path'); $this->form->form('path');
$this->assertEquals('path', $this->form->value('path'));
$this->assertEquals(htmlentities('path', ENT_QUOTES, 'UTF-8'), $this->form->value('path'));
} }
public function testValueNotIsset() public function testValueNotIsset()
{ {
$this->form->form('path'); $this->form->form('path');
$this->assertEquals('param2', $this->form->value('param1','param2'));
$this->assertEquals(htmlentities('param2', ENT_QUOTES, 'UTF-8'), $this->form->value('param1','param2'));
} }
public function testMessageIsset() public function testMessageIsset()
{ {
$this->form->form('path'); $this->form->form('path');
$this->assertNotEmpty($this->form->message('path'));
$this->assertEquals('<span class="error">' . htmlentities('path', ENT_QUOTES, 'UTF-8') . '</span>', $this->form->message('path'));
} }
public function testMessageNotIsset() public function testMessageNotIsset()

Loading…
Cancel
Save