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 Muting users from sending you emails is not enabled
39 * @expectedException ErrorPageError
41 public function testEmailBlacklistNotEnabled() {
42 $this->setMwGlobals( [
43 'wgEnableUserEmailBlacklist' => false
46 $user = $this->getTestUser()->getUser();
47 $this->executeSpecialPage(
48 $user->getName(), null, 'qqx', $user
53 * @covers SpecialMute::execute
54 * @expectedException UserNotLoggedIn
56 public function testUserNotLoggedIn() {
57 $this->executeSpecialPage( 'TestUser' );
61 * @covers SpecialMute::execute
63 public function testMuteAddsUserToEmailBlacklist() {
64 $this->setMwGlobals( [
65 'wgCentralIdLookupProvider' => 'local',
68 $targetUser = $this->getTestUser()->getUser();
70 $loggedInUser = $this->getMutableTestUser()->getUser();
71 $loggedInUser->setOption( 'email-blacklist', "999" );
72 $loggedInUser->confirmEmail();
73 $loggedInUser->saveSettings();
75 $fauxRequest = new FauxRequest( [ 'wpMuteEmail' => 1 ], true );
76 list( $html, ) = $this->executeSpecialPage(
77 $targetUser->getName(), $fauxRequest, 'qqx', $loggedInUser
80 $this->assertContains( 'specialmute-success', $html );
82 "999\n" . $targetUser->getId(),
83 $loggedInUser->getOption( 'email-blacklist' )
88 * @covers SpecialMute::execute
90 public function testUnmuteRemovesUserFromEmailBlacklist() {
91 $this->setMwGlobals( [
92 'wgCentralIdLookupProvider' => 'local',
95 $targetUser = $this->getTestUser()->getUser();
97 $loggedInUser = $this->getMutableTestUser()->getUser();
98 $loggedInUser->setOption( 'email-blacklist', "999\n" . $targetUser->getId() );
99 $loggedInUser->confirmEmail();
100 $loggedInUser->saveSettings();
102 $fauxRequest = new FauxRequest( [ 'wpMuteEmail' => false ], true );
103 list( $html, ) = $this->executeSpecialPage(
104 $targetUser->getName(), $fauxRequest, 'qqx', $loggedInUser
107 $this->assertContains( 'specialmute-success', $html );
108 $this->assertEquals( "999", $loggedInUser->getOption( 'email-blacklist' ) );