-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [#1903] fix(phoneValidation): fix validation to allow one number in…
… the optional sub-zone * [#1903] test(phoneValidation): Add some test cases
- Loading branch information
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package play.data.validation; | ||
|
||
import org.junit.Test; | ||
|
||
import play.data.validation.Validation.ValidationResult; | ||
import play.i18n.MessagesBuilder; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class PhoneTest { | ||
|
||
@Test | ||
public void validPhoneValidationTest() { | ||
new MessagesBuilder().build(); | ||
Validation.current.set(new Validation()); | ||
|
||
// US | ||
assertValidPhone(true, "(305) 613 09 58 ext 101"); | ||
assertValidPhone(true, "(305) 613 09 58 extension 101"); | ||
// France | ||
assertValidPhone(true, "+33 (0)147376224"); | ||
assertValidPhone(true, "+33 0147376224"); | ||
assertValidPhone(true, "+33 1 47 37 62 24 x3"); | ||
assertValidPhone(true, "+33 (0)1 47 37 62 24 x3"); | ||
assertValidPhone(true, "+33 0147376224 x3"); | ||
// Germany | ||
assertValidPhone(true, "+49-4312 / 777 777"); | ||
assertValidPhone(true, "+49-4312 / 777 777"); | ||
// China | ||
assertValidPhone(true, "+86 (10)69445464"); | ||
assertValidPhone(true, "+86 (00)69445464"); | ||
|
||
// UK | ||
assertValidPhone(true, "(020) 1234 1234"); | ||
} | ||
|
||
@Test | ||
public void invalidalidPhoneValidationTest() { | ||
new MessagesBuilder().build(); | ||
Validation.current.set(new Validation()); | ||
|
||
assertValidPhone(false, "(305) abc 09 58 ext 101"); | ||
// France | ||
assertValidPhone(false, "+330147376224"); | ||
assertValidPhone(false, "+33(0)147376224"); | ||
assertValidPhone(false, "+33 (0)1 47 37 62 24 x3"); | ||
|
||
// China | ||
assertValidPhone(false, "+86(10)69445464"); | ||
assertValidPhone(false, "+86(0)69445464"); | ||
|
||
assertValidPhone(false, "+1229 343433345"); | ||
} | ||
|
||
public void assertValidPhone(Boolean valid, String phone){ | ||
Validation.clear(); | ||
ValidationResult result = Validation.phone("phone", phone); | ||
assertEquals("Validation phone [" + phone + "] should be " + valid, valid, result.ok); | ||
} | ||
|
||
} |