Open Journal Systems  3.3.0
FormValidatorLengthTest.php
1 <?php
2 
17 import('lib.pkp.tests.PKPTestCase');
18 import('lib.pkp.classes.form.Form');
19 
25  public function testIsValid() {
26  $form = new Form('some template');
27  $form->setData('testData', 'test');
28 
29  // Encode the tests to be run against the validator
30  $tests = array(
31  array('==', 4, true),
32  array('==', 5, false),
33  array('==', 3, false),
34  array('!=', 4, false),
35  array('!=', 5, true),
36  array('!=', 3, true),
37  array('<', 5, true),
38  array('<', 4, false),
39  array('>', 3, true),
40  array('>', 4, false),
41  array('<=', 4, true),
42  array('<=', 5, true),
43  array('<=', 3, false),
44  array('>=', 4, true),
45  array('>=', 3, true),
46  array('>=', 5, false),
47  array('...', 3, false)
48  );
49 
50  foreach($tests as $test) {
51  $validator = new FormValidatorLength($form, 'testData', FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key', $test[0], $test[1]);
52  self::assertSame($test[2], $validator->isValid());
53  }
54 
55  // Test optional validation type
56  $form->setData('testData', '');
57  $validator = new FormValidatorLength($form, 'testData', FORM_VALIDATOR_OPTIONAL_VALUE, 'some.message.key', '==', 4);
58  self::assertTrue($validator->isValid());
59  }
60 }
61 
FormValidatorLength
Form validation check that checks if a field's length meets certain requirements.
Definition: FormValidatorLength.inc.php:18
PKPTestCase
Class that implements functionality common to all PKP unit test cases.
Definition: PKPTestCase.inc.php:27
FormValidatorLengthTest
Test class for FormValidatorLength.
Definition: FormValidatorLengthTest.php:20
FormValidatorLengthTest\testIsValid
testIsValid()
Definition: FormValidatorLengthTest.php:25
Form
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47