/** * test default validation of DateInput and DateRangeInput */ public function testDateValidation() { // confirm when nothing posted nothing will be invalidated $this->assertTrue($this->form->validate()); $this->assertEmpty($this->form->oDate->getInvalidations()); // create invalid posted values /* * TODO commented these tests, because I currently can't properly simulate a POST of xsrftoken * $_POST = array('date' => '123-123', 'dateRange-from' => '1', 'dateRange-to' => '2', 'xsrftoken' => 'boo'); $form = new TestForm(); $this->assertFalse($form->validate()); $this->assertNotEmpty($form->oDate->getInvalidations()); $this->assertNotEmpty($form->oDateRange->getInvalidations()); */ }
<?php // require the library require_once '../vendor/autoload.php'; // force English version test form $t = \WinkForm\Translation\Translator::getInstance(); $t->setLocale('en'); // typically your own autoloader should be configured to look in your forms directory require_once 'TestForm.php'; // create the form $form = new TestForm(); if ($form->isPosted() && !$form->validate()) { echo error('Can\'t process form, because not all fields are filled correctly'); } // for sake of the example the html and css is inline here ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Form Example</title> <!-- DateInput uses jquery ui date picker --> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"> <!-- ChainedDropdowns uses this jquery plugin --> <script src="js/jquery.chained.min.js"></script> <!-- This script is required to use the placeholder attribute in IE -->
function testPrePostValidation() { $f = new TestForm(); $this->assertFalse($f->validate(array('one' => 1)), 'Форма без полей не валидна'); $f->addInput('one'); $this->assertTrue($f->validate(array('one' => 1)), 'Форма валидна'); $this->assertFalse($f->validate(array('before' => 1)), 'Пре-валидация: форма невалидна'); $this->assertFalse($f->validate(array('after' => 1)), 'Пост-валидация: форма невалидна'); }