MediaWiki  1.23.2
GenderCacheTest.php
Go to the documentation of this file.
1 <?php
2 
8 
9  protected function setUp() {
10  global $wgDefaultUserOptions;
11  parent::setUp();
12  //ensure the correct default gender
13  $wgDefaultUserOptions['gender'] = 'unknown';
14  }
15 
16  function addDBData() {
17  $user = User::newFromName( 'UTMale' );
18  if ( $user->getID() == 0 ) {
19  $user->addToDatabase();
20  $user->setPassword( 'UTMalePassword' );
21  }
22  //ensure the right gender
23  $user->setOption( 'gender', 'male' );
24  $user->saveSettings();
25 
26  $user = User::newFromName( 'UTFemale' );
27  if ( $user->getID() == 0 ) {
28  $user->addToDatabase();
29  $user->setPassword( 'UTFemalePassword' );
30  }
31  //ensure the right gender
32  $user->setOption( 'gender', 'female' );
33  $user->saveSettings();
34 
35  $user = User::newFromName( 'UTDefaultGender' );
36  if ( $user->getID() == 0 ) {
37  $user->addToDatabase();
38  $user->setPassword( 'UTDefaultGenderPassword' );
39  }
40  //ensure the default gender
41  $user->setOption( 'gender', null );
42  $user->saveSettings();
43  }
44 
51  public function testUserName( $username, $expectedGender ) {
52  $genderCache = GenderCache::singleton();
53  $gender = $genderCache->getGenderOf( $username );
54  $this->assertEquals( $gender, $expectedGender, "GenderCache normal" );
55  }
56 
63  public function testUserObjects( $username, $expectedGender ) {
64  $genderCache = GenderCache::singleton();
65  $user = User::newFromName( $username );
66  $gender = $genderCache->getGenderOf( $user );
67  $this->assertEquals( $gender, $expectedGender, "GenderCache normal" );
68  }
69 
70  public static function provideUserGenders() {
71  return array(
72  array( 'UTMale', 'male' ),
73  array( 'UTFemale', 'female' ),
74  array( 'UTDefaultGender', 'unknown' ),
75  array( 'UTNotExist', 'unknown' ),
76  //some not valid user
77  array( '127.0.0.1', 'unknown' ),
78  array( 'user@test', 'unknown' ),
79  );
80  }
81 
89  public function testStripSubpages( $pageWithSubpage, $expectedGender ) {
90  $genderCache = GenderCache::singleton();
91  $gender = $genderCache->getGenderOf( $pageWithSubpage );
92  $this->assertEquals( $gender, $expectedGender, "GenderCache must strip of subpages" );
93  }
94 
95  public static function provideStripSubpages() {
96  return array(
97  array( 'UTMale/subpage', 'male' ),
98  array( 'UTFemale/subpage', 'female' ),
99  array( 'UTDefaultGender/subpage', 'unknown' ),
100  array( 'UTNotExist/subpage', 'unknown' ),
101  array( '127.0.0.1/subpage', 'unknown' ),
102  );
103  }
104 }
GenderCache\singleton
static singleton()
Definition: GenderCache.php:39
GenderCacheTest\addDBData
addDBData()
Stub.
Definition: GenderCacheTest.php:16
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
GenderCacheTest\provideStripSubpages
static provideStripSubpages()
Definition: GenderCacheTest.php:95
GenderCacheTest
@group Database @group Cache
Definition: GenderCacheTest.php:7
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:388
GenderCacheTest\setUp
setUp()
Definition: GenderCacheTest.php:9
GenderCacheTest\testUserName
testUserName( $username, $expectedGender)
test usernames
Definition: GenderCacheTest.php:51
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
GenderCacheTest\testStripSubpages
testStripSubpages( $pageWithSubpage, $expectedGender)
test strip of subpages to avoid unnecessary queries against the never existing username
Definition: GenderCacheTest.php:89
GenderCacheTest\provideUserGenders
static provideUserGenders()
Definition: GenderCacheTest.php:70
GenderCacheTest\testUserObjects
testUserObjects( $username, $expectedGender)
genderCache should work with user objects, too
Definition: GenderCacheTest.php:63
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
$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:237