Merge "Surround edit notices with appropriate classes"
[lhc/web/wiklou.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->getMock( 'User' );
21 $user->expects( $this->any() )->method( 'getName' )->will( $this->returnValue( 'UserName' ) );
22 $user->expects( $this->any() )->method( 'getEmail' )->will( $this->returnValue( 'foo@bar.baz' ) );
23 $user->expects( $this->any() )->method( 'getRealName' )->will( $this->returnValue( 'Real name' ) );
24
25 $ma = MailAddress::newFromUser( $user );
26 $this->assertInstanceOf( 'MailAddress', $ma );
27 $this->setMwGlobals( 'wgEnotifUseRealName', true );
28 $this->assertEquals( 'Real name <foo@bar.baz>', $ma->toString() );
29 $this->setMwGlobals( 'wgEnotifUseRealName', false );
30 $this->assertEquals( 'UserName <foo@bar.baz>', $ma->toString() );
31 }
32
33 /**
34 * @covers MailAddress::toString
35 * @dataProvider provideToString
36 */
37 public function testToString( $useRealName, $address, $name, $realName, $expected ) {
38 if ( wfIsWindows() ) {
39 $this->markTestSkipped( 'This test only works on non-Windows platforms' );
40 }
41 $this->setMwGlobals( 'wgEnotifUseRealName', $useRealName );
42 $ma = new MailAddress( $address, $name, $realName );
43 $this->assertEquals( $expected, $ma->toString() );
44 }
45
46 public static function provideToString() {
47 return array(
48 array( true, 'foo@bar.baz', 'FooBar', 'Foo Bar', 'Foo Bar <foo@bar.baz>' ),
49 array( true, 'foo@bar.baz', 'UserName', null, 'UserName <foo@bar.baz>' ),
50 array( true, 'foo@bar.baz', 'AUser', 'My real name', 'My real name <foo@bar.baz>' ),
51 array( true, 'foo@bar.baz', 'A.user.name', 'my@real.name', '"my@real.name" <foo@bar.baz>' ),
52 array( false, 'foo@bar.baz', 'AUserName', 'Some real name', 'AUserName <foo@bar.baz>' ),
53 array( false, 'foo@bar.baz', '', '', 'foo@bar.baz' ),
54 array( true, 'foo@bar.baz', '', '', 'foo@bar.baz' ),
55 array( true, '', '', '', '' ),
56 );
57 }
58
59 /**
60 * @covers MailAddress::__toString
61 */
62 public function test__ToString() {
63 $ma = new MailAddress( 'some@email.com', 'UserName', 'A real name' );
64 $this->assertEquals( $ma->toString(), (string)$ma );
65 }
66 }