PreferencesTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @group Database
  4. */
  5. class PreferencesTest extends MediaWikiTestCase {
  6. /**
  7. * @var User[]
  8. */
  9. private $prefUsers;
  10. /**
  11. * @var RequestContext
  12. */
  13. private $context;
  14. public function __construct() {
  15. parent::__construct();
  16. $this->prefUsers['noemail'] = new User;
  17. $this->prefUsers['notauth'] = new User;
  18. $this->prefUsers['notauth']
  19. ->setEmail( 'noauth@example.org' );
  20. $this->prefUsers['auth'] = new User;
  21. $this->prefUsers['auth']
  22. ->setEmail( 'noauth@example.org' );
  23. $this->prefUsers['auth']
  24. ->setEmailAuthenticationTimestamp( 1330946623 );
  25. $this->context = new RequestContext;
  26. $this->context->setTitle( Title::newFromText( 'PreferencesTest' ) );
  27. }
  28. protected function setUp() {
  29. parent::setUp();
  30. $this->setMwGlobals( [
  31. 'wgEnableEmail' => true,
  32. 'wgEmailAuthentication' => true,
  33. ] );
  34. }
  35. /**
  36. * Placeholder to verify T36302
  37. * @covers Preferences::profilePreferences
  38. * @deprecated replaced by DefaultPreferencesFactoryTest::testEmailAuthentication()
  39. */
  40. public function testEmailAuthenticationFieldWhenUserHasNoEmail() {
  41. $prefs = $this->prefsFor( 'noemail' );
  42. $this->assertArrayHasKey( 'cssclass',
  43. $prefs['emailauthentication']
  44. );
  45. $this->assertEquals( 'mw-email-none', $prefs['emailauthentication']['cssclass'] );
  46. }
  47. /**
  48. * Placeholder to verify T36302
  49. * @covers Preferences::profilePreferences
  50. * @deprecated replaced by DefaultPreferencesFactoryTest::testEmailAuthentication()
  51. */
  52. public function testEmailAuthenticationFieldWhenUserEmailNotAuthenticated() {
  53. $prefs = $this->prefsFor( 'notauth' );
  54. $this->assertArrayHasKey( 'cssclass',
  55. $prefs['emailauthentication']
  56. );
  57. $this->assertEquals( 'mw-email-not-authenticated', $prefs['emailauthentication']['cssclass'] );
  58. }
  59. /**
  60. * Placeholder to verify T36302
  61. * @covers Preferences::profilePreferences
  62. * @deprecated replaced by DefaultPreferencesFactoryTest::testEmailAuthentication()
  63. */
  64. public function testEmailAuthenticationFieldWhenUserEmailIsAuthenticated() {
  65. $prefs = $this->prefsFor( 'auth' );
  66. $this->assertArrayHasKey( 'cssclass',
  67. $prefs['emailauthentication']
  68. );
  69. $this->assertEquals( 'mw-email-authenticated', $prefs['emailauthentication']['cssclass'] );
  70. }
  71. /** Helper */
  72. protected function prefsFor( $user_key ) {
  73. return Preferences::getPreferences(
  74. $this->prefUsers[$user_key],
  75. $this->context
  76. );
  77. }
  78. }