MediaWiki  REL1_19
MWDebugTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class MWDebugTest extends MediaWikiTestCase {
00004 
00005 
00006         function 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         }
00016 
00017         function testAddLog() {
00018                 MWDebug::log( 'logging a string' );
00019                 $this->assertEquals( array( array(
00020                         'msg' => 'logging a string',
00021                         'type' => 'log',
00022                         'caller' => __METHOD__ ,
00023                         ) ),
00024                         MWDebug::getLog()
00025                 );
00026         }
00027 
00028         function testAddWarning() {
00029                 MWDebug::warning( 'Warning message' );
00030                 $this->assertEquals( array( array(
00031                         'msg' => 'Warning message',
00032                         'type' => 'warn',
00033                         'caller' => 'MWDebug::warning',
00034                         ) ),
00035                         MWDebug::getLog()
00036                 );
00037         }
00038 
00039         function testAvoidDuplicateDeprecations() {
00040                 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
00041                 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
00042 
00043                 // assertCount() not available on WMF integration server
00044                 $this->assertEquals( 1,
00045                         count( MWDebug::getLog() ),
00046                         "Only one deprecated warning per function should be kept"
00047                 );
00048         }
00049 
00050         function testAvoidNonConsecutivesDuplicateDeprecations() {
00051                 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
00052                 MWDebug::warning( 'some warning' );
00053                 MWDebug::log( 'we could have logged something too' );
00054                 // Another deprecation
00055                 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
00056 
00057                 // assertCount() not available on WMF integration server
00058                 $this->assertEquals( 3,
00059                         count( MWDebug::getLog() ),
00060                         "Only one deprecated warning per function should be kept"
00061                 );
00062         }
00063 }