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