7 class GenderCacheTest
extends MediaWikiLangTestCase
{
10 //ensure the correct default gender
11 $this->mergeMwGlobalArrayValue( 'wgDefaultUserOptions', array( 'gender' => 'unknown' ) );
13 $user = User
::newFromName( 'UTMale' );
14 if ( $user->getID() == 0 ) {
15 $user->addToDatabase();
16 $user->setPassword( 'UTMalePassword' );
18 //ensure the right gender
19 $user->setOption( 'gender', 'male' );
20 $user->saveSettings();
22 $user = User
::newFromName( 'UTFemale' );
23 if ( $user->getID() == 0 ) {
24 $user->addToDatabase();
25 $user->setPassword( 'UTFemalePassword' );
27 //ensure the right gender
28 $user->setOption( 'gender', 'female' );
29 $user->saveSettings();
31 $user = User
::newFromName( 'UTDefaultGender' );
32 if ( $user->getID() == 0 ) {
33 $user->addToDatabase();
34 $user->setPassword( 'UTDefaultGenderPassword' );
36 //ensure the default gender
37 $user->setOption( 'gender', null );
38 $user->saveSettings();
44 * @dataProvider provideUserGenders
45 * @covers GenderCache::getGenderOf
47 public function testUserName( $username, $expectedGender ) {
48 $genderCache = GenderCache
::singleton();
49 $gender = $genderCache->getGenderOf( $username );
50 $this->assertEquals( $gender, $expectedGender, "GenderCache normal" );
54 * genderCache should work with user objects, too
56 * @dataProvider provideUserGenders
57 * @covers GenderCache::getGenderOf
59 public function testUserObjects( $username, $expectedGender ) {
60 $genderCache = GenderCache
::singleton();
61 $user = User
::newFromName( $username );
62 $gender = $genderCache->getGenderOf( $user );
63 $this->assertEquals( $gender, $expectedGender, "GenderCache normal" );
66 public static function provideUserGenders() {
68 array( 'UTMale', 'male' ),
69 array( 'UTFemale', 'female' ),
70 array( 'UTDefaultGender', 'unknown' ),
71 array( 'UTNotExist', 'unknown' ),
73 array( '127.0.0.1', 'unknown' ),
74 array( 'user@test', 'unknown' ),
79 * test strip of subpages to avoid unnecessary queries
80 * against the never existing username
82 * @dataProvider provideStripSubpages
83 * @covers GenderCache::getGenderOf
85 public function testStripSubpages( $pageWithSubpage, $expectedGender ) {
86 $genderCache = GenderCache
::singleton();
87 $gender = $genderCache->getGenderOf( $pageWithSubpage );
88 $this->assertEquals( $gender, $expectedGender, "GenderCache must strip of subpages" );
91 public static function provideStripSubpages() {
93 array( 'UTMale/subpage', 'male' ),
94 array( 'UTFemale/subpage', 'female' ),
95 array( 'UTDefaultGender/subpage', 'unknown' ),
96 array( 'UTNotExist/subpage', 'unknown' ),
97 array( '127.0.0.1/subpage', 'unknown' ),