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