2012-01-13 23:07:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class MWDebugTest extends MediaWikiTestCase {
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
2012-10-23 17:02:36 +00:00
|
|
|
parent::setUp();
|
2012-01-16 13:50:17 +00:00
|
|
|
// Make sure MWDebug class is enabled
|
|
|
|
|
static $MWDebugEnabled = false;
|
2013-02-14 13:10:38 +00:00
|
|
|
if ( !$MWDebugEnabled ) {
|
2012-01-16 13:50:17 +00:00
|
|
|
MWDebug::init();
|
|
|
|
|
$MWDebugEnabled = true;
|
|
|
|
|
}
|
2012-01-13 23:07:52 +00:00
|
|
|
/** Clear log before each test */
|
|
|
|
|
MWDebug::clearLog();
|
2012-08-25 11:09:46 +00:00
|
|
|
wfSuppressWarnings();
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function tearDown() {
|
2012-08-25 11:09:46 +00:00
|
|
|
wfRestoreWarnings();
|
2012-10-23 17:02:36 +00:00
|
|
|
parent::tearDown();
|
2012-01-13 23:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 19:35:04 +00:00
|
|
|
/**
|
|
|
|
|
* @covers MWDebug::log
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testAddLog() {
|
2012-01-13 23:07:52 +00:00
|
|
|
MWDebug::log( 'logging a string' );
|
2013-02-14 13:10:38 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
array( array(
|
|
|
|
|
'msg' => 'logging a string',
|
|
|
|
|
'type' => 'log',
|
|
|
|
|
'caller' => __METHOD__,
|
2012-01-13 23:07:52 +00:00
|
|
|
) ),
|
|
|
|
|
MWDebug::getLog()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 19:35:04 +00:00
|
|
|
/**
|
|
|
|
|
* @covers MWDebug::warning
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testAddWarning() {
|
2012-01-13 23:07:52 +00:00
|
|
|
MWDebug::warning( 'Warning message' );
|
2013-02-14 13:10:38 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
array( array(
|
|
|
|
|
'msg' => 'Warning message',
|
|
|
|
|
'type' => 'warn',
|
|
|
|
|
'caller' => 'MWDebugTest::testAddWarning',
|
2012-01-13 23:07:52 +00:00
|
|
|
) ),
|
|
|
|
|
MWDebug::getLog()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 19:35:04 +00:00
|
|
|
/**
|
|
|
|
|
* @covers MWDebug::deprecated
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testAvoidDuplicateDeprecations() {
|
2012-01-13 23:07:52 +00:00
|
|
|
MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
|
|
|
|
MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
|
|
|
|
|
2012-01-16 13:56:18 +00:00
|
|
|
// assertCount() not available on WMF integration server
|
|
|
|
|
$this->assertEquals( 1,
|
|
|
|
|
count( MWDebug::getLog() ),
|
2012-01-13 23:07:52 +00:00
|
|
|
"Only one deprecated warning per function should be kept"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 19:35:04 +00:00
|
|
|
/**
|
|
|
|
|
* @covers MWDebug::deprecated
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testAvoidNonConsecutivesDuplicateDeprecations() {
|
2012-01-13 23:07:52 +00:00
|
|
|
MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
|
|
|
|
MWDebug::warning( 'some warning' );
|
|
|
|
|
MWDebug::log( 'we could have logged something too' );
|
|
|
|
|
// Another deprecation
|
|
|
|
|
MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
|
|
|
|
|
2012-01-16 13:56:18 +00:00
|
|
|
// assertCount() not available on WMF integration server
|
|
|
|
|
$this->assertEquals( 3,
|
|
|
|
|
count( MWDebug::getLog() ),
|
2012-01-13 23:07:52 +00:00
|
|
|
"Only one deprecated warning per function should be kept"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|