Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
9a99b766
Commit
9a99b766
authored
8 years ago
by
gnaegi
Browse files
Options
Downloads
Patches
Plain Diff
OO-1969 allow more phone number formats, write testcases
parent
defaaeda
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/olat/user/propertyhandlers/PhonePropertyHandler.java
+3
-3
3 additions, 3 deletions
.../org/olat/user/propertyhandlers/PhonePropertyHandler.java
src/test/java/org/olat/user/UserPropertiesTest.java
+32
-13
32 additions, 13 deletions
src/test/java/org/olat/user/UserPropertiesTest.java
with
35 additions
and
16 deletions
src/main/java/org/olat/user/propertyhandlers/PhonePropertyHandler.java
+
3
−
3
View file @
9a99b766
...
...
@@ -40,7 +40,7 @@ import org.olat.core.util.StringHelper;
public
class
PhonePropertyHandler
extends
Generic127CharTextPropertyHandler
{
// Regexp to define valid phone numbers
private
static
final
Pattern
VALID_PHONE_PATTERN_IP
=
Pattern
.
compile
(
"[0-9/\\-+'
]+"
);
private
static
final
Pattern
VALID_PHONE_PATTERN_IP
=
Pattern
.
compile
(
"[0-9/\\-+'
\\(\\)\\. e(ext\\.*)(extension)
]+"
);
/* (non-Javadoc)
* @see org.olat.user.propertyhandlers.Generic127CharTextPropertyHandler#addFormItem(java.util.Locale, org.olat.core.id.User, java.lang.String, boolean, org.olat.core.gui.components.form.flexible.FormItemContainer)
...
...
@@ -85,7 +85,7 @@ public class PhonePropertyHandler extends Generic127CharTextPropertyHandler {
if
(
StringHelper
.
containsNonWhitespace
(
value
))
{
// check phone address syntax
if
(!
VALID_PHONE_PATTERN_IP
.
matcher
(
value
).
matches
())
{
if
(!
VALID_PHONE_PATTERN_IP
.
matcher
(
value
.
toLowerCase
()
).
matches
())
{
formItem
.
setErrorKey
(
i18nFormElementLabelKey
()
+
".error.valid"
,
null
);
return
false
;
}
...
...
@@ -103,7 +103,7 @@ public class PhonePropertyHandler extends Generic127CharTextPropertyHandler {
if
(
StringHelper
.
containsNonWhitespace
(
value
))
{
// check phone address syntax
if
(
!
VALID_PHONE_PATTERN_IP
.
matcher
(
value
).
matches
())
{
if
(
!
VALID_PHONE_PATTERN_IP
.
matcher
(
value
.
toLowerCase
()
).
matches
())
{
validationError
.
setErrorKey
(
i18nFormElementLabelKey
()+
".error.valid"
);
return
false
;
}
...
...
This diff is collapsed.
Click to expand it.
src/test/java/org/olat/user/UserPropertiesTest.java
+
32
−
13
View file @
9a99b766
...
...
@@ -19,11 +19,12 @@
*/
package
org.olat.user
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
org.junit.Test
;
import
org.olat.core.gui.components.form.ValidationError
;
import
org.olat.user.propertyhandlers.PhonePropertyHandler
;
import
org.olat.user.propertyhandlers.URLPropertyHandler
;
/**
...
...
@@ -44,19 +45,37 @@ public class UserPropertiesTest {
URLPropertyHandler
urlHandler
=
new
URLPropertyHandler
();
ValidationError
error
=
new
ValidationError
();
boolean
valid1
=
urlHandler
.
isValidValue
(
null
,
"http://www.openolat.org"
,
error
,
null
);
assertTrue
(
valid1
);
boolean
valid2
=
urlHandler
.
isValidValue
(
null
,
"http://test.ch"
,
error
,
null
);
assertTrue
(
valid2
);
boolean
valid3
=
urlHandler
.
isValidValue
(
null
,
"http://localhost"
,
error
,
null
);
assertTrue
(
valid3
);
boolean
invalid1
=
urlHandler
.
isValidValue
(
null
,
"http:www.openolat.org"
,
error
,
null
);
assertFalse
(
invalid1
);
// test for valid URL's
assertTrue
(
urlHandler
.
isValidValue
(
null
,
"http://www.openolat.org"
,
error
,
null
));
assertTrue
(
urlHandler
.
isValidValue
(
null
,
"https://www.openolat.org"
,
error
,
null
));
assertTrue
(
urlHandler
.
isValidValue
(
null
,
"http://test.ch"
,
error
,
null
));
assertTrue
(
urlHandler
.
isValidValue
(
null
,
"http://localhost"
,
error
,
null
));
// test for invalid URL's
assertFalse
(
urlHandler
.
isValidValue
(
null
,
"http:www.openolat.org"
,
error
,
null
));
assertFalse
(
urlHandler
.
isValidValue
(
null
,
"www.openolat.org"
,
error
,
null
));
}
@Test
public
void
testPhonePropertyHandlerValidation
()
{
PhonePropertyHandler
phoneHandler
=
new
PhonePropertyHandler
();
ValidationError
error
=
new
ValidationError
();
// test for valid phone number formats
assertTrue
(
phoneHandler
.
isValidValue
(
null
,
"043 544 90 00"
,
error
,
null
));
assertTrue
(
phoneHandler
.
isValidValue
(
null
,
"043/544'90'00"
,
error
,
null
));
assertTrue
(
phoneHandler
.
isValidValue
(
null
,
"043/544'90'00"
,
error
,
null
));
assertTrue
(
phoneHandler
.
isValidValue
(
null
,
"043-544-90-00"
,
error
,
null
));
assertTrue
(
phoneHandler
.
isValidValue
(
null
,
"043.544.90.00"
,
error
,
null
));
assertTrue
(
phoneHandler
.
isValidValue
(
null
,
"+41 43 544 90 00"
,
error
,
null
));
assertTrue
(
phoneHandler
.
isValidValue
(
null
,
"+41 (0)43 544 90 00"
,
error
,
null
));
assertTrue
(
phoneHandler
.
isValidValue
(
null
,
"+41 43 544 90 00 x0"
,
error
,
null
));
assertTrue
(
phoneHandler
.
isValidValue
(
null
,
"+41 43 544 90 00 ext. 0"
,
error
,
null
));
assertTrue
(
phoneHandler
.
isValidValue
(
null
,
"+41 43 544 90 00 ext0"
,
error
,
null
));
assertTrue
(
phoneHandler
.
isValidValue
(
null
,
"+41 43 544 90 00 ext 0"
,
error
,
null
));
assertTrue
(
phoneHandler
.
isValidValue
(
null
,
"+41 43 544 90 00 extension 0"
,
error
,
null
));
assertTrue
(
phoneHandler
.
isValidValue
(
null
,
"+41 43 544 90 00 Extension 0"
,
error
,
null
));
// test for invalid phone number formats
assertFalse
(
phoneHandler
.
isValidValue
(
null
,
"+41 43 frentix GmbH"
,
error
,
null
));
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment