Open Journal Systems  3.3.0
FormValidatorUsernameTest.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 
28  // Allowed characters are a-z, 0-9, -, _. The characters - and _ are
29  // not allowed at the start of the string.
30  $form->setData('testData', 'a-z0123_bkj');
31  $validator = new FormValidatorUsername($form, 'testData', FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key');
32  self::assertTrue($validator->isValid());
33 
34  // Test invalid strings
35  $form->setData('testData', '-z0123_bkj');
36  $validator = new FormValidatorUsername($form, 'testData', FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key');
37  self::assertFalse($validator->isValid());
38 
39  $form->setData('testData', 'abc#def');
40  $validator = new FormValidatorUsername($form, 'testData', FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key');
41  self::assertFalse($validator->isValid());
42  }
43 }
44 
FormValidatorUsername
Form validation check for usernames (lowercase alphanumeric with interior dash/underscore.
Definition: FormValidatorUsername.inc.php:19
PKPTestCase
Class that implements functionality common to all PKP unit test cases.
Definition: PKPTestCase.inc.php:27
FormValidatorUsernameTest\testIsValid
testIsValid()
Definition: FormValidatorUsernameTest.php:25
FormValidatorUsernameTest
Test class for FormValidatorUsername.
Definition: FormValidatorUsernameTest.php:20
Form
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47