2013-10-28 16:24:50 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* @author Antoine Musso
|
|
|
|
|
* @copyright Copyright © 2013, Antoine Musso
|
|
|
|
|
* @copyright Copyright © 2013, Wikimedia Foundation Inc.
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
2020-06-30 15:09:24 +00:00
|
|
|
class MWExceptionTest extends MediaWikiIntegrationTestCase {
|
2013-10-28 16:24:50 +00:00
|
|
|
|
|
|
|
|
/**
|
2017-12-28 08:22:35 +00:00
|
|
|
* @covers MWException
|
2013-10-28 16:24:50 +00:00
|
|
|
*/
|
2014-02-24 20:21:09 +00:00
|
|
|
public function testMwexceptionThrowing() {
|
2019-10-11 22:22:26 +00:00
|
|
|
$this->expectException( MWException::class );
|
2013-10-28 16:24:50 +00:00
|
|
|
throw new MWException();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-26 13:01:47 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideTextUseOutputPage
|
|
|
|
|
* @covers MWException::useOutputPage
|
|
|
|
|
*/
|
2020-10-28 21:21:24 +00:00
|
|
|
public function testUseOutputPage( $expected, $langObj, $fullyInitialised, $outputPage ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setMwGlobals( [
|
2016-03-09 16:47:58 +00:00
|
|
|
'wgLang' => $langObj,
|
2020-10-28 21:21:24 +00:00
|
|
|
'wgFullyInitialised' => $fullyInitialised,
|
|
|
|
|
'wgOut' => $outputPage,
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2014-02-26 13:01:47 +00:00
|
|
|
|
|
|
|
|
$e = new MWException();
|
|
|
|
|
$this->assertEquals( $expected, $e->useOutputPage() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideTextUseOutputPage() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2016-03-09 16:47:58 +00:00
|
|
|
// expected, langObj, wgFullyInitialised, wgOut
|
2016-02-17 09:09:32 +00:00
|
|
|
[ false, null, null, null ],
|
|
|
|
|
[ false, $this->getMockLanguage(), null, null ],
|
|
|
|
|
[ false, $this->getMockLanguage(), true, null ],
|
|
|
|
|
[ false, null, true, null ],
|
|
|
|
|
[ false, null, null, true ],
|
|
|
|
|
[ true, $this->getMockLanguage(), true, true ],
|
|
|
|
|
];
|
2014-02-26 13:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getMockLanguage() {
|
2018-01-13 00:02:09 +00:00
|
|
|
return $this->getMockBuilder( Language::class )
|
2014-02-26 13:01:47 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers MWException::useMessageCache
|
|
|
|
|
*/
|
2020-03-02 09:35:57 +00:00
|
|
|
public function testUseMessageCache() {
|
2014-02-26 13:01:47 +00:00
|
|
|
$e = new MWException();
|
2020-03-02 09:35:57 +00:00
|
|
|
$this->assertTrue( $e->useMessageCache() );
|
2014-02-26 13:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers MWException::isLoggable
|
|
|
|
|
*/
|
|
|
|
|
public function testIsLogable() {
|
|
|
|
|
$e = new MWException();
|
|
|
|
|
$this->assertTrue( $e->isLoggable() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideIsCommandLine
|
|
|
|
|
* @covers MWException::isCommandLine
|
|
|
|
|
*/
|
2020-10-28 21:21:24 +00:00
|
|
|
public function testisCommandLine( $expected, $commandLineMode ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setMwGlobals( [
|
2020-10-28 21:21:24 +00:00
|
|
|
'wgCommandLineMode' => $commandLineMode,
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2014-02-26 13:01:47 +00:00
|
|
|
$e = new MWException();
|
|
|
|
|
$this->assertEquals( $expected, $e->isCommandLine() );
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-18 01:28:26 +00:00
|
|
|
public static function provideIsCommandLine() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ false, null ],
|
|
|
|
|
[ true, true ],
|
|
|
|
|
];
|
2014-02-26 13:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-28 16:24:50 +00:00
|
|
|
/**
|
|
|
|
|
* Verify the exception classes are JSON serializabe.
|
|
|
|
|
*
|
|
|
|
|
* @covers MWExceptionHandler::jsonSerializeException
|
|
|
|
|
* @dataProvider provideExceptionClasses
|
|
|
|
|
*/
|
2014-02-24 20:21:09 +00:00
|
|
|
public function testJsonSerializeExceptions( $exception_class ) {
|
2013-10-28 16:24:50 +00:00
|
|
|
$json = MWExceptionHandler::jsonSerializeException(
|
|
|
|
|
new $exception_class()
|
|
|
|
|
);
|
2020-10-28 19:57:14 +00:00
|
|
|
$this->assertIsString( $json,
|
2013-10-28 16:24:50 +00:00
|
|
|
"The $exception_class exception should be JSON serializable, got false." );
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-18 01:28:26 +00:00
|
|
|
public static function provideExceptionClasses() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2018-01-13 00:02:09 +00:00
|
|
|
[ Exception::class ],
|
|
|
|
|
[ MWException::class ],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-10-28 16:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|