Merge "Genderize Special:Preferences"
[lhc/web/wiklou.git] / tests / phpunit / includes / PreferencesTest.php
1 <?php
2
3 /**
4 * @group Database
5 */
6 class PreferencesTest extends MediaWikiTestCase {
7 /** Array of User objects */
8 private $prefUsers;
9 private $context;
10
11 function __construct() {
12 parent::__construct();
13
14 $this->prefUsers['noemail'] = new User;
15
16 $this->prefUsers['notauth'] = new User;
17 $this->prefUsers['notauth']
18 ->setEmail( 'noauth@example.org' );
19
20 $this->prefUsers['auth'] = new User;
21 $this->prefUsers['auth']
22 ->setEmail( 'noauth@example.org' );
23 $this->prefUsers['auth']
24 ->setEmailAuthenticationTimestamp( 1330946623 );
25
26 $this->context = new RequestContext;
27 $this->context->setTitle( Title::newFromText('PreferencesTest') );
28 }
29
30 protected function setUp() {
31 parent::setUp();
32
33 $this->setMwGlobals( 'wgEnableEmail', true );
34 }
35
36 /**
37 * Placeholder to verify bug 34302
38 * @covers Preferences::profilePreferences
39 */
40 function testEmailFieldsWhenUserHasNoEmail() {
41 $prefs = $this->prefsFor( 'noemail' );
42 $this->assertArrayHasKey( 'cssclass',
43 $prefs['emailaddress']
44 );
45 $this->assertEquals( 'mw-email-none', $prefs['emailaddress']['cssclass'] );
46 }
47 /**
48 * Placeholder to verify bug 34302
49 * @covers Preferences::profilePreferences
50 */
51 function testEmailFieldsWhenUserEmailNotAuthenticated() {
52 $prefs = $this->prefsFor( 'notauth' );
53 $this->assertArrayHasKey( 'cssclass',
54 $prefs['emailaddress']
55 );
56 $this->assertEquals( 'mw-email-not-authenticated', $prefs['emailaddress']['cssclass'] );
57 }
58 /**
59 * Placeholder to verify bug 34302
60 * @covers Preferences::profilePreferences
61 */
62 function testEmailFieldsWhenUserEmailIsAuthenticated() {
63 $prefs = $this->prefsFor( 'auth' );
64 $this->assertArrayHasKey( 'cssclass',
65 $prefs['emailaddress']
66 );
67 $this->assertEquals( 'mw-email-authenticated', $prefs['emailaddress']['cssclass'] );
68 }
69
70 /** Helper */
71 function prefsFor( $user_key ) {
72 $preferences = array();
73 Preferences::profilePreferences(
74 $this->prefUsers[$user_key]
75 , $this->context
76 , $preferences
77 );
78 return $preferences;
79 }
80 }