Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / tests / phpunit / includes / specials / SpecialMuteTest.php
1 <?php
2
3 /**
4 * @group SpecialPage
5 * @covers SpecialMute
6 */
7 class SpecialMuteTest extends SpecialPageTestBase {
8
9 protected function setUp() {
10 parent::setUp();
11
12 $this->setMwGlobals( [
13 'wgEnableUserEmailBlacklist' => true
14 ] );
15 }
16
17 /**
18 * @inheritDoc
19 */
20 protected function newSpecialPage() {
21 return new SpecialMute();
22 }
23
24 /**
25 * @covers SpecialMute::execute
26 * @expectedExceptionMessage username requested could not be found
27 * @expectedException ErrorPageError
28 */
29 public function testInvalidTarget() {
30 $user = $this->getTestUser()->getUser();
31 $this->executeSpecialPage(
32 'InvalidUser', null, 'qqx', $user
33 );
34 }
35
36 /**
37 * @covers SpecialMute::execute
38 * @expectedExceptionMessage Muting users from sending you emails is not enabled
39 * @expectedException ErrorPageError
40 */
41 public function testEmailBlacklistNotEnabled() {
42 $this->setMwGlobals( [
43 'wgEnableUserEmailBlacklist' => false
44 ] );
45
46 $user = $this->getTestUser()->getUser();
47 $this->executeSpecialPage(
48 $user->getName(), null, 'qqx', $user
49 );
50 }
51
52 /**
53 * @covers SpecialMute::execute
54 * @expectedException UserNotLoggedIn
55 */
56 public function testUserNotLoggedIn() {
57 $this->executeSpecialPage( 'TestUser' );
58 }
59
60 /**
61 * @covers SpecialMute::execute
62 */
63 public function testMuteAddsUserToEmailBlacklist() {
64 $this->setMwGlobals( [
65 'wgCentralIdLookupProvider' => 'local',
66 ] );
67
68 $targetUser = $this->getTestUser()->getUser();
69
70 $loggedInUser = $this->getMutableTestUser()->getUser();
71 $loggedInUser->setOption( 'email-blacklist', "999" );
72 $loggedInUser->confirmEmail();
73 $loggedInUser->saveSettings();
74
75 $fauxRequest = new FauxRequest( [ 'wpMuteEmail' => 1 ], true );
76 list( $html, ) = $this->executeSpecialPage(
77 $targetUser->getName(), $fauxRequest, 'qqx', $loggedInUser
78 );
79
80 $this->assertContains( 'specialmute-success', $html );
81 $this->assertEquals(
82 "999\n" . $targetUser->getId(),
83 $loggedInUser->getOption( 'email-blacklist' )
84 );
85 }
86
87 /**
88 * @covers SpecialMute::execute
89 */
90 public function testUnmuteRemovesUserFromEmailBlacklist() {
91 $this->setMwGlobals( [
92 'wgCentralIdLookupProvider' => 'local',
93 ] );
94
95 $targetUser = $this->getTestUser()->getUser();
96
97 $loggedInUser = $this->getMutableTestUser()->getUser();
98 $loggedInUser->setOption( 'email-blacklist', "999\n" . $targetUser->getId() );
99 $loggedInUser->confirmEmail();
100 $loggedInUser->saveSettings();
101
102 $fauxRequest = new FauxRequest( [ 'wpMuteEmail' => false ], true );
103 list( $html, ) = $this->executeSpecialPage(
104 $targetUser->getName(), $fauxRequest, 'qqx', $loggedInUser
105 );
106
107 $this->assertContains( 'specialmute-success', $html );
108 $this->assertEquals( "999", $loggedInUser->getOption( 'email-blacklist' ) );
109 }
110 }