MediaWiki  REL1_22
MWDebugTest.php
Go to the documentation of this file.
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     public function testAddLog() {
00025         MWDebug::log( 'logging a string' );
00026         $this->assertEquals(
00027             array( array(
00028                 'msg' => 'logging a string',
00029                 'type' => 'log',
00030                 'caller' => __METHOD__,
00031             ) ),
00032             MWDebug::getLog()
00033         );
00034     }
00035 
00036     public function testAddWarning() {
00037         MWDebug::warning( 'Warning message' );
00038         $this->assertEquals(
00039             array( array(
00040                 'msg' => 'Warning message',
00041                 'type' => 'warn',
00042                 'caller' => 'MWDebugTest::testAddWarning',
00043             ) ),
00044             MWDebug::getLog()
00045         );
00046     }
00047 
00048     public function testAvoidDuplicateDeprecations() {
00049         MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
00050         MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
00051 
00052         // assertCount() not available on WMF integration server
00053         $this->assertEquals( 1,
00054             count( MWDebug::getLog() ),
00055             "Only one deprecated warning per function should be kept"
00056         );
00057     }
00058 
00059     public function testAvoidNonConsecutivesDuplicateDeprecations() {
00060         MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
00061         MWDebug::warning( 'some warning' );
00062         MWDebug::log( 'we could have logged something too' );
00063         // Another deprecation
00064         MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
00065 
00066         // assertCount() not available on WMF integration server
00067         $this->assertEquals( 3,
00068             count( MWDebug::getLog() ),
00069             "Only one deprecated warning per function should be kept"
00070         );
00071     }
00072 }