]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - tests/phpunit/includes/mail/MailAddressTest.php
MediaWiki 1.30.2
[autoinstalls/mediawiki.git] / tests / phpunit / includes / mail / MailAddressTest.php
1 <?php
2
3 class MailAddressTest extends MediaWikiTestCase {
4
5         /**
6          * @covers MailAddress::__construct
7          */
8         public function testConstructor() {
9                 $ma = new MailAddress( 'foo@bar.baz', 'UserName', 'Real name' );
10                 $this->assertInstanceOf( 'MailAddress', $ma );
11         }
12
13         /**
14          * @covers MailAddress::newFromUser
15          */
16         public function testNewFromUser() {
17                 if ( wfIsWindows() ) {
18                         $this->markTestSkipped( 'This test only works on non-Windows platforms' );
19                 }
20                 $user = $this->createMock( 'User' );
21                 $user->expects( $this->any() )->method( 'getName' )->will(
22                         $this->returnValue( 'UserName' )
23                 );
24                 $user->expects( $this->any() )->method( 'getEmail' )->will(
25                         $this->returnValue( 'foo@bar.baz' )
26                 );
27                 $user->expects( $this->any() )->method( 'getRealName' )->will(
28                         $this->returnValue( 'Real name' )
29                 );
30
31                 $ma = MailAddress::newFromUser( $user );
32                 $this->assertInstanceOf( 'MailAddress', $ma );
33                 $this->setMwGlobals( 'wgEnotifUseRealName', true );
34                 $this->assertEquals( 'Real name <foo@bar.baz>', $ma->toString() );
35                 $this->setMwGlobals( 'wgEnotifUseRealName', false );
36                 $this->assertEquals( 'UserName <foo@bar.baz>', $ma->toString() );
37         }
38
39         /**
40          * @covers MailAddress::toString
41          * @dataProvider provideToString
42          */
43         public function testToString( $useRealName, $address, $name, $realName, $expected ) {
44                 if ( wfIsWindows() ) {
45                         $this->markTestSkipped( 'This test only works on non-Windows platforms' );
46                 }
47                 $this->setMwGlobals( 'wgEnotifUseRealName', $useRealName );
48                 $ma = new MailAddress( $address, $name, $realName );
49                 $this->assertEquals( $expected, $ma->toString() );
50         }
51
52         public static function provideToString() {
53                 return [
54                         [ true, 'foo@bar.baz', 'FooBar', 'Foo Bar', 'Foo Bar <foo@bar.baz>' ],
55                         [ true, 'foo@bar.baz', 'UserName', null, 'UserName <foo@bar.baz>' ],
56                         [ true, 'foo@bar.baz', 'AUser', 'My real name', 'My real name <foo@bar.baz>' ],
57                         [ true, 'foo@bar.baz', 'A.user.name', 'my@real.name', '"my@real.name" <foo@bar.baz>' ],
58                         [ false, 'foo@bar.baz', 'AUserName', 'Some real name', 'AUserName <foo@bar.baz>' ],
59                         [ false, 'foo@bar.baz', '', '', 'foo@bar.baz' ],
60                         [ true, 'foo@bar.baz', '', '', 'foo@bar.baz' ],
61                         [ true, '', '', '', '' ],
62                 ];
63         }
64
65         /**
66          * @covers MailAddress::__toString
67          */
68         public function test__ToString() {
69                 $ma = new MailAddress( 'some@email.com', 'UserName', 'A real name' );
70                 $this->assertEquals( $ma->toString(), (string)$ma );
71         }
72 }