Add tests for MailAddress
[lhc/web/wiklou.git] / tests / phpunit / includes / mail / MailAddressTest.php
1 <?php
2
3 class MailAddressTest extends MediaWikiTestCase {
4
5 /**
6 * @covers MailAddress::toString
7 * @dataProvider provideToString
8 */
9 public function testToString( $useRealName, $address, $name, $realName, $expected ) {
10 if ( wfIsWindows() ) {
11 $this->markTestSkipped( 'This test only works on non-Windows platforms' );
12 }
13 $this->setMwGlobals( 'wgEnotifUseRealName', $useRealName );
14 $ma = new MailAddress( $address, $name, $realName );
15 $this->assertEquals( $expected, $ma->toString() );
16 }
17
18 public static function provideToString() {
19 return array(
20 array( true, 'foo@bar.baz', 'FooBar', 'Foo Bar', 'Foo Bar <foo@bar.baz>' ),
21 array( true, 'foo@bar.baz', 'UserName', null, 'UserName <foo@bar.baz>' ),
22 array( true, 'foo@bar.baz', 'AUser', 'My real name', 'My real name <foo@bar.baz>' ),
23 array( true, 'foo@bar.baz', 'A.user.name', 'my@real.name', '"my@real.name" <foo@bar.baz>' ),
24 array( false, 'foo@bar.baz', 'AUserName', 'Some real name', 'AUserName <foo@bar.baz>' ),
25 array( false, 'foo@bar.baz', '', '', 'foo@bar.baz' ),
26 array( true, 'foo@bar.baz', '', '', 'foo@bar.baz' ),
27 );
28 }
29
30 /**
31 * @covers MailAddress::__toString
32 */
33 public function test__ToString() {
34 $ma = new MailAddress( 'some@email.com', 'UserName', 'A real name' );
35 $this->assertEquals( $ma->toString(), (string)$ma );
36 }
37
38 }