Merge "(Bug 41352) Provide tests for edit conflicts."
[lhc/web/wiklou.git] / tests / phpunit / includes / WikiPageTest.php
index 23a4a01..fb20ce6 100644 (file)
@@ -3,6 +3,7 @@
 * @group ContentHandler
 * @group Database
 * ^--- important, causes temporary tables to be used instead of the real database
+* @group medium
 **/
 
 class WikiPageTest extends MediaWikiLangTestCase {
@@ -12,32 +13,33 @@ class WikiPageTest extends MediaWikiLangTestCase {
        function  __construct( $name = null, array $data = array(), $dataName = '' ) {
                parent::__construct( $name, $data, $dataName );
 
-               $this->tablesUsed = array_merge ( $this->tablesUsed,
-                                                                                 array( 'page',
-                                                                                               'revision',
-                                                                                               'text',
+               $this->tablesUsed = array_merge (
+                       $this->tablesUsed,
+                       array( 'page',
+                                       'revision',
+                                       'text',
 
-                                                                                               'recentchanges',
-                                                                                               'logging',
+                                       'recentchanges',
+                                       'logging',
 
-                                                                                               'page_props',
-                                                                                               'pagelinks',
-                                                                                               'categorylinks',
-                                                                                               'langlinks',
-                                                                                               'externallinks',
-                                                                                               'imagelinks',
-                                                                                               'templatelinks',
-                                                                                               'iwlinks' ) );
+                                       'page_props',
+                                       'pagelinks',
+                                       'categorylinks',
+                                       'langlinks',
+                                       'externallinks',
+                                       'imagelinks',
+                                       'templatelinks',
+                                       'iwlinks' ) );
        }
 
-       public function setUp() {
+       protected function setUp() {
                parent::setUp();
                $this->pages_to_delete = array();
 
                LinkCache::singleton()->clear(); # avoid cached redirect status, etc
        }
 
-       public function tearDown() {
+       protected function tearDown() {
                foreach ( $this->pages_to_delete as $p ) {
                        /* @var $p WikiPage */
 
@@ -59,7 +61,8 @@ class WikiPageTest extends MediaWikiLangTestCase {
         */
        protected function newPage( $title, $model = null ) {
                if ( is_string( $title ) ) {
-                       $title = Title::newFromText( $title );
+                       $ns = $this->getDefaultWikitextNS();
+                       $title = Title::newFromText( $title, $ns );
                }
 
                $p = new WikiPage( $title );
@@ -78,11 +81,7 @@ class WikiPageTest extends MediaWikiLangTestCase {
         * @return WikiPage
         */
        protected function createPage( $page, $text, $model = null ) {
-               if ( is_string( $page ) ) {
-                       $page = Title::newFromText( $page );
-               }
-
-               if ( $page instanceof Title ) {
+               if ( is_string( $page ) || $page instanceof Title ) {
                        $page = $this->newPage( $page, $model );
                }
 
@@ -93,13 +92,12 @@ class WikiPageTest extends MediaWikiLangTestCase {
        }
 
        public function testDoEditContent() {
-               $title = Title::newFromText( "WikiPageTest_testDoEditContent" );
-
-               $page = $this->newPage( $title );
+               $page = $this->newPage( "WikiPageTest_testDoEditContent" );
+               $title = $page->getTitle();
 
                $content = ContentHandler::makeContent( "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
-                                                                                         . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
-                                                                                         $title, CONTENT_MODEL_WIKITEXT );
+                                               . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
+                                               $title, CONTENT_MODEL_WIKITEXT );
 
                $page->doEditContent( $content, "[[testing]] 1" );
 
@@ -374,7 +372,7 @@ class WikiPageTest extends MediaWikiLangTestCase {
                $this->assertFalse( $page->exists() );
        }
 
-       public function dataHasViewableContent() {
+       public static function provideHasViewableContent() {
                return array(
                        array( 'WikiPageTest_testHasViewableContent', false, true ),
                        array( 'Special:WikiPageTest_testHasViewableContent', false ),
@@ -385,7 +383,7 @@ class WikiPageTest extends MediaWikiLangTestCase {
        }
 
        /**
-        * @dataProvider dataHasViewableContent
+        * @dataProvider provideHasViewableContent
         */
        public function testHasViewableContent( $title, $viewable, $create = false ) {
                $page = $this->newPage( $title );
@@ -400,7 +398,7 @@ class WikiPageTest extends MediaWikiLangTestCase {
                }
        }
 
-       public function dataGetRedirectTarget() {
+       public static function provideGetRedirectTarget() {
                return array(
                        array( 'WikiPageTest_testGetRedirectTarget_1', CONTENT_MODEL_WIKITEXT, "hello world", null ),
                        array( 'WikiPageTest_testGetRedirectTarget_2', CONTENT_MODEL_WIKITEXT, "#REDIRECT [[hello world]]", "Hello world" ),
@@ -408,7 +406,7 @@ class WikiPageTest extends MediaWikiLangTestCase {
        }
 
        /**
-        * @dataProvider dataGetRedirectTarget
+        * @dataProvider provideGetRedirectTarget
         */
        public function testGetRedirectTarget( $title, $model, $text, $target ) {
                $page = $this->createPage( $title, $text, $model );
@@ -423,14 +421,14 @@ class WikiPageTest extends MediaWikiLangTestCase {
        }
 
        /**
-        * @dataProvider dataGetRedirectTarget
+        * @dataProvider provideGetRedirectTarget
         */
        public function testIsRedirect( $title, $model, $text, $target ) {
                $page = $this->createPage( $title, $text, $model );
                $this->assertEquals( !is_null( $target ), $page->isRedirect() );
        }
 
-       public function dataIsCountable() {
+       public static function provideIsCountable() {
                return array(
 
                        // any
@@ -539,13 +537,19 @@ class WikiPageTest extends MediaWikiLangTestCase {
 
 
        /**
-        * @dataProvider dataIsCountable
+        * @dataProvider provideIsCountable
         */
        public function testIsCountable( $title, $model, $text, $mode, $expected ) {
-               global $wgArticleCountMethod;
+               global $wgContentHandlerUseDB;
+
+               $this->setMwGlobals( 'wgArticleCountMethod', $mode );
 
-               $oldArticleCountMethod = $wgArticleCountMethod;
-               $wgArticleCountMethod = $mode;
+               $title = Title::newFromText( $title );
+
+               if ( !$wgContentHandlerUseDB && ContentHandler::getDefaultModelFor( $title ) != $model ) {
+                       $this->markTestSkipped( "Can not use non-default content model $model for "
+                               . $title->getPrefixedDBkey() . " with \wgArticleCountMethod disabled." );
+               }
 
                $page = $this->createPage( $title, $text, $model );
                $hasLinks = wfGetDB( DB_SLAVE )->selectField( 'pagelinks', 1,
@@ -556,8 +560,6 @@ class WikiPageTest extends MediaWikiLangTestCase {
                $v = $page->isCountable();
                $w = $page->isCountable( $editInfo );
 
-               $wgArticleCountMethod = $oldArticleCountMethod;
-
                $this->assertEquals( $expected, $v, "isCountable( null ) returned unexpected value " . var_export( $v, true )
                                                                                        . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" );
 
@@ -565,7 +567,7 @@ class WikiPageTest extends MediaWikiLangTestCase {
                                                                                        . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" );
        }
 
-       public function dataGetParserOutput() {
+       public static function provideGetParserOutput() {
                return array(
                        array( CONTENT_MODEL_WIKITEXT, "hello ''world''\n", "<p>hello <i>world</i></p>"),
                        // @todo: more...?
@@ -573,12 +575,12 @@ class WikiPageTest extends MediaWikiLangTestCase {
        }
 
        /**
-        * @dataProvider dataGetParserOutput
+        * @dataProvider provideGetParserOutput
         */
        public function testGetParserOutput( $model, $text, $expectedHtml ) {
                $page = $this->createPage( 'WikiPageTest_testGetParserOutput', $text, $model );
 
-               $opt = new ParserOptions();
+               $opt = $page->makeParserOptions( 'canonical' );
                $po = $page->getParserOutput( $opt );
                $text = $po->getText();
 
@@ -589,6 +591,29 @@ class WikiPageTest extends MediaWikiLangTestCase {
                return $po;
        }
 
+       public function testGetParserOutput_nonexisting( ) {
+               static $count = 0;
+               $count ++;
+
+               $page = new WikiPage( new Title( "WikiPageTest_testGetParserOutput_nonexisting_$count" ) );
+
+               $opt = new ParserOptions();
+               $po = $page->getParserOutput( $opt );
+
+               $this->assertFalse( $po, "getParserOutput() shall return false for non-existing pages." );
+       }
+
+       public function testGetParserOutput_badrev( ) {
+               $page = $this->createPage( 'WikiPageTest_testGetParserOutput', "dummy", CONTENT_MODEL_WIKITEXT );
+
+               $opt = new ParserOptions();
+               $po = $page->getParserOutput( $opt, $page->getLatest() + 1234 );
+
+               //@todo: would be neat to also test deleted revision
+
+               $this->assertFalse( $po, "getParserOutput() shall return false for non-existing revisions." );
+       }
+
        static $sections =
 
                "Intro
@@ -819,7 +844,7 @@ more stuff
                $this->assertEquals( "one", $page->getContent()->getNativeData() );
        }
 
-       public function dataGetAutosummary( ) {
+       public static function provideGetAutosummary( ) {
                return array(
                        array(
                                'Hello there, world!',
@@ -861,7 +886,7 @@ more stuff
        }
 
        /**
-        * @dataProvider dataGetAutoSummary
+        * @dataProvider provideGetAutoSummary
         */
        public function testGetAutosummary( $old, $new, $flags, $expected ) {
                $this->hideDeprecated( "WikiPage::getAutosummary" );
@@ -874,7 +899,7 @@ more stuff
                                                        "Autosummary didn't match expected pattern $expected: $summary" );
        }
 
-       public function dataGetAutoDeleteReason( ) {
+       public static function provideGetAutoDeleteReason( ) {
                return array(
                        array(
                                array(),
@@ -933,7 +958,7 @@ more stuff
        }
 
        /**
-        * @dataProvider dataGetAutoDeleteReason
+        * @dataProvider provideGetAutoDeleteReason
         */
        public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) {
                global $wgUser;
@@ -968,7 +993,7 @@ more stuff
                $page->doDeleteArticle( "done" );
        }
 
-       public function dataPreSaveTransform() {
+       public static function providePreSaveTransform() {
                return array(
                        array( 'hello this is ~~~',
                                        "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
@@ -980,7 +1005,7 @@ more stuff
        }
 
        /**
-        * @dataProvider dataPreSaveTransform
+        * @dataProvider providePreSaveTransform
         */
        public function testPreSaveTransform( $text, $expected ) {
                $this->hideDeprecated( 'WikiPage::preSaveTransform' );