MediaWiki REL1_33
SanitizerValidateEmailTest.php
Go to the documentation of this file.
1<?php
2
8class SanitizerValidateEmailTest extends PHPUnit\Framework\TestCase {
9
10 use MediaWikiCoversValidator;
11
12 private function checkEmail( $addr, $expected = true, $msg = '' ) {
13 if ( $msg == '' ) {
14 $msg = "Testing $addr";
15 }
16
17 $this->assertEquals(
18 $expected,
19 Sanitizer::validateEmail( $addr ),
20 $msg
21 );
22 }
23
24 private function valid( $addr, $msg = '' ) {
25 $this->checkEmail( $addr, true, $msg );
26 }
27
28 private function invalid( $addr, $msg = '' ) {
29 $this->checkEmail( $addr, false, $msg );
30 }
31
33 $this->valid( 'user@example.com' );
34 $this->valid( 'user@example.museum' );
35 }
36
38 $this->valid( 'USER@example.com' );
39 $this->valid( 'user@EXAMPLE.COM' );
40 $this->valid( 'user@Example.com' );
41 $this->valid( 'USER@eXAMPLE.com' );
42 }
43
44 public function testEmailWithAPlusInUserName() {
45 $this->valid( 'user+sub@example.com' );
46 $this->valid( 'user+@example.com' );
47 }
48
50 $this->valid( "user@localhost" );
51 $this->valid( "FooBar@localdomain" );
52 $this->valid( "nobody@mycompany" );
53 }
54
56 $this->invalid( " user@host.com" );
57 $this->invalid( "user@host.com " );
58 $this->invalid( "\tuser@host.com" );
59 $this->invalid( "user@host.com\t" );
60 }
61
63 $this->invalid( "User user@host" );
64 $this->invalid( "first last@mycompany" );
65 $this->invalid( "firstlast@my company" );
66 }
67
72 $this->invalid( "user,foo@example.org" );
73 $this->invalid( "userfoo@ex,ample.org" );
74 }
75
76 public function testEmailWithHyphens() {
77 $this->valid( "user-foo@example.org" );
78 $this->valid( "userfoo@ex-ample.org" );
79 }
80
82 $this->invalid( "user@." );
83 $this->invalid( "user@.localdomain" );
84 $this->invalid( "user@localdomain." );
85 $this->valid( "user.@localdomain" );
86 $this->valid( ".@localdomain" );
87 $this->invalid( ".@a............" );
88 }
89
90 public function testEmailWithFunnyCharacters() {
91 $this->valid( "\$user!ex{this}@123.com" );
92 }
93
95 $this->valid( "user@example.1234" );
96 }
97
99 $this->invalid( 'useràexample.com' );
100 }
101
103 $this->valid( 'user@a' );
104 }
105}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
testEmailWithCommasAreInvalids()
T28948 : comma were matched by an incorrect regexp range.
checkEmail( $addr, $expected=true, $msg='')