MediaWiki  1.23.2
MWExceptionTest.php
Go to the documentation of this file.
1 <?php
10 
14  public function testMwexceptionThrowing() {
15  throw new MWException();
16  }
17 
22  public function testUseOutputPage( $expected, $wgLang, $wgFullyInitialised, $wgOut ) {
23  $this->setMwGlobals( array(
24  'wgLang' => $wgLang,
25  'wgFullyInitialised' => $wgFullyInitialised,
26  'wgOut' => $wgOut,
27  ) );
28 
29  $e = new MWException();
30  $this->assertEquals( $expected, $e->useOutputPage() );
31  }
32 
33  public function provideTextUseOutputPage() {
34  return array(
35  // expected, wgLang, wgFullyInitialised, wgOut
36  array( false, null, null, null ),
37  array( false, $this->getMockLanguage(), null, null ),
38  array( false, $this->getMockLanguage(), true, null ),
39  array( false, null, true, null ),
40  array( false, null, null, true ),
41  array( true, $this->getMockLanguage(), true, true ),
42  );
43  }
44 
45  private function getMockLanguage() {
46  return $this->getMockBuilder( 'Language' )
47  ->disableOriginalConstructor()
48  ->getMock();
49  }
50 
55  public function testUseMessageCache( $expected, $wgLang ) {
56  $this->setMwGlobals( array(
57  'wgLang' => $wgLang,
58  ) );
59  $e = new MWException();
60  $this->assertEquals( $expected, $e->useMessageCache() );
61  }
62 
63  public function provideUseMessageCache() {
64  return array(
65  array( false, null ),
66  array( true, $this->getMockLanguage() ),
67  );
68  }
69 
73  public function testIsLogable() {
74  $e = new MWException();
75  $this->assertTrue( $e->isLoggable() );
76  }
77 
82  public function testRunHooks( $wgExceptionHooks, $name, $args, $expectedReturn ) {
83  $this->setMwGlobals( array(
84  'wgExceptionHooks' => $wgExceptionHooks,
85  ) );
86  $e = new MWException();
87  $this->assertEquals( $expectedReturn, $e->runHooks( $name, $args ) );
88  }
89 
90  public function provideRunHooks() {
91  return array(
92  array( null, null, null, null ),
93  array( array(), 'name', array(), null ),
94  array( array( 'name' => false ), 'name', array(), null ),
95  array(
96  array( 'mockHook' => array( 'MWExceptionTest::mockHook' ) ),
97  'mockHook', array(), 'YAY.[]'
98  ),
99  array(
100  array( 'mockHook' => array( 'MWExceptionTest::mockHook' ) ),
101  'mockHook', array( 'a' ), 'YAY.{"1":"a"}'
102  ),
103  array(
104  array( 'mockHook' => array( 'MWExceptionTest::mockHook' ) ),
105  'mockHook', array( null ), null
106  ),
107  );
108  }
109 
113  public static function mockHook() {
114  $args = func_get_args();
115  if ( !$args[0] instanceof MWException ) {
116  return '$caller not instance of MWException';
117  }
118  unset( $args[0] );
119  if ( array_key_exists( 1, $args ) && $args[1] === null ) {
120  return null;
121  }
122  return 'YAY.' . json_encode( $args );
123  }
124 
129  public function testisCommandLine( $expected, $wgCommandLineMode ) {
130  $this->setMwGlobals( array(
131  'wgCommandLineMode' => $wgCommandLineMode,
132  ) );
133  $e = new MWException();
134  $this->assertEquals( $expected, $e->isCommandLine() );
135  }
136 
137  public function provideIsCommandLine() {
138  return array(
139  array( false, null ),
140  array( true, true ),
141  );
142  }
143 
150  public function testJsonSerializeExceptions( $exception_class ) {
152  new $exception_class()
153  );
154  $this->assertNotEquals( false, $json,
155  "The $exception_class exception should be JSON serializable, got false." );
156  }
157 
158  public function provideExceptionClasses() {
159  return array(
160  array( 'Exception' ),
161  array( 'MWException' ),
162  );
163  }
164 
175  public function testJsonserializeexceptionKeys( $expectedKeyType, $exClass, $key ) {
176 
177  # Make sure we log a backtrace:
178  $this->setMwGlobals( array( 'wgLogExceptionBacktrace' => true ) );
179 
180  $json = json_decode(
182  );
183  $this->assertObjectHasAttribute( $key, $json,
184  "JSON serialized exception is missing key '$key'"
185  );
186  $this->assertInternalType( $expectedKeyType, $json->$key,
187  "JSON serialized key '$key' has type " . gettype( $json->$key )
188  . " (expected: $expectedKeyType)."
189  );
190  }
191 
195  public function provideJsonSerializedKeys() {
196  $testCases = array();
197  foreach ( array( 'Exception', 'MWException' ) as $exClass ) {
198  $exTests = array(
199  array( 'string', $exClass, 'id' ),
200  array( 'string', $exClass, 'file' ),
201  array( 'integer', $exClass, 'line' ),
202  array( 'string', $exClass, 'message' ),
203  array( 'null', $exClass, 'url' ),
204  # Backtrace only enabled with wgLogExceptionBacktrace = true
205  array( 'array', $exClass, 'backtrace' ),
206  );
207  $testCases = array_merge( $testCases, $exTests );
208  }
209  return $testCases;
210  }
211 
219  $this->setMwGlobals( array( 'wgLogExceptionBacktrace' => true ) );
220  $json = json_decode(
222  );
223  $this->assertObjectHasAttribute( 'backtrace', $json );
224  }
225 
233  $this->setMwGlobals( array( 'wgLogExceptionBacktrace' => false ) );
234  $json = json_decode(
236  );
237  $this->assertObjectNotHasAttribute( 'backtrace', $json );
238 
239  }
240 
241 }
MWExceptionTest\testJsonserializeexceptionBacktracingDisabled
testJsonserializeexceptionBacktracingDisabled()
Given wgLogExceptionBacktrace is false then serialized exception SHOULD NOT have a backtrace.
Definition: MWExceptionTest.php:232
MWExceptionTest
Definition: MWExceptionTest.php:9
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
MWExceptionTest\testJsonserializeexceptionBacktracingEnabled
testJsonserializeexceptionBacktracingEnabled()
Given wgLogExceptionBacktrace is true then serialized exception SHOULD have a backtrace.
Definition: MWExceptionTest.php:218
MWExceptionTest\provideJsonSerializedKeys
provideJsonSerializedKeys()
Returns test cases: exception class, key name, gettype()
Definition: MWExceptionTest.php:195
MWExceptionTest\testIsLogable
testIsLogable()
@covers MWException::isLoggable
Definition: MWExceptionTest.php:73
MWExceptionTest\testUseOutputPage
testUseOutputPage( $expected, $wgLang, $wgFullyInitialised, $wgOut)
@dataProvider provideTextUseOutputPage @covers MWException::useOutputPage
Definition: MWExceptionTest.php:22
MWExceptionTest\testMwexceptionThrowing
testMwexceptionThrowing()
@expectedException MWException
Definition: MWExceptionTest.php:14
MWExceptionTest\getMockLanguage
getMockLanguage()
Definition: MWExceptionTest.php:45
MWExceptionHandler\jsonSerializeException
static jsonSerializeException(Exception $e, $pretty=false, $escaping=0)
Serialize an Exception object to JSON.
Definition: MWExceptionHandler.php:318
MWExceptionTest\provideUseMessageCache
provideUseMessageCache()
Definition: MWExceptionTest.php:63
MWExceptionTest\provideExceptionClasses
provideExceptionClasses()
Definition: MWExceptionTest.php:158
MWException
MediaWiki exception.
Definition: MWException.php:26
MWExceptionTest\provideRunHooks
provideRunHooks()
Definition: MWExceptionTest.php:90
$wgFullyInitialised
$wgFullyInitialised
Definition: Setup.php:606
$wgCommandLineMode
global $wgCommandLineMode
Definition: Setup.php:401
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
$wgOut
$wgOut
Definition: Setup.php:562
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
MWExceptionTest\testisCommandLine
testisCommandLine( $expected, $wgCommandLineMode)
@dataProvider provideIsCommandLine @covers MWException::isCommandLine
Definition: MWExceptionTest.php:129
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
MWExceptionTest\testJsonserializeexceptionKeys
testJsonserializeexceptionKeys( $expectedKeyType, $exClass, $key)
Lame JSON schema validation.
Definition: MWExceptionTest.php:175
MWExceptionTest\mockHook
static mockHook()
Used in conjunction with provideRunHooks and testRunHooks as a mock callback for a hook.
Definition: MWExceptionTest.php:113
only
published in in Madrid In the first edition of the Vocabolario for was published In in Rotterdam was the Dictionnaire Universel ! html< p > The first monolingual dictionary written in a Romance language was< i > Sebastián Covarrubias</i >< i > Tesoro de la lengua castellana o published in in Madrid In the first edition of the< i > Vocabolario dell< a href="/index.php?title=Accademia_della_Crusca&amp;action=edit&amp;redlink=1" class="new" title="Accademia della Crusca (page does not exist)"> Accademia della Crusca</a ></i > for was published In in Rotterdam was the< i > Dictionnaire Universel</i ></p > ! end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html php< p >< i > foo</i ></p > ! html parsoid< p >< i > foo</i >< b ></b ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html php< p >< b > foo</b ></p > ! html parsoid< p >< b > foo</b >< i ></i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html php< p >< b > foo</b ></p > ! html parsoid< p >< b > foo</b >< i ></i ></p > !end ! test Italics and ! options ! wikitext foo ! html< p >< b >< i > foo</i ></b ></p > !end ! test Italics and ! wikitext foo ! html< p >< i >< b > foo</b ></i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i >< b > foo</b ></i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i >< b > foo</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html< p >< i > foo< b > bar</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html< p >< i > foo< b > bar</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html< p >< i > foo< b > bar</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html php< p >< b > foo</b > bar</p > ! html parsoid< p >< b > foo</b > bar< i ></i ></p > !end ! test Italics and ! wikitext foo bar ! html php< p >< b > foo</b > bar</p > ! html parsoid< p >< b > foo</b > bar< b ></b ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< i > this is about< b > foo s family</b ></i ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< i > this is about< b > foo s</b > family</i ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< b > this is about< i > foo</i ></b >< i > s family</i ></p > !end ! test Italics and ! options ! wikitext this is about foo s family ! html< p >< i > this is about</i > foo< b > s family</b ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< b > this is about< i > foo s</i > family</b ></p > !end ! test Italicized possessive ! wikitext The s talk page ! html< p > The< i >< a href="/wiki/Main_Page" title="Main Page"> Main Page</a ></i > s talk page</p > ! end ! test Parsoid only
Definition: parserTests.txt:396
$args
if( $line===false) $args
Definition: cdb.php:62
$wgLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
Definition: design.txt:56
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
MWExceptionTest\testJsonSerializeExceptions
testJsonSerializeExceptions( $exception_class)
Verify the exception classes are JSON serializabe.
Definition: MWExceptionTest.php:150
MWExceptionTest\testUseMessageCache
testUseMessageCache( $expected, $wgLang)
@dataProvider provideUseMessageCache @covers MWException::useMessageCache
Definition: MWExceptionTest.php:55
$e
if( $useReadline) $e
Definition: eval.php:66
MWExceptionTest\testRunHooks
testRunHooks( $wgExceptionHooks, $name, $args, $expectedReturn)
@dataProvider provideRunHooks @covers MWException::runHooks
Definition: MWExceptionTest.php:82
MWExceptionTest\provideTextUseOutputPage
provideTextUseOutputPage()
Definition: MWExceptionTest.php:33
MWExceptionTest\provideIsCommandLine
provideIsCommandLine()
Definition: MWExceptionTest.php:137