* @license PHP License * @package WB * @subpackage unittest */ require_once dirname(__FILE__) . '/form/auxiliary.php'; /** * Unit Test * * * * @version 0.2.0 * @package WB * @subpackage unittest */ class TestCasePat_Forms_Base extends TestCasePat_Forms { /** * load class and start */ public function testInit() { $form = null; WBClass::load( 'WBException_Argument' ); // first shot try{ $form = WBClass::create( 'patForms' ); $this->assertTrue( false ); } catch( WBException_Argument $e ) { $code = $e->getCode(); $this->assertEqual( 'WBClass_Creator_patForms.1', $e->getCode() ); } $this->assertNull( $form ); $this->assertTrue( class_exists( 'patForms', false ) ); // second shot $params = array( 'elements' => array( 'proper' => array( 'type' => 'String', 'attributes' => array( 'name' => 'proper', 'maxlength' => 200 ) ), 'wrong' => array( 'type' => 'String', 'attributes' => array( 'name' => 'wrong', ) ) ) ); try{ $form = WBClass::create( 'patForms', $params ); $this->assertTrue( false ); } catch( WBException_Argument $e ) { $code = $e->getCode(); $this->assertEqual( 'WBClass_Creator_patForms.2', $e->getCode() ); } $this->assertNull( $form ); // now this should work $params = array( 'elements' => array( 'proper' => array( 'type' => 'String', 'attributes' => array( 'name' => 'proper', 'maxlength' => 200 ) ), 'number' => array( 'type' => 'Number', 'attributes' => array( 'name' => 'number', ) ) ) ); try{ $form = WBClass::create( 'patForms', $params ); } catch( WBException_Argument $e ) { $code = $e->getCode(); $this->assertEqual( 'WBClass_Creator_patForms.2', $e->getCode() ); } $this->assertIsA( $form, 'patForms' ); } /** * load class and start */ public function testSimpleFormProcessor() { $fp = new formProcSimple(); $values = array( 'save' => null ); $this->req->import($values); $this->assertTrue( $fp->processForm('formSimple')); // validate form $values = array( 'save' => 'save me' ); $this->req->import($values); $this->assertFalse( $fp->processForm('formSimple')); // validate form $values = array( 'save' => 'save me', 'name' => 'Joe Doe', 'age' => '18' ); $this->req->import($values); $this->assertTrue($fp->processForm('formSimple')); // validate form $values = array( 'save' => 'save me', 'name' => 'Jo', 'age' => '18' ); $this->req->import($values); $this->assertFalse($fp->processForm('formSimple')); // validate form $values = array( 'save' => 'save me', 'name' => '', 'age' => '18' ); $this->req->import($values); $this->assertFalse($fp->processForm('formSimple')); // validate form $values = array( 'save' => 'save me', 'name' => 'Joe Doe', 'age' => '17' ); $this->req->import($values); $this->assertFalse($fp->processForm('formSimple')); // validate form $values = array( 'save' => 'save me', 'name' => 'Joe Doe', 'age' => '155' ); $this->req->import($values); $this->assertFalse($fp->processForm('formSimple')); // validate form $values = array( 'save' => 'save me', 'name' => '', 'age' => '' ); $this->req->import($values); $this->assertFalse($fp->processForm('formSimple')); } } ?>