summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/exception/BadTitleErrorTest.php
blob: 003efd27f46441e43958dad1d7046108c6242bfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
 * @covers BadTitleError
 * @author Adam Shorland
 */
class BadTitleErrorTest extends MediaWikiTestCase {

	protected $wgOut;

	protected function setUp() {
		parent::setUp();
		global $wgOut;
		$this->wgOut = clone $wgOut;
	}

	protected function tearDown() {
		parent::tearDown();
		global $wgOut;
		$wgOut = $this->wgOut;
	}

	public function testExceptionSetsStatusCode() {
		global $wgOut;
		$wgOut = $this->getMockWgOut();
		try {
			throw new BadTitleError();
		} catch ( BadTitleError $e ) {
			$e->report();
			$this->assertTrue( true );
		}
	}

	private function getMockWgOut() {
		$mock = $this->getMockBuilder( 'OutputPage' )
			->disableOriginalConstructor()
			->getMock();
		$mock->expects( $this->once() )
			->method( 'setStatusCode' )
			->with( 400 );
		return $mock;
	}

}