MediaWiki  REL1_22
PreferencesTest.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class PreferencesTest extends MediaWikiTestCase {
00010     private $prefUsers;
00014     private $context;
00015 
00016     public function __construct() {
00017         parent::__construct();
00018 
00019         $this->prefUsers['noemail'] = new User;
00020 
00021         $this->prefUsers['notauth'] = new User;
00022         $this->prefUsers['notauth']
00023             ->setEmail( '[email protected]' );
00024 
00025         $this->prefUsers['auth'] = new User;
00026         $this->prefUsers['auth']
00027             ->setEmail( '[email protected]' );
00028         $this->prefUsers['auth']
00029             ->setEmailAuthenticationTimestamp( 1330946623 );
00030 
00031         $this->context = new RequestContext;
00032         $this->context->setTitle( Title::newFromText( 'PreferencesTest' ) );
00033     }
00034 
00035     protected function setUp() {
00036         parent::setUp();
00037 
00038         $this->setMwGlobals( array(
00039             'wgEnableEmail' => true,
00040             'wgEmailAuthentication' => true,
00041         ) );
00042     }
00043 
00048     public function testEmailFieldsWhenUserHasNoEmail() {
00049         $prefs = $this->prefsFor( 'noemail' );
00050         $this->assertArrayHasKey( 'cssclass',
00051             $prefs['emailaddress']
00052         );
00053         $this->assertEquals( 'mw-email-none', $prefs['emailaddress']['cssclass'] );
00054     }
00055 
00060     public function testEmailFieldsWhenUserEmailNotAuthenticated() {
00061         $prefs = $this->prefsFor( 'notauth' );
00062         $this->assertArrayHasKey( 'cssclass',
00063             $prefs['emailaddress']
00064         );
00065         $this->assertEquals( 'mw-email-not-authenticated', $prefs['emailaddress']['cssclass'] );
00066     }
00067 
00072     public function testEmailFieldsWhenUserEmailIsAuthenticated() {
00073         $prefs = $this->prefsFor( 'auth' );
00074         $this->assertArrayHasKey( 'cssclass',
00075             $prefs['emailaddress']
00076         );
00077         $this->assertEquals( 'mw-email-authenticated', $prefs['emailaddress']['cssclass'] );
00078     }
00079 
00081     protected function prefsFor( $user_key ) {
00082         $preferences = array();
00083         Preferences::profilePreferences(
00084             $this->prefUsers[$user_key]
00085             , $this->context
00086             , $preferences
00087         );
00088 
00089         return $preferences;
00090     }
00091 }