2012-03-05 11:48:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
2012-12-09 09:27:56 +00:00
|
|
|
/**
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
2012-03-05 11:48:35 +00:00
|
|
|
class PreferencesTest extends MediaWikiTestCase {
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
|
|
|
|
* @var User[]
|
|
|
|
|
*/
|
2012-09-11 00:07:18 +00:00
|
|
|
private $prefUsers;
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
|
|
|
|
* @var RequestContext
|
|
|
|
|
*/
|
2012-09-11 00:07:18 +00:00
|
|
|
private $context;
|
2012-03-05 11:48:35 +00:00
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
public function __construct() {
|
2012-03-05 11:48:35 +00:00
|
|
|
parent::__construct();
|
|
|
|
|
|
2012-09-11 00:07:18 +00:00
|
|
|
$this->prefUsers['noemail'] = new User;
|
2012-03-05 11:48:35 +00:00
|
|
|
|
2012-09-11 00:07:18 +00:00
|
|
|
$this->prefUsers['notauth'] = new User;
|
|
|
|
|
$this->prefUsers['notauth']
|
2012-03-05 11:48:35 +00:00
|
|
|
->setEmail( 'noauth@example.org' );
|
|
|
|
|
|
2013-02-14 11:22:13 +00:00
|
|
|
$this->prefUsers['auth'] = new User;
|
2012-09-11 00:07:18 +00:00
|
|
|
$this->prefUsers['auth']
|
2012-03-05 11:48:35 +00:00
|
|
|
->setEmail( 'noauth@example.org' );
|
2012-09-11 00:07:18 +00:00
|
|
|
$this->prefUsers['auth']
|
2012-03-05 11:48:35 +00:00
|
|
|
->setEmailAuthenticationTimestamp( 1330946623 );
|
|
|
|
|
|
|
|
|
|
$this->context = new RequestContext;
|
2013-02-14 11:22:13 +00:00
|
|
|
$this->context->setTitle( Title::newFromText( 'PreferencesTest' ) );
|
2012-10-08 10:56:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
2012-04-30 07:29:45 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setMwGlobals( [
|
2013-05-11 20:14:18 +00:00
|
|
|
'wgEnableEmail' => true,
|
|
|
|
|
'wgEmailAuthentication' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2012-03-05 11:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-03-05 11:50:30 +00:00
|
|
|
* Placeholder to verify bug 34302
|
2012-03-05 11:48:35 +00:00
|
|
|
* @covers Preferences::profilePreferences
|
|
|
|
|
*/
|
2015-12-13 00:56:47 +00:00
|
|
|
public function testEmailAuthenticationFieldWhenUserHasNoEmail() {
|
2012-03-05 11:48:35 +00:00
|
|
|
$prefs = $this->prefsFor( 'noemail' );
|
2012-03-07 09:56:24 +00:00
|
|
|
$this->assertArrayHasKey( 'cssclass',
|
2015-12-13 00:56:47 +00:00
|
|
|
$prefs['emailauthentication']
|
2012-03-05 11:48:35 +00:00
|
|
|
);
|
2015-12-13 00:56:47 +00:00
|
|
|
$this->assertEquals( 'mw-email-none', $prefs['emailauthentication']['cssclass'] );
|
2012-03-05 11:48:35 +00:00
|
|
|
}
|
2013-02-14 11:22:13 +00:00
|
|
|
|
2012-03-05 11:48:35 +00:00
|
|
|
/**
|
2012-03-05 11:50:30 +00:00
|
|
|
* Placeholder to verify bug 34302
|
2012-03-05 11:48:35 +00:00
|
|
|
* @covers Preferences::profilePreferences
|
|
|
|
|
*/
|
2015-12-13 00:56:47 +00:00
|
|
|
public function testEmailAuthenticationFieldWhenUserEmailNotAuthenticated() {
|
2012-03-05 11:48:35 +00:00
|
|
|
$prefs = $this->prefsFor( 'notauth' );
|
2012-03-07 09:56:24 +00:00
|
|
|
$this->assertArrayHasKey( 'cssclass',
|
2015-12-13 00:56:47 +00:00
|
|
|
$prefs['emailauthentication']
|
2012-03-05 11:48:35 +00:00
|
|
|
);
|
2015-12-13 00:56:47 +00:00
|
|
|
$this->assertEquals( 'mw-email-not-authenticated', $prefs['emailauthentication']['cssclass'] );
|
2012-03-05 11:48:35 +00:00
|
|
|
}
|
2013-02-14 11:22:13 +00:00
|
|
|
|
2012-03-05 11:48:35 +00:00
|
|
|
/**
|
2012-03-05 11:50:30 +00:00
|
|
|
* Placeholder to verify bug 34302
|
2012-03-05 11:48:35 +00:00
|
|
|
* @covers Preferences::profilePreferences
|
|
|
|
|
*/
|
2015-12-13 00:56:47 +00:00
|
|
|
public function testEmailAuthenticationFieldWhenUserEmailIsAuthenticated() {
|
2012-03-05 11:48:35 +00:00
|
|
|
$prefs = $this->prefsFor( 'auth' );
|
2012-03-07 09:56:24 +00:00
|
|
|
$this->assertArrayHasKey( 'cssclass',
|
2015-12-13 00:56:47 +00:00
|
|
|
$prefs['emailauthentication']
|
2012-03-05 11:48:35 +00:00
|
|
|
);
|
2015-12-13 00:56:47 +00:00
|
|
|
$this->assertEquals( 'mw-email-authenticated', $prefs['emailauthentication']['cssclass'] );
|
2012-03-05 11:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Helper */
|
2013-10-21 21:09:13 +00:00
|
|
|
protected function prefsFor( $user_key ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$preferences = [];
|
2012-03-05 11:48:35 +00:00
|
|
|
Preferences::profilePreferences(
|
2013-12-01 19:58:51 +00:00
|
|
|
$this->prefUsers[$user_key],
|
|
|
|
|
$this->context,
|
|
|
|
|
$preferences
|
2012-03-05 11:48:35 +00:00
|
|
|
);
|
2013-04-26 12:00:22 +00:00
|
|
|
|
2012-03-05 11:48:35 +00:00
|
|
|
return $preferences;
|
|
|
|
|
}
|
|
|
|
|
}
|