Introducing ContentGetParserOutput hook.
[lhc/web/wiklou.git] / tests / phpunit / includes / content / TextContentTest.php
index 382f71a..d7dde37 100644 (file)
@@ -7,14 +7,21 @@
  */
 class TextContentTest extends MediaWikiLangTestCase {
        protected $context;
+       protected $savedContentGetParserOutput;
 
        protected function setUp() {
+               global $wgHooks;
+
                parent::setUp();
 
                // Anon user
                $user = new User();
                $user->setName( '127.0.0.1' );
 
+               $this->context = new RequestContext( new FauxRequest() );
+               $this->context->setTitle( Title::newFromText( 'Test' ) );
+               $this->context->setUser( $user );
+
                $this->setMwGlobals( array(
                        'wgUser' => $user,
                        'wgTextModelsToParse' => array(
@@ -26,9 +33,22 @@ class TextContentTest extends MediaWikiLangTestCase {
                        'wgAlwaysUseTidy' => false,
                ) );
 
-               $this->context = new RequestContext( new FauxRequest() );
-               $this->context->setTitle( Title::newFromText( 'Test' ) );
-               $this->context->setUser( $user );
+               // bypass hooks that force custom rendering
+               if ( isset( $wgHooks['ContentGetParserOutput'] )  ) {
+                       $this->savedContentGetParserOutput = $wgHooks['ContentGetParserOutput'];
+                       unset( $wgHooks['ContentGetParserOutput'] );
+               }
+       }
+
+       public function teardown() {
+               global $wgHooks;
+
+               // restore hooks that force custom rendering
+               if ( $this->savedContentGetParserOutput !== null ) {
+                       $wgHooks['ContentGetParserOutput'] = $this->savedContentGetParserOutput;
+               }
+
+               parent::teardown();
        }
 
        public function newContent( $text ) {
@@ -162,7 +182,7 @@ class TextContentTest extends MediaWikiLangTestCase {
        }
 
        /**
-        * @todo: test needs database! Should be done by a test class in the Database group.
+        * @todo Test needs database! Should be done by a test class in the Database group.
         */
        /*
        public function getRedirectChain() {
@@ -172,7 +192,7 @@ class TextContentTest extends MediaWikiLangTestCase {
        */
 
        /**
-        * @todo: test needs database! Should be done by a test class in the Database group.
+        * @todo Test needs database! Should be done by a test class in the Database group.
         */
        /*
        public function getUltimateRedirectTarget() {
@@ -211,15 +231,11 @@ class TextContentTest extends MediaWikiLangTestCase {
         * @group Database
         */
        public function testIsCountable( $text, $hasLinks, $mode, $expected ) {
-               global $wgArticleCountMethod;
-
-               $old = $wgArticleCountMethod;
-               $wgArticleCountMethod = $mode;
+               $this->setMwGlobals( 'wgArticleCountMethod', $mode );
 
                $content = $this->newContent( $text );
 
                $v = $content->isCountable( $hasLinks, $this->context->getTitle() );
-               $wgArticleCountMethod = $old;
 
                $this->assertEquals( $expected, $v, 'isCountable() returned unexpected value ' . var_export( $v, true )
                        . ' instead of ' . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" );
@@ -427,5 +443,4 @@ class TextContentTest extends MediaWikiLangTestCase {
                        $this->assertEquals( $expectedNative, $converted->getNativeData() );
                }
        }
-
 }