Make lines short to pass phpcs in WikitextContentTest.php
[lhc/web/wiklou.git] / tests / phpunit / includes / content / WikitextContentTest.php
index bd4ae35..f0d486a 100644 (file)
@@ -89,8 +89,12 @@ more stuff
                        $update = $updates[$class];
 
                        foreach ( $fieldValues as $field => $value ) {
-                               $v = $update->$field; #if the field doesn't exist, just crash and burn
-                               $this->assertEquals( $value, $v, "unexpected value for field $field in instance of $class" );
+                               $v = $update->$field; # if the field doesn't exist, just crash and burn
+                               $this->assertEquals(
+                                       $value,
+                                       $v,
+                                       "unexpected value for field $field in instance of $class"
+                               );
                        }
                }
 
@@ -208,10 +212,12 @@ just a test"
 
        public static function dataPreloadTransform() {
                return array(
-                       array( 'hello this is ~~~',
+                       array(
+                               'hello this is ~~~',
                                "hello this is ~~~",
                        ),
-                       array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
+                       array(
+                               'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
                                'hello \'\'this\'\' is bar',
                        ),
                );
@@ -318,7 +324,10 @@ just a test"
                $this->assertTrue( $content->matchMagicWord( $mw ), "should have matched magic word" );
 
                $content = $this->newContent( "#REDIRECT [[FOO]]" );
-               $this->assertFalse( $content->matchMagicWord( $mw ), "should not have matched magic word" );
+               $this->assertFalse(
+                       $content->matchMagicWord( $mw ),
+                       "should not have matched magic word"
+               );
        }
 
        /**
@@ -340,7 +349,10 @@ just a test"
                $this->assertFalse( $content->equals( $newContent ), "content should have changed" );
                $this->assertTrue( $newContent->isRedirect(), "new content should be a redirect" );
 
-               $this->assertEquals( $target->getFullText(), $newContent->getRedirectTarget()->getFullText() );
+               $this->assertEquals(
+                       $target->getFullText(),
+                       $newContent->getRedirectTarget()->getFullText()
+               );
        }
 
        /**
@@ -361,6 +373,65 @@ just a test"
                $this->assertEquals( CONTENT_MODEL_WIKITEXT, $content->getContentHandler()->getModelID() );
        }
 
+       public function testRedirectParserOption() {
+               $title = Title::newFromText( 'testRedirectParserOption' );
+
+               // Set up hook and its reporting variables
+               $wikitext = null;
+               $redirectTarget = null;
+               $this->mergeMwGlobalArrayValue( 'wgHooks', array(
+                       'InternalParseBeforeLinks' => array(
+                               function ( &$parser, &$text, &$stripState ) use ( &$wikitext, &$redirectTarget ) {
+                                       $wikitext = $text;
+                                       $redirectTarget = $parser->getOptions()->getRedirectTarget();
+                               }
+                       )
+               ) );
+
+               // Test with non-redirect page
+               $wikitext = false;
+               $redirectTarget = false;
+               $content = $this->newContent( 'hello world.' );
+               $options = $content->getContentHandler()->makeParserOptions( 'canonical' );
+               $options->setRedirectTarget( $title );
+               $content->getParserOutput( $title, null, $options );
+               $this->assertEquals( 'hello world.', $wikitext,
+                       'Wikitext passed to hook was not as expected'
+               );
+               $this->assertEquals( null, $redirectTarget, 'Redirect seen in hook was not null' );
+               $this->assertEquals( $title, $options->getRedirectTarget(),
+                       'ParserOptions\' redirectTarget was changed'
+               );
+
+               // Test with a redirect page
+               $wikitext = false;
+               $redirectTarget = false;
+               $content = $this->newContent(
+                       "#REDIRECT [[TestRedirectParserOption/redir]]\nhello redirect."
+               );
+               $options = $content->getContentHandler()->makeParserOptions( 'canonical' );
+               $content->getParserOutput( $title, null, $options );
+               $this->assertEquals(
+                       'hello redirect.',
+                       $wikitext,
+                       'Wikitext passed to hook was not as expected'
+               );
+               $this->assertNotEquals(
+                       null,
+                       $redirectTarget,
+                       'Redirect seen in hook was null' );
+               $this->assertEquals(
+                       'TestRedirectParserOption/redir',
+                       $redirectTarget->getFullText(),
+                       'Redirect seen in hook was not the expected title'
+               );
+               $this->assertEquals(
+                       null,
+                       $options->getRedirectTarget(),
+                       'ParserOptions\' redirectTarget was changed'
+               );
+       }
+
        public static function dataEquals() {
                return array(
                        array( new WikitextContent( "hallo" ), null, false ),