Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / mail / MailAddressTest.php
blob18d2acdf38d6f438532e5dd3ca0dc853a7ae49de
1 <?php
3 class MailAddressTest extends MediaWikiTestCase {
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 );
13 /**
14 * @covers MailAddress::newFromUser
16 public function testNewFromUser() {
17 if ( wfIsWindows() ) {
18 $this->markTestSkipped( 'This test only works on non-Windows platforms' );
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' ) );
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() );
33 /**
34 * @covers MailAddress::toString
35 * @dataProvider provideToString
37 public function testToString( $useRealName, $address, $name, $realName, $expected ) {
38 if ( wfIsWindows() ) {
39 $this->markTestSkipped( 'This test only works on non-Windows platforms' );
41 $this->setMwGlobals( 'wgEnotifUseRealName', $useRealName );
42 $ma = new MailAddress( $address, $name, $realName );
43 $this->assertEquals( $expected, $ma->toString() );
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, '', '', '', '' ),
59 /**
60 * @covers MailAddress::__toString
62 public function test__ToString() {
63 $ma = new MailAddress( 'some@email.com', 'UserName', 'A real name' );
64 $this->assertEquals( $ma->toString(), (string)$ma );