Merge "(bug 44219) Avoid fatal errors when a revision doesn't exist in action=info"
[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(
27 array( array(
28 'msg' => 'logging a string',
29 'type' => 'log',
30 'caller' => __METHOD__,
31 ) ),
32 MWDebug::getLog()
33 );
34 }
35
36 function testAddWarning() {
37 MWDebug::warning( 'Warning message' );
38 $this->assertEquals(
39 array( array(
40 'msg' => 'Warning message',
41 'type' => 'warn',
42 'caller' => 'MWDebugTest::testAddWarning',
43 ) ),
44 MWDebug::getLog()
45 );
46 }
47
48 function testAvoidDuplicateDeprecations() {
49 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
50 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
51
52 // assertCount() not available on WMF integration server
53 $this->assertEquals( 1,
54 count( MWDebug::getLog() ),
55 "Only one deprecated warning per function should be kept"
56 );
57 }
58
59 function testAvoidNonConsecutivesDuplicateDeprecations() {
60 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
61 MWDebug::warning( 'some warning' );
62 MWDebug::log( 'we could have logged something too' );
63 // Another deprecation
64 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
65
66 // assertCount() not available on WMF integration server
67 $this->assertEquals( 3,
68 count( MWDebug::getLog() ),
69 "Only one deprecated warning per function should be kept"
70 );
71 }
72 }