Update code formatting
[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 /**
49 * Placeholder to verify bug 34302
50 * @covers Preferences::profilePreferences
51 */
52 function testEmailFieldsWhenUserEmailNotAuthenticated() {
53 $prefs = $this->prefsFor( 'notauth' );
54 $this->assertArrayHasKey( 'cssclass',
55 $prefs['emailaddress']
56 );
57 $this->assertEquals( 'mw-email-not-authenticated', $prefs['emailaddress']['cssclass'] );
58 }
59
60 /**
61 * Placeholder to verify bug 34302
62 * @covers Preferences::profilePreferences
63 */
64 function testEmailFieldsWhenUserEmailIsAuthenticated() {
65 $prefs = $this->prefsFor( 'auth' );
66 $this->assertArrayHasKey( 'cssclass',
67 $prefs['emailaddress']
68 );
69 $this->assertEquals( 'mw-email-authenticated', $prefs['emailaddress']['cssclass'] );
70 }
71
72 /** Helper */
73 function prefsFor( $user_key ) {
74 $preferences = array();
75 Preferences::profilePreferences(
76 $this->prefUsers[$user_key]
77 , $this->context
78 , $preferences
79 );
80
81 return $preferences;
82 }
83 }