MediaWiki  REL1_24
MailAddressTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class MailAddressTest extends MediaWikiTestCase {
00004 
00008     public function testConstructor() {
00009         $ma = new MailAddress( '[email protected]', 'UserName', 'Real name' );
00010         $this->assertInstanceOf( 'MailAddress', $ma );
00011     }
00012 
00016     public function testNewFromUser() {
00017         $user = $this->getMock( 'User' );
00018         $user->expects( $this->any() )->method( 'getName' )->will( $this->returnValue( 'UserName' ) );
00019         $user->expects( $this->any() )->method( 'getEmail' )->will( $this->returnValue( '[email protected]' ) );
00020         $user->expects( $this->any() )->method( 'getRealName' )->will( $this->returnValue( 'Real name' ) );
00021 
00022         $ma = MailAddress::newFromUser( $user );
00023         $this->assertInstanceOf( 'MailAddress', $ma );
00024         $this->setMwGlobals( 'wgEnotifUseRealName', true );
00025         $this->assertEquals( 'Real name <[email protected]>', $ma->toString() );
00026         $this->setMwGlobals( 'wgEnotifUseRealName', false );
00027         $this->assertEquals( 'UserName <[email protected]>', $ma->toString() );
00028     }
00029 
00034     public function testToString( $useRealName, $address, $name, $realName, $expected ) {
00035         if ( wfIsWindows() ) {
00036             $this->markTestSkipped( 'This test only works on non-Windows platforms' );
00037         }
00038         $this->setMwGlobals( 'wgEnotifUseRealName', $useRealName );
00039         $ma = new MailAddress( $address, $name, $realName );
00040         $this->assertEquals( $expected, $ma->toString() );
00041     }
00042 
00043     public static function provideToString() {
00044         return array(
00045             array( true, '[email protected]', 'FooBar', 'Foo Bar', 'Foo Bar <[email protected]>' ),
00046             array( true, '[email protected]', 'UserName', null, 'UserName <[email protected]>' ),
00047             array( true, '[email protected]', 'AUser', 'My real name', 'My real name <[email protected]>' ),
00048             array( true, '[email protected]', 'A.user.name', '[email protected]', '"[email protected]" <[email protected]>' ),
00049             array( false, '[email protected]', 'AUserName', 'Some real name', 'AUserName <[email protected]>' ),
00050             array( false, '[email protected]', '', '', '[email protected]' ),
00051             array( true, '[email protected]', '', '', '[email protected]' ),
00052         );
00053     }
00054 
00058     public function test__ToString() {
00059         $ma = new MailAddress( '[email protected]', 'UserName', 'A real name' );
00060         $this->assertEquals( $ma->toString(), (string)$ma );
00061     }
00062 
00063 }