Merge "Allow callers to load user objects from slaves if desired"
[mediawiki.git] / tests / phpunit / includes / PreferencesTest.php
blob5841bb6f07ff51b28c7bb5cf7e1902fc45d1799a
1 <?php
3 /**
4 * @group Database
5 */
6 class PreferencesTest extends MediaWikiTestCase {
7 /**
8 * @var User[]
9 */
10 private $prefUsers;
11 /**
12 * @var RequestContext
14 private $context;
16 public function __construct() {
17 parent::__construct();
19 $this->prefUsers['noemail'] = new User;
21 $this->prefUsers['notauth'] = new User;
22 $this->prefUsers['notauth']
23 ->setEmail( 'noauth@example.org' );
25 $this->prefUsers['auth'] = new User;
26 $this->prefUsers['auth']
27 ->setEmail( 'noauth@example.org' );
28 $this->prefUsers['auth']
29 ->setEmailAuthenticationTimestamp( 1330946623 );
31 $this->context = new RequestContext;
32 $this->context->setTitle( Title::newFromText( 'PreferencesTest' ) );
35 protected function setUp() {
36 parent::setUp();
38 $this->setMwGlobals( array(
39 'wgEnableEmail' => true,
40 'wgEmailAuthentication' => true,
41 ) );
44 /**
45 * Placeholder to verify bug 34302
46 * @covers Preferences::profilePreferences
48 public function testEmailFieldsWhenUserHasNoEmail() {
49 $prefs = $this->prefsFor( 'noemail' );
50 $this->assertArrayHasKey( 'cssclass',
51 $prefs['emailaddress']
53 $this->assertEquals( 'mw-email-none', $prefs['emailaddress']['cssclass'] );
56 /**
57 * Placeholder to verify bug 34302
58 * @covers Preferences::profilePreferences
60 public function testEmailFieldsWhenUserEmailNotAuthenticated() {
61 $prefs = $this->prefsFor( 'notauth' );
62 $this->assertArrayHasKey( 'cssclass',
63 $prefs['emailaddress']
65 $this->assertEquals( 'mw-email-not-authenticated', $prefs['emailaddress']['cssclass'] );
68 /**
69 * Placeholder to verify bug 34302
70 * @covers Preferences::profilePreferences
72 public function testEmailFieldsWhenUserEmailIsAuthenticated() {
73 $prefs = $this->prefsFor( 'auth' );
74 $this->assertArrayHasKey( 'cssclass',
75 $prefs['emailaddress']
77 $this->assertEquals( 'mw-email-authenticated', $prefs['emailaddress']['cssclass'] );
80 /** Helper */
81 protected function prefsFor( $user_key ) {
82 $preferences = array();
83 Preferences::profilePreferences(
84 $this->prefUsers[$user_key],
85 $this->context,
86 $preferences
89 return $preferences;