MediaWiki  1.29.1
PreferencesTest.php
Go to the documentation of this file.
1 <?php
2 
10  private $prefUsers;
14  private $context;
15 
16  public function __construct() {
17  parent::__construct();
18 
19  $this->prefUsers['noemail'] = new User;
20 
21  $this->prefUsers['notauth'] = new User;
22  $this->prefUsers['notauth']
23  ->setEmail( 'noauth@example.org' );
24 
25  $this->prefUsers['auth'] = new User;
26  $this->prefUsers['auth']
27  ->setEmail( 'noauth@example.org' );
28  $this->prefUsers['auth']
29  ->setEmailAuthenticationTimestamp( 1330946623 );
30 
31  $this->context = new RequestContext;
32  $this->context->setTitle( Title::newFromText( 'PreferencesTest' ) );
33  }
34 
35  protected function setUp() {
36  parent::setUp();
37 
38  $this->setMwGlobals( [
39  'wgEnableEmail' => true,
40  'wgEmailAuthentication' => true,
41  ] );
42  }
43 
49  $prefs = $this->prefsFor( 'noemail' );
50  $this->assertArrayHasKey( 'cssclass',
51  $prefs['emailauthentication']
52  );
53  $this->assertEquals( 'mw-email-none', $prefs['emailauthentication']['cssclass'] );
54  }
55 
61  $prefs = $this->prefsFor( 'notauth' );
62  $this->assertArrayHasKey( 'cssclass',
63  $prefs['emailauthentication']
64  );
65  $this->assertEquals( 'mw-email-not-authenticated', $prefs['emailauthentication']['cssclass'] );
66  }
67 
73  $prefs = $this->prefsFor( 'auth' );
74  $this->assertArrayHasKey( 'cssclass',
75  $prefs['emailauthentication']
76  );
77  $this->assertEquals( 'mw-email-authenticated', $prefs['emailauthentication']['cssclass'] );
78  }
79 
81  protected function prefsFor( $user_key ) {
82  $preferences = [];
84  $this->prefUsers[$user_key],
85  $this->context,
86  $preferences
87  );
88 
89  return $preferences;
90  }
91 }
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:265
PreferencesTest\setUp
setUp()
Definition: PreferencesTest.php:35
PreferencesTest\$prefUsers
User[] $prefUsers
Definition: PreferencesTest.php:10
PreferencesTest
Database.
Definition: PreferencesTest.php:6
PreferencesTest\testEmailAuthenticationFieldWhenUserHasNoEmail
testEmailAuthenticationFieldWhenUserHasNoEmail()
Placeholder to verify T36302 Preferences::profilePreferences.
Definition: PreferencesTest.php:48
PreferencesTest\testEmailAuthenticationFieldWhenUserEmailIsAuthenticated
testEmailAuthenticationFieldWhenUserEmailIsAuthenticated()
Placeholder to verify T36302 Preferences::profilePreferences.
Definition: PreferencesTest.php:72
User
User
Definition: All_system_messages.txt:425
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
PreferencesTest\testEmailAuthenticationFieldWhenUserEmailNotAuthenticated
testEmailAuthenticationFieldWhenUserEmailNotAuthenticated()
Placeholder to verify T36302 Preferences::profilePreferences.
Definition: PreferencesTest.php:60
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:658
MediaWikiTestCase
Definition: MediaWikiTestCase.php:13
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:33
PreferencesTest\__construct
__construct()
Definition: PreferencesTest.php:16
PreferencesTest\prefsFor
prefsFor( $user_key)
Helper.
Definition: PreferencesTest.php:81
Preferences\profilePreferences
static profilePreferences( $user, IContextSource $context, &$defaultPreferences)
Definition: Preferences.php:208
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:50
RequestContext\setTitle
setTitle(Title $title=null)
Set the Title object.
Definition: RequestContext.php:166
PreferencesTest\$context
RequestContext $context
Definition: PreferencesTest.php:14