MediaWiki  REL1_22
GenderCacheTest.php
Go to the documentation of this file.
00001 <?php
00002 
00007 class GenderCacheTest extends MediaWikiLangTestCase {
00008 
00009     protected function setUp() {
00010         global $wgDefaultUserOptions;
00011         parent::setUp();
00012         //ensure the correct default gender
00013         $wgDefaultUserOptions['gender'] = 'unknown';
00014     }
00015 
00016     function addDBData() {
00017         $user = User::newFromName( 'UTMale' );
00018         if ( $user->getID() == 0 ) {
00019             $user->addToDatabase();
00020             $user->setPassword( 'UTMalePassword' );
00021         }
00022         //ensure the right gender
00023         $user->setOption( 'gender', 'male' );
00024         $user->saveSettings();
00025 
00026         $user = User::newFromName( 'UTFemale' );
00027         if ( $user->getID() == 0 ) {
00028             $user->addToDatabase();
00029             $user->setPassword( 'UTFemalePassword' );
00030         }
00031         //ensure the right gender
00032         $user->setOption( 'gender', 'female' );
00033         $user->saveSettings();
00034 
00035         $user = User::newFromName( 'UTDefaultGender' );
00036         if ( $user->getID() == 0 ) {
00037             $user->addToDatabase();
00038             $user->setPassword( 'UTDefaultGenderPassword' );
00039         }
00040         //ensure the default gender
00041         $user->setOption( 'gender', null );
00042         $user->saveSettings();
00043     }
00044 
00051     public function testUserName( $username, $expectedGender ) {
00052         $genderCache = GenderCache::singleton();
00053         $gender = $genderCache->getGenderOf( $username );
00054         $this->assertEquals( $gender, $expectedGender, "GenderCache normal" );
00055     }
00056 
00063     public function testUserObjects( $username, $expectedGender ) {
00064         $genderCache = GenderCache::singleton();
00065         $user = User::newFromName( $username );
00066         $gender = $genderCache->getGenderOf( $user );
00067         $this->assertEquals( $gender, $expectedGender, "GenderCache normal" );
00068     }
00069 
00070     public static function provideUserGenders() {
00071         return array(
00072             array( 'UTMale', 'male' ),
00073             array( 'UTFemale', 'female' ),
00074             array( 'UTDefaultGender', 'unknown' ),
00075             array( 'UTNotExist', 'unknown' ),
00076             //some not valid user
00077             array( '127.0.0.1', 'unknown' ),
00078             array( 'user@test', 'unknown' ),
00079         );
00080     }
00081 
00089     public function testStripSubpages( $pageWithSubpage, $expectedGender ) {
00090         $genderCache = GenderCache::singleton();
00091         $gender = $genderCache->getGenderOf( $pageWithSubpage );
00092         $this->assertEquals( $gender, $expectedGender, "GenderCache must strip of subpages" );
00093     }
00094 
00095     public static function provideStripSubpages() {
00096         return array(
00097             array( 'UTMale/subpage', 'male' ),
00098             array( 'UTFemale/subpage', 'female' ),
00099             array( 'UTDefaultGender/subpage', 'unknown' ),
00100             array( 'UTNotExist/subpage', 'unknown' ),
00101             array( '127.0.0.1/subpage', 'unknown' ),
00102         );
00103     }
00104 }