MediaWiki  1.30.0
MailAddressTest.php
Go to the documentation of this file.
1 <?php
2 
4 
8  public function testConstructor() {
9  $ma = new MailAddress( 'foo@bar.baz', 'UserName', 'Real name' );
10  $this->assertInstanceOf( 'MailAddress', $ma );
11  }
12 
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 
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 
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 
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 }
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:244
MailAddressTest\testNewFromUser
testNewFromUser()
MailAddress::newFromUser.
Definition: MailAddressTest.php:16
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
MailAddress\newFromUser
static newFromUser(User $user)
Create a new MailAddress object for the given user.
Definition: MailAddress.php:75
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MailAddressTest\testToString
testToString( $useRealName, $address, $name, $realName, $expected)
MailAddress::toString provideToString.
Definition: MailAddressTest.php:43
MailAddressTest\provideToString
static provideToString()
Definition: MailAddressTest.php:52
MailAddress
Stores a single person's name and email address.
Definition: MailAddress.php:32
MailAddressTest\testConstructor
testConstructor()
MailAddress::__construct.
Definition: MailAddressTest.php:8
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:672
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
string
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition: hooks.txt:175
any
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition: COPYING.txt:326
wfIsWindows
wfIsWindows()
Check if the operating system is Windows.
Definition: GlobalFunctions.php:2079
MailAddressTest\test__ToString
test__ToString()
MailAddress::__toString.
Definition: MailAddressTest.php:68
MailAddressTest
Definition: MailAddressTest.php:3