Right now, ErrorPageError *assumes* you're never running on the cli or the API. It's kinda a crappy superclass to use for errors unless you're 1000% sure you'll never hit that code path. Yay assumptions! Ideally, all of this report() crap is cleaned up and unified across the like 1192902117 places we have it spread out, but for now just detect the scenario and delegate back to MWException, which does the right thing Bug: T168337 Change-Id: Ia2f490528e128527a7a5ef1f4f5eea36ec9ee810
52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @covers ErrorPageError
|
|
* @author Addshore
|
|
*/
|
|
class ErrorPageErrorTest extends MediaWikiTestCase {
|
|
|
|
private function getMockMessage() {
|
|
$mockMessage = $this->getMockBuilder( 'Message' )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$mockMessage->expects( $this->once() )
|
|
->method( 'inLanguage' )
|
|
->will( $this->returnValue( $mockMessage ) );
|
|
$mockMessage->expects( $this->once() )
|
|
->method( 'useDatabase' )
|
|
->will( $this->returnValue( $mockMessage ) );
|
|
return $mockMessage;
|
|
}
|
|
|
|
public function testConstruction() {
|
|
$mockMessage = $this->getMockMessage();
|
|
$title = 'Foo';
|
|
$params = [ 'Baz' ];
|
|
$e = new ErrorPageError( $title, $mockMessage, $params );
|
|
$this->assertEquals( $title, $e->title );
|
|
$this->assertEquals( $mockMessage, $e->msg );
|
|
$this->assertEquals( $params, $e->params );
|
|
}
|
|
|
|
public function testReport() {
|
|
$mockMessage = $this->getMockMessage();
|
|
$title = 'Foo';
|
|
$params = [ 'Baz' ];
|
|
|
|
$mock = $this->getMockBuilder( 'OutputPage' )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$mock->expects( $this->once() )
|
|
->method( 'showErrorPage' )
|
|
->with( $title, $mockMessage, $params );
|
|
$mock->expects( $this->once() )
|
|
->method( 'output' );
|
|
$this->setMwGlobals( 'wgOut', $mock );
|
|
$this->setMwGlobals( 'wgCommandLineMode', false );
|
|
|
|
$e = new ErrorPageError( $title, $mockMessage, $params );
|
|
$e->report();
|
|
}
|
|
|
|
}
|