Merge "Correct documentation for EditFilter hook parameter"
[lhc/web/wiklou.git] / tests / phpunit / includes / debug / MWDebugTest.php
1 <?php
2
3 class MWDebugTest extends MediaWikiTestCase {
4
5
6 protected function setUp() {
7 parent::setUp();
8 // Make sure MWDebug class is enabled
9 static $MWDebugEnabled = false;
10 if( !$MWDebugEnabled ) {
11 MWDebug::init();
12 $MWDebugEnabled = true;
13 }
14 /** Clear log before each test */
15 MWDebug::clearLog();
16 wfSuppressWarnings();
17 }
18
19 protected function tearDown() {
20 wfRestoreWarnings();
21 parent::tearDown();
22 }
23
24 function testAddLog() {
25 MWDebug::log( 'logging a string' );
26 $this->assertEquals( array( array(
27 'msg' => 'logging a string',
28 'type' => 'log',
29 'caller' => __METHOD__ ,
30 ) ),
31 MWDebug::getLog()
32 );
33 }
34
35 function testAddWarning() {
36 MWDebug::warning( 'Warning message' );
37 $this->assertEquals( array( array(
38 'msg' => 'Warning message',
39 'type' => 'warn',
40 'caller' => 'MWDebugTest::testAddWarning',
41 ) ),
42 MWDebug::getLog()
43 );
44 }
45
46 function testAvoidDuplicateDeprecations() {
47 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
48 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
49
50 // assertCount() not available on WMF integration server
51 $this->assertEquals( 1,
52 count( MWDebug::getLog() ),
53 "Only one deprecated warning per function should be kept"
54 );
55 }
56
57 function testAvoidNonConsecutivesDuplicateDeprecations() {
58 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
59 MWDebug::warning( 'some warning' );
60 MWDebug::log( 'we could have logged something too' );
61 // Another deprecation
62 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
63
64 // assertCount() not available on WMF integration server
65 $this->assertEquals( 3,
66 count( MWDebug::getLog() ),
67 "Only one deprecated warning per function should be kept"
68 );
69 }
70 }