MediaWiki
master
|
00001 <?php 00002 00003 class MWDebugTest extends MediaWikiTestCase { 00004 00005 00006 protected function setUp() { 00007 parent::setUp(); 00008 // Make sure MWDebug class is enabled 00009 static $MWDebugEnabled = false; 00010 if( !$MWDebugEnabled ) { 00011 MWDebug::init(); 00012 $MWDebugEnabled = true; 00013 } 00015 MWDebug::clearLog(); 00016 wfSuppressWarnings(); 00017 } 00018 00019 protected function tearDown() { 00020 wfRestoreWarnings(); 00021 parent::tearDown(); 00022 } 00023 00024 function testAddLog() { 00025 MWDebug::log( 'logging a string' ); 00026 $this->assertEquals( array( array( 00027 'msg' => 'logging a string', 00028 'type' => 'log', 00029 'caller' => __METHOD__ , 00030 ) ), 00031 MWDebug::getLog() 00032 ); 00033 } 00034 00035 function testAddWarning() { 00036 MWDebug::warning( 'Warning message' ); 00037 $this->assertEquals( array( array( 00038 'msg' => 'Warning message', 00039 'type' => 'warn', 00040 'caller' => 'MWDebugTest::testAddWarning', 00041 ) ), 00042 MWDebug::getLog() 00043 ); 00044 } 00045 00046 function testAvoidDuplicateDeprecations() { 00047 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' ); 00048 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' ); 00049 00050 // assertCount() not available on WMF integration server 00051 $this->assertEquals( 1, 00052 count( MWDebug::getLog() ), 00053 "Only one deprecated warning per function should be kept" 00054 ); 00055 } 00056 00057 function testAvoidNonConsecutivesDuplicateDeprecations() { 00058 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' ); 00059 MWDebug::warning( 'some warning' ); 00060 MWDebug::log( 'we could have logged something too' ); 00061 // Another deprecation 00062 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' ); 00063 00064 // assertCount() not available on WMF integration server 00065 $this->assertEquals( 3, 00066 count( MWDebug::getLog() ), 00067 "Only one deprecated warning per function should be kept" 00068 ); 00069 } 00070 }