24 $this->testWikiPage =
new WikiPage( $testTitle );
26 $testContext->setTitle( $testTitle );
27 $this->watchAction =
new WatchAction( $this->testWikiPage, $testContext );
44 $this->assertEquals(
'watch', $this->watchAction->getName() );
51 $this->assertFalse( $this->watchAction->requiresUnblock() );
58 $this->assertTrue( $this->watchAction->doesWrites() );
67 $actual = $this->watchAction->onSubmit( [] );
69 $this->assertTrue( $actual->isGood() );
82 $actual = $this->watchAction->onSubmit( [] );
85 $this->assertTrue( $actual->hasMessage(
'hookaborted' ) );
92 $notLoggedInUser =
new User();
94 $testContext->
setUser( $notLoggedInUser );
106 $loggedInUser->method(
'isLoggedIn' )->willReturn(
true );
108 $testContext->
setUser( $loggedInUser );
117 $this->assertNull( $exception,
118 'UserNotLoggedIn exception should not be thrown if user is logged in.' );
125 $testContext = $this->getMock(
128 [ $this->watchAction->getContext() ]
130 $testOutput =
new OutputPage( $testContext );
131 $testContext->setOutput( $testOutput );
132 $testContext->method(
'msg' )->willReturnCallback(
function ( $msgKey ) {
139 $this->assertEquals(
'<p>addedwatchtext
140 </p>', $testOutput->getHTML() );
147 $testContext = $this->getMock(
150 [ $this->watchAction->getContext() ]
152 $testOutput =
new OutputPage( $testContext );
153 $testContext->method(
'getOutput' )->willReturn( $testOutput );
154 $testContext->method(
'msg' )->willReturnCallback(
function ( $msgKey ) {
158 $testContext->setTitle( $talkPageTitle );
163 $this->assertEquals(
'<p>addedwatchtext-talk
164 </p>', $testOutput->getHTML() );
172 $notPermittedUser->method(
'isAllowed' )->willReturn(
false );
176 $this->assertTrue( $actual->isGood() );
184 $notPermittedUser->method(
'isAllowed' )->willReturn(
false );
188 $this->assertFalse( $actual->isGood() );
196 $permittedUser->method(
'isAllowed' )->willReturn(
true );
197 $permittedUser->expects( $this->once() )
198 ->method(
'addWatch' )
199 ->with( $this->equalTo( $this->testWikiPage->getTitle() ), $this->equalTo(
true ) );
203 $this->assertTrue( $actual->isGood() );
211 $notPermittedUser->method(
'isAllowed' )->willReturn(
false );
213 $actual = WatchAction::doUnWatch( $this->testWikiPage->getTitle(), $notPermittedUser );
215 $this->assertFalse( $actual->isGood() );
223 $permittedUser->method(
'isAllowed' )->willReturn(
true );
228 $status = WatchAction::doUnWatch( $this->testWikiPage->getTitle(), $permittedUser );
230 $this->assertFalse(
$status->isGood() );
231 $errors =
$status->getErrors();
232 $this->assertEquals( 1,
count( $errors ) );
233 $this->assertEquals(
'hookaborted', $errors[0][
'message'] );
241 $permittedUser->method(
'isAllowed' )->willReturn(
true );
242 $permittedUser->expects( $this->once() )
243 ->method(
'removeWatch' )
244 ->with( $this->equalTo( $this->testWikiPage->getTitle() ) );
246 $actual = WatchAction::doUnWatch( $this->testWikiPage->getTitle(), $permittedUser );
248 $this->assertTrue( $actual->isGood() );
256 $user->expects( $this->once() )
257 ->method(
'getEditToken' )
258 ->with( $this->equalTo(
'watch' ) );
268 $user->expects( $this->once() )->method(
'getEditToken' );
278 $user->expects( $this->once() )->method(
'getEditToken' );
281 WatchAction::getUnWatchToken( $this->watchAction->getTitle(),
$user );
289 $user->expects( $this->never() )->method(
'removeWatch' );
290 $user->expects( $this->never() )->method(
'addWatch' );
294 $this->assertTrue(
$status->isGood() );
302 $user->expects( $this->never() )->method(
'removeWatch' );
303 $user->expects( $this->never() )->method(
'addWatch' );
307 $this->assertTrue(
$status->isGood() );
315 $user->expects( $this->never() )->method(
'removeWatch' );
316 $user->expects( $this->never() )->method(
'addWatch' );
320 $this->assertTrue(
$status->isGood() );
328 $user->expects( $this->never() )->method(
'removeWatch' );
329 $user->expects( $this->once() )
330 ->method(
'addWatch' )
331 ->with( $this->equalTo( $this->testWikiPage->getTitle() ), $this->equalTo(
false ) );
335 $this->assertTrue(
$status->isGood() );
343 $user->method(
'isAllowed' )->willReturn(
true );
344 $user->expects( $this->never() )->method(
'addWatch' );
345 $user->expects( $this->once() )
346 ->method(
'removeWatch' )
347 ->with( $this->equalTo( $this->testWikiPage->getTitle() ) );
351 $this->assertTrue(
$status->isGood() );
361 $user->method(
'isLoggedIn' )->willReturn( $isLoggedIn );
362 $user->method(
'isWatched' )->willReturn( $isWatched );