This repository has been archived by the owner on Dec 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestFixtures.go
63 lines (52 loc) · 1.82 KB
/
TestFixtures.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package ecms_go_inputfilter
import (
ecms_validator "github.com/extensible-cms/ecms-go-validator"
"regexp"
)
var (
ContactFormInputFilter InputFilter
NameInput *Input
EmailInput *Input
SubjInput *Input
MessageInput *Input
)
func init() {
nameValidatorOps := ecms_validator.NewRegexValidatorOptions()
nameValidatorOps.Pattern = regexp.MustCompile("^[a-zA-Z][a-zA-Z\\s'\"]{4,54}$")
NameValidator := ecms_validator.RegexValidator(nameValidatorOps)
NameInput = NewInput("name")
NameInput.Required = true
NameInput.RequiredMessage = "Name is required."
NameInput.AddValidator(NameValidator)
EmailInput = NewInput("email")
EmailInput.Required = true
EmailInput.RequiredMessage = "Email is required."
fakeEmailValidatorOps := ecms_validator.NewRegexValidatorOptions()
fakeEmailValidatorOps.Pattern = regexp.MustCompile("^[^@]{1,55}@[^@]{1,55}$")
fakeEmailValidator := ecms_validator.RegexValidator(fakeEmailValidatorOps)
EmailInput.AddValidator(fakeEmailValidator)
DescrLenValidatorOps := ecms_validator.NewLengthValidatorOptions()
DescrLenValidatorOps.Min = 1
DescrLenValidatorOps.Max = 2048
DescrLenValidator := ecms_validator.LengthValidator(DescrLenValidatorOps)
SubjInput = NewInput("subject")
SubjInput.AddValidator(func() ecms_validator.Validator {
lenOps := ecms_validator.NewLengthValidatorOptions()
lenOps.Min = 3
lenOps.Max = 55
return ecms_validator.LengthValidator(lenOps)
}())
MessageInput = NewInput("message")
MessageInput.Required = true
MessageInput.RequiredMessage = "Message is required."
MessageInput.AddValidator(DescrLenValidator)
ContactFormInputFilter = InputFilter{
Inputs: map[string]*Input{
NameInput.Name: NameInput,
EmailInput.Name: EmailInput,
SubjInput.Name: SubjInput,
MessageInput.Name: MessageInput,
},
BreakOnFailure: false, // validate all inputs
}
}