7 class GenderCacheTest
extends MediaWikiLangTestCase
{
9 protected function setUp() {
10 global $wgDefaultUserOptions;
12 //ensure the correct default gender
13 $wgDefaultUserOptions['gender'] = 'unknown';
16 function addDBData() {
17 $user = User
::newFromName( 'UTMale' );
18 if ( $user->getID() == 0 ) {
19 $user->addToDatabase();
20 $user->setPassword( 'UTMalePassword' );
22 //ensure the right gender
23 $user->setOption( 'gender', 'male' );
24 $user->saveSettings();
26 $user = User
::newFromName( 'UTFemale' );
27 if ( $user->getID() == 0 ) {
28 $user->addToDatabase();
29 $user->setPassword( 'UTFemalePassword' );
31 //ensure the right gender
32 $user->setOption( 'gender', 'female' );
33 $user->saveSettings();
35 $user = User
::newFromName( 'UTDefaultGender' );
36 if ( $user->getID() == 0 ) {
37 $user->addToDatabase();
38 $user->setPassword( 'UTDefaultGenderPassword' );
40 //ensure the default gender
41 $user->setOption( 'gender', null );
42 $user->saveSettings();
48 * @dataProvider provideUserGenders
50 function testUserName( $username, $expectedGender ) {
51 $genderCache = GenderCache
::singleton();
52 $gender = $genderCache->getGenderOf( $username );
53 $this->assertEquals( $gender, $expectedGender, "GenderCache normal" );
57 * genderCache should work with user objects, too
59 * @dataProvider provideUserGenders
61 function testUserObjects( $username, $expectedGender ) {
62 $genderCache = GenderCache
::singleton();
63 $user = User
::newFromName( $username );
64 $gender = $genderCache->getGenderOf( $user );
65 $this->assertEquals( $gender, $expectedGender, "GenderCache normal" );
68 public static function provideUserGenders() {
70 array( 'UTMale', 'male' ),
71 array( 'UTFemale', 'female' ),
72 array( 'UTDefaultGender', 'unknown' ),
73 array( 'UTNotExist', 'unknown' ),
75 array( '127.0.0.1', 'unknown' ),
76 array( 'user@test', 'unknown' ),
81 * test strip of subpages to avoid unnecessary queries
82 * against the never existing username
84 * @dataProvider provideStripSubpages
86 function testStripSubpages( $pageWithSubpage, $expectedGender ) {
87 $genderCache = GenderCache
::singleton();
88 $gender = $genderCache->getGenderOf( $pageWithSubpage );
89 $this->assertEquals( $gender, $expectedGender, "GenderCache must strip of subpages" );
92 public static function provideStripSubpages() {
94 array( 'UTMale/subpage', 'male' ),
95 array( 'UTFemale/subpage', 'female' ),
96 array( 'UTDefaultGender/subpage', 'unknown' ),
97 array( 'UTNotExist/subpage', 'unknown' ),
98 array( '127.0.0.1/subpage', 'unknown' ),