MediaWiki
REL1_22
|
00001 <?php 00011 class MWExceptionHandlerTest extends MediaWikiTestCase { 00012 00016 function testGetRedactedTrace() { 00017 try { 00018 $array = array( 'a', 'b' ); 00019 $object = new StdClass(); 00020 self::helperThrowAnException( $array, $object ); 00021 } catch (Exception $e) { 00022 } 00023 00024 # Make sure our strack trace contains an array and an object passed to 00025 # some function in the stacktrace. Else, we can not assert the trace 00026 # redaction achieved its job. 00027 $trace = $e->getTrace(); 00028 $hasObject = false; 00029 $hasArray = false; 00030 foreach ( $trace as $frame ) { 00031 if ( ! isset( $frame['args'] ) ) { 00032 continue; 00033 } 00034 foreach ( $frame['args'] as $arg ) { 00035 $hasObject = $hasObject || is_object( $arg ); 00036 $hasArray = $hasArray || is_array( $arg ); 00037 } 00038 00039 if( $hasObject && $hasArray ) { 00040 break; 00041 } 00042 } 00043 $this->assertTrue( $hasObject, 00044 "The stacktrace must have a function having an object has parameter" ); 00045 $this->assertTrue( $hasArray, 00046 "The stacktrace must have a function having an array has parameter" ); 00047 00048 # Now we redact the trace.. and make sure no function arguments are 00049 # arrays or objects. 00050 $redacted = MWExceptionHandler::getRedactedTrace( $e ); 00051 00052 foreach ( $redacted as $frame ) { 00053 if ( ! isset( $frame['args'] ) ) { 00054 continue; 00055 } 00056 foreach ( $frame['args'] as $arg ) { 00057 $this->assertNotInternalType( 'array', $arg); 00058 $this->assertNotInternalType( 'object', $arg); 00059 } 00060 } 00061 } 00062 00070 protected static function helperThrowAnException( $a, $b ) { 00071 throw new Exception(); 00072 } 00073 }