Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / cache / GenderCacheTest.php
blob04fb00d98a613c98015afd53cf34b94b1e6d953e
1 <?php
3 /**
4 * @group Database
5 * @group Cache
6 */
7 class GenderCacheTest extends MediaWikiLangTestCase {
9 function addDBData() {
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();
41 /**
42 * test usernames
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" );
53 /**
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() {
67 return array(
68 array( 'UTMale', 'male' ),
69 array( 'UTFemale', 'female' ),
70 array( 'UTDefaultGender', 'unknown' ),
71 array( 'UTNotExist', 'unknown' ),
72 //some not valid user
73 array( '127.0.0.1', 'unknown' ),
74 array( 'user@test', 'unknown' ),
78 /**
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() {
92 return array(
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' ),