7 class SpecialMuteTest
extends SpecialPageTestBase
{
9 protected function setUp() {
12 $this->setMwGlobals( [
13 'wgEnableUserEmailBlacklist' => true
20 protected function newSpecialPage() {
21 return new SpecialMute();
25 * @covers SpecialMute::execute
26 * @expectedExceptionMessage username requested could not be found
27 * @expectedException ErrorPageError
29 public function testInvalidTarget() {
30 $user = $this->getTestUser()->getUser();
31 $this->executeSpecialPage(
32 'InvalidUser', null, 'qqx', $user
37 * @covers SpecialMute::execute
38 * @expectedExceptionMessage Mute features are unavailable
39 * @expectedException ErrorPageError
41 public function testEmailBlacklistNotEnabled() {
42 $this->setTemporaryHook(
43 'SpecialMuteModifyFormFields',
47 $this->setMwGlobals( [
48 'wgEnableUserEmailBlacklist' => false
51 $user = $this->getTestUser()->getUser();
52 $this->executeSpecialPage(
53 $user->getName(), null, 'qqx', $user
58 * @covers SpecialMute::execute
59 * @expectedException UserNotLoggedIn
61 public function testUserNotLoggedIn() {
62 $this->executeSpecialPage( 'TestUser' );
66 * @covers SpecialMute::execute
68 public function testMuteAddsUserToEmailBlacklist() {
69 $this->setMwGlobals( [
70 'wgCentralIdLookupProvider' => 'local',
73 $targetUser = $this->getTestUser()->getUser();
75 $loggedInUser = $this->getMutableTestUser()->getUser();
76 $loggedInUser->setOption( 'email-blacklist', "999" );
77 $loggedInUser->confirmEmail();
78 $loggedInUser->saveSettings();
80 $fauxRequest = new FauxRequest( [ 'wpemail-blacklist' => true ], true );
81 list( $html, ) = $this->executeSpecialPage(
82 $targetUser->getName(), $fauxRequest, 'qqx', $loggedInUser
85 $this->assertContains( 'specialmute-success', $html );
87 "999\n" . $targetUser->getId(),
88 $loggedInUser->getOption( 'email-blacklist' )
93 * @covers SpecialMute::execute
95 public function testUnmuteRemovesUserFromEmailBlacklist() {
96 $this->setMwGlobals( [
97 'wgCentralIdLookupProvider' => 'local',
100 $targetUser = $this->getTestUser()->getUser();
102 $loggedInUser = $this->getMutableTestUser()->getUser();
103 $loggedInUser->setOption( 'email-blacklist', "999\n" . $targetUser->getId() );
104 $loggedInUser->confirmEmail();
105 $loggedInUser->saveSettings();
107 $fauxRequest = new FauxRequest( [ 'wpemail-blacklist' => false ], true );
108 list( $html, ) = $this->executeSpecialPage(
109 $targetUser->getName(), $fauxRequest, 'qqx', $loggedInUser
112 $this->assertContains( 'specialmute-success', $html );
113 $this->assertEquals( "999", $loggedInUser->getOption( 'email-blacklist' ) );