From 496ff9d4106fe87f41da0ae02c5e2d33ce9f52b2 Mon Sep 17 00:00:00 2001 From: X! Date: Sun, 2 Jan 2011 02:16:32 +0000 Subject: [PATCH] Followup r79467: Add more wfDebug() tests, complete with MockOutputPage --- tests/phpunit/includes/GlobalTest.php | 47 +++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/includes/GlobalTest.php b/tests/phpunit/includes/GlobalTest.php index 1e09f398ca..104d4f2775 100644 --- a/tests/phpunit/includes/GlobalTest.php +++ b/tests/phpunit/includes/GlobalTest.php @@ -467,26 +467,58 @@ class GlobalTest extends MediaWikiTestCase { function testDebugFunctionTest() { - global $wgDebugLogFile; + + global $wgDebugLogFile, $wgOut, $wgShowDebug; $old_log_file = $wgDebugLogFile; - $wgDebugLogFile = tempnam( wfTempDir(), 'mw-' ); + wfDebug( "This is a normal string" ); $this->assertEquals( "This is a normal string", file_get_contents( $wgDebugLogFile ) ); unlink( $wgDebugLogFile ); + wfDebug( "This is nöt an ASCII string" ); $this->assertEquals( "This is nöt an ASCII string", file_get_contents( $wgDebugLogFile ) ); unlink( $wgDebugLogFile ); + wfDebug( "\00305This has böth UTF and control chars\003" ); $this->assertEquals( " 05This has böth UTF and control chars ", file_get_contents( $wgDebugLogFile ) ); unlink( $wgDebugLogFile ); + + $old_wgOut = $wgOut; + $old_wgShowDebug = $wgShowDebug; + + $wgOut = new StubObject( 'wgOut', 'MockOutputPage' ); + $wgOut->doNothing(); //just to unstub it + + $wgShowDebug = true; + + $message = "\00305This has böth UTF and control chars\003"; + + wfDebug( $message ); + + if( $wgOut->message == "JAJA is a stupid error message. Anyway, here's your message: $message" ) { + $this->assertTrue( true, 'MockOutputPage called, set the proper message.' ); + } + else { + $this->assertTrue( false, 'MockOutputPage was not called.' ); + } + + unlink( $wgDebugLogFile ); + + + $wgOut = $old_wgOut; + $wgShowDebug = $old_wgShowDebug; + + + + $wgDebugLogFile = $old_log_file; } @@ -495,3 +527,14 @@ class GlobalTest extends MediaWikiTestCase { } +class MockOutputPage { + + public $message; + + function debug( $message ) { + $this->message = "JAJA is a stupid error message. Anyway, here's your message: $message"; + } + + function doNothing() {} +} + -- 2.20.1