Browse Source

fillhelperdata

master
Ilya Sigunov 13 years ago
parent
commit
8b74d80251
  1. 70
      tests/form/FormTest.php

70
tests/form/FormTest.php

@ -15,6 +15,28 @@ require_once dirname(__FILE__) . '/../../validator/EmailValidator.php';
class FormTest extends PHPUnit_Framework_TestCase class FormTest extends PHPUnit_Framework_TestCase
{ {
public function testAddFieldEmptyMessage()
{
$stub = $this->getMockForAbstractClass('Form');
$method = new ReflectionMethod('Form', 'addField');
$method->setAccessible(true);
$this->assertInstanceOf('FormField', $method->invoke($stub, 'login'));
}
public function testAddFieldWithMessage()
{
$message = 'message';
$form_field = new FormField($message);
$stub = $this->getMockForAbstractClass('Form');
$method = new ReflectionMethod('Form', 'addField');
$method->setAccessible(true);
$return_object = $method->invokeArgs($stub, array('login',$message));
$this->assertInstanceOf('FormField', $return_object);
$this->assertEquals($form_field, $return_object);
$this->assertAttributeEquals('message', 'default_message', $return_object);
}
public function testIsValidWithNotArray() public function testIsValidWithNotArray()
{ {
$form = new NotEmptyForm(); $form = new NotEmptyForm();
@ -39,6 +61,25 @@ class FormTest extends PHPUnit_Framework_TestCase
'password'=> 'password' 'password'=> 'password'
); );
$this->assertSame(0, $form->isValid($test_array)); $this->assertSame(0, $form->isValid($test_array));
$data['messages'] = $form->getMessages();
$data['values'] = $form->getSourceValues();
$this->assertSame($_SESSION['NotEmptyForm'], $data);
}
public function testFillHelperData()
{
$form = new NotEmptyForm();
$test_array = array(
'password'=> 'password'
);
$form->isValid($test_array);
$data['messages'] = $form->getMessages();
$data['values'] = $form->getSourceValues();
$stub = $this->getMockForAbstractClass('Form');
$method = new ReflectionMethod('Form', 'fillHelperData');
$method->setAccessible(true);
$method->invoke($stub);
$this->assertSame($_SESSION['NotEmptyForm'], $data);
} }
public function testGetValues() public function testGetValues()
@ -193,3 +234,32 @@ class NotEmptyForm extends Form
$this->addField('password')->addValidator($validator); $this->addField('password')->addValidator($validator);
} }
} }
class NullForm extends Form
{
public function init()
{
/**/
}
}
class FooTest extends PHPUnit_Framework_TestCase
{
/**
* @covers Foo::doSomethingPrivate
*/
public function testPrivateMethod()
{
$method = new ReflectionMethod(
'Foo', 'doSomethingPrivate'
);
$method->setAccessible(TRUE);
$this->assertEquals(
'blah', $method->invoke(new Foo)
);
}
}
Loading…
Cancel
Save