|
|
@ -15,6 +15,28 @@ require_once dirname(__FILE__) . '/../../validator/EmailValidator.php'; |
|
|
|
|
|
|
|
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() |
|
|
|
{ |
|
|
|
$form = new NotEmptyForm(); |
|
|
@ -39,6 +61,25 @@ class FormTest extends PHPUnit_Framework_TestCase |
|
|
|
'password'=> 'password' |
|
|
|
); |
|
|
|
$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() |
|
|
@ -192,4 +233,33 @@ class NotEmptyForm extends Form |
|
|
|
$validator->setMessage('Enter your password.'); |
|
|
|
$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) |
|
|
|
); |
|
|
|
} |
|
|
|
} |