Merge "Add the main stash, WAN, and server caches to MediaWikiServices"
[lhc/web/wiklou.git] / tests / phpunit / includes / page / WikiPageTest.php
index 6d2b398..4b7ebd3 100644 (file)
@@ -10,12 +10,12 @@ class WikiPageTest extends MediaWikiLangTestCase {
 
        protected $pages_to_delete;
 
-       function __construct( $name = null, array $data = array(), $dataName = '' ) {
+       function __construct( $name = null, array $data = [], $dataName = '' ) {
                parent::__construct( $name, $data, $dataName );
 
                $this->tablesUsed = array_merge(
                        $this->tablesUsed,
-                       array( 'page',
+                       [ 'page',
                                'revision',
                                'text',
 
@@ -29,12 +29,12 @@ class WikiPageTest extends MediaWikiLangTestCase {
                                'externallinks',
                                'imagelinks',
                                'templatelinks',
-                               'iwlinks' ) );
+                               'iwlinks' ] );
        }
 
        protected function setUp() {
                parent::setUp();
-               $this->pages_to_delete = array();
+               $this->pages_to_delete = [];
 
                LinkCache::singleton()->clear(); # avoid cached redirect status, etc
        }
@@ -92,6 +92,9 @@ class WikiPageTest extends MediaWikiLangTestCase {
 
        /**
         * @covers WikiPage::doEditContent
+        * @covers WikiPage::doModify
+        * @covers WikiPage::doCreate
+        * @covers WikiPage::doEditUpdates
         */
        public function testDoEditContent() {
                $page = $this->newPage( "WikiPageTest_testDoEditContent" );
@@ -115,7 +118,7 @@ class WikiPageTest extends MediaWikiLangTestCase {
 
                # ------------------------
                $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
+               $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
                $n = $res->numRows();
                $res->free();
 
@@ -145,7 +148,7 @@ class WikiPageTest extends MediaWikiLangTestCase {
 
                # ------------------------
                $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
+               $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
                $n = $res->numRows();
                $res->free();
 
@@ -154,6 +157,7 @@ class WikiPageTest extends MediaWikiLangTestCase {
 
        /**
         * @covers WikiPage::doEdit
+        * @deprecated since 1.21. Should be removed when WikiPage::doEdit() gets removed
         */
        public function testDoEdit() {
                $this->hideDeprecated( "WikiPage::doEdit" );
@@ -179,7 +183,7 @@ class WikiPageTest extends MediaWikiLangTestCase {
 
                # ------------------------
                $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
+               $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
                $n = $res->numRows();
                $res->free();
 
@@ -205,37 +209,13 @@ class WikiPageTest extends MediaWikiLangTestCase {
 
                # ------------------------
                $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
+               $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
                $n = $res->numRows();
                $res->free();
 
                $this->assertEquals( 2, $n, 'pagelinks should contain two links from the page' );
        }
 
-       /**
-        * @covers WikiPage::doQuickEditContent
-        */
-       public function testDoQuickEditContent() {
-               global $wgUser;
-
-               $page = $this->createPage(
-                       "WikiPageTest_testDoQuickEditContent",
-                       "original text",
-                       CONTENT_MODEL_WIKITEXT
-               );
-
-               $content = ContentHandler::makeContent(
-                       "quick text",
-                       $page->getTitle(),
-                       CONTENT_MODEL_WIKITEXT
-               );
-               $page->doQuickEditContent( $content, $wgUser, "testing q" );
-
-               # ---------------------
-               $page = new WikiPage( $page->getTitle() );
-               $this->assertTrue( $content->equals( $page->getContent() ) );
-       }
-
        /**
         * @covers WikiPage::doDeleteArticle
         */
@@ -276,12 +256,12 @@ class WikiPageTest extends MediaWikiLangTestCase {
                // Run the job queue
                JobQueueGroup::destroySingletons();
                $jobs = new RunJobs;
-               $jobs->loadParamsAndArgs( null, array( 'quiet' => true ), null );
+               $jobs->loadParamsAndArgs( null, [ 'quiet' => true ], null );
                $jobs->execute();
 
                # ------------------------
                $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
+               $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
                $n = $res->numRows();
                $res->free();
 
@@ -300,18 +280,18 @@ class WikiPageTest extends MediaWikiLangTestCase {
                $id = $page->getId();
 
                // Similar to MovePage logic
-               wfGetDB( DB_MASTER )->delete( 'page', array( 'page_id' => $id ), __METHOD__ );
+               wfGetDB( DB_MASTER )->delete( 'page', [ 'page_id' => $id ], __METHOD__ );
                $page->doDeleteUpdates( $id );
 
                // Run the job queue
                JobQueueGroup::destroySingletons();
                $jobs = new RunJobs;
-               $jobs->loadParamsAndArgs( null, array( 'quiet' => true ), null );
+               $jobs->loadParamsAndArgs( null, [ 'quiet' => true ], null );
                $jobs->execute();
 
                # ------------------------
                $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
+               $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
                $n = $res->numRows();
                $res->free();
 
@@ -433,13 +413,13 @@ class WikiPageTest extends MediaWikiLangTestCase {
        }
 
        public static function provideHasViewableContent() {
-               return array(
-                       array( 'WikiPageTest_testHasViewableContent', false, true ),
-                       array( 'Special:WikiPageTest_testHasViewableContent', false ),
-                       array( 'MediaWiki:WikiPageTest_testHasViewableContent', false ),
-                       array( 'Special:Userlogin', true ),
-                       array( 'MediaWiki:help', true ),
-               );
+               return [
+                       [ 'WikiPageTest_testHasViewableContent', false, true ],
+                       [ 'Special:WikiPageTest_testHasViewableContent', false ],
+                       [ 'MediaWiki:WikiPageTest_testHasViewableContent', false ],
+                       [ 'Special:Userlogin', true ],
+                       [ 'MediaWiki:help', true ],
+               ];
        }
 
        /**
@@ -460,15 +440,15 @@ class WikiPageTest extends MediaWikiLangTestCase {
        }
 
        public static function provideGetRedirectTarget() {
-               return array(
-                       array( 'WikiPageTest_testGetRedirectTarget_1', CONTENT_MODEL_WIKITEXT, "hello world", null ),
-                       array(
+               return [
+                       [ 'WikiPageTest_testGetRedirectTarget_1', CONTENT_MODEL_WIKITEXT, "hello world", null ],
+                       [
                                'WikiPageTest_testGetRedirectTarget_2',
                                CONTENT_MODEL_WIKITEXT,
                                "#REDIRECT [[hello world]]",
                                "Hello world"
-                       ),
-               );
+                       ],
+               ];
        }
 
        /**
@@ -476,9 +456,9 @@ class WikiPageTest extends MediaWikiLangTestCase {
         * @covers WikiPage::getRedirectTarget
         */
        public function testGetRedirectTarget( $title, $model, $text, $target ) {
-               $this->setMwGlobals( array(
+               $this->setMwGlobals( [
                        'wgCapitalLinks' => true,
-               ) );
+               ] );
 
                $page = $this->createPage( $title, $text, $model );
 
@@ -501,110 +481,110 @@ class WikiPageTest extends MediaWikiLangTestCase {
        }
 
        public static function provideIsCountable() {
-               return array(
+               return [
 
                        // any
-                       array( 'WikiPageTest_testIsCountable',
+                       [ 'WikiPageTest_testIsCountable',
                                CONTENT_MODEL_WIKITEXT,
                                '',
                                'any',
                                true
-                       ),
-                       array( 'WikiPageTest_testIsCountable',
+                       ],
+                       [ 'WikiPageTest_testIsCountable',
                                CONTENT_MODEL_WIKITEXT,
                                'Foo',
                                'any',
                                true
-                       ),
+                       ],
 
                        // comma
-                       array( 'WikiPageTest_testIsCountable',
+                       [ 'WikiPageTest_testIsCountable',
                                CONTENT_MODEL_WIKITEXT,
                                'Foo',
                                'comma',
                                false
-                       ),
-                       array( 'WikiPageTest_testIsCountable',
+                       ],
+                       [ 'WikiPageTest_testIsCountable',
                                CONTENT_MODEL_WIKITEXT,
                                'Foo, bar',
                                'comma',
                                true
-                       ),
+                       ],
 
                        // link
-                       array( 'WikiPageTest_testIsCountable',
+                       [ 'WikiPageTest_testIsCountable',
                                CONTENT_MODEL_WIKITEXT,
                                'Foo',
                                'link',
                                false
-                       ),
-                       array( 'WikiPageTest_testIsCountable',
+                       ],
+                       [ 'WikiPageTest_testIsCountable',
                                CONTENT_MODEL_WIKITEXT,
                                'Foo [[bar]]',
                                'link',
                                true
-                       ),
+                       ],
 
                        // redirects
-                       array( 'WikiPageTest_testIsCountable',
+                       [ 'WikiPageTest_testIsCountable',
                                CONTENT_MODEL_WIKITEXT,
                                '#REDIRECT [[bar]]',
                                'any',
                                false
-                       ),
-                       array( 'WikiPageTest_testIsCountable',
+                       ],
+                       [ 'WikiPageTest_testIsCountable',
                                CONTENT_MODEL_WIKITEXT,
                                '#REDIRECT [[bar]]',
                                'comma',
                                false
-                       ),
-                       array( 'WikiPageTest_testIsCountable',
+                       ],
+                       [ 'WikiPageTest_testIsCountable',
                                CONTENT_MODEL_WIKITEXT,
                                '#REDIRECT [[bar]]',
                                'link',
                                false
-                       ),
+                       ],
 
                        // not a content namespace
-                       array( 'Talk:WikiPageTest_testIsCountable',
+                       [ 'Talk:WikiPageTest_testIsCountable',
                                CONTENT_MODEL_WIKITEXT,
                                'Foo',
                                'any',
                                false
-                       ),
-                       array( 'Talk:WikiPageTest_testIsCountable',
+                       ],
+                       [ 'Talk:WikiPageTest_testIsCountable',
                                CONTENT_MODEL_WIKITEXT,
                                'Foo, bar',
                                'comma',
                                false
-                       ),
-                       array( 'Talk:WikiPageTest_testIsCountable',
+                       ],
+                       [ 'Talk:WikiPageTest_testIsCountable',
                                CONTENT_MODEL_WIKITEXT,
                                'Foo [[bar]]',
                                'link',
                                false
-                       ),
+                       ],
 
                        // not a content namespace, different model
-                       array( 'MediaWiki:WikiPageTest_testIsCountable.js',
+                       [ 'MediaWiki:WikiPageTest_testIsCountable.js',
                                null,
                                'Foo',
                                'any',
                                false
-                       ),
-                       array( 'MediaWiki:WikiPageTest_testIsCountable.js',
+                       ],
+                       [ 'MediaWiki:WikiPageTest_testIsCountable.js',
                                null,
                                'Foo, bar',
                                'comma',
                                false
-                       ),
-                       array( 'MediaWiki:WikiPageTest_testIsCountable.js',
+                       ],
+                       [ 'MediaWiki:WikiPageTest_testIsCountable.js',
                                null,
                                'Foo [[bar]]',
                                'link',
                                false
-                       ),
-               );
+                       ],
+               ];
        }
 
        /**
@@ -651,10 +631,10 @@ class WikiPageTest extends MediaWikiLangTestCase {
        }
 
        public static function provideGetParserOutput() {
-               return array(
-                       array( CONTENT_MODEL_WIKITEXT, "hello ''world''\n", "<p>hello <i>world</i></p>" ),
+               return [
+                       [ CONTENT_MODEL_WIKITEXT, "hello ''world''\n", "<p>hello <i>world</i></p>" ],
                        // @todo more...?
-               );
+               ];
        }
 
        /**
@@ -721,24 +701,24 @@ more stuff
 
        public function dataReplaceSection() {
                // NOTE: assume the Help namespace to contain wikitext
-               return array(
-                       array( 'Help:WikiPageTest_testReplaceSection',
+               return [
+                       [ 'Help:WikiPageTest_testReplaceSection',
                                CONTENT_MODEL_WIKITEXT,
                                WikiPageTest::$sections,
                                "0",
                                "No more",
                                null,
                                trim( preg_replace( '/^Intro/sm', 'No more', WikiPageTest::$sections ) )
-                       ),
-                       array( 'Help:WikiPageTest_testReplaceSection',
+                       ],
+                       [ 'Help:WikiPageTest_testReplaceSection',
                                CONTENT_MODEL_WIKITEXT,
                                WikiPageTest::$sections,
                                "",
                                "No more",
                                null,
                                "No more"
-                       ),
-                       array( 'Help:WikiPageTest_testReplaceSection',
+                       ],
+                       [ 'Help:WikiPageTest_testReplaceSection',
                                CONTENT_MODEL_WIKITEXT,
                                WikiPageTest::$sections,
                                "2",
@@ -747,40 +727,24 @@ more stuff
                                trim( preg_replace( '/^== test ==.*== foo ==/sm',
                                        "== TEST ==\nmore fun\n\n== foo ==",
                                        WikiPageTest::$sections ) )
-                       ),
-                       array( 'Help:WikiPageTest_testReplaceSection',
+                       ],
+                       [ 'Help:WikiPageTest_testReplaceSection',
                                CONTENT_MODEL_WIKITEXT,
                                WikiPageTest::$sections,
                                "8",
                                "No more",
                                null,
                                trim( WikiPageTest::$sections )
-                       ),
-                       array( 'Help:WikiPageTest_testReplaceSection',
+                       ],
+                       [ 'Help:WikiPageTest_testReplaceSection',
                                CONTENT_MODEL_WIKITEXT,
                                WikiPageTest::$sections,
                                "new",
                                "No more",
                                "New",
                                trim( WikiPageTest::$sections ) . "\n\n== New ==\n\nNo more"
-                       ),
-               );
-       }
-
-       /**
-        * @dataProvider dataReplaceSection
-        * @covers WikiPage::replaceSection
-        */
-       public function testReplaceSection( $title, $model, $text, $section, $with,
-               $sectionTitle, $expected
-       ) {
-               $this->hideDeprecated( "WikiPage::replaceSection" );
-
-               $page = $this->createPage( $title, $text, $model );
-               $text = $page->replaceSection( $section, $with, $sectionTitle );
-               $text = trim( $text );
-
-               $this->assertEquals( $expected, $text );
+                       ],
+               ];
        }
 
        /**
@@ -917,7 +881,7 @@ more stuff
                # now, try the actual rollback
                $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
                $token = $admin->getEditToken(
-                       array( $page->getTitle()->getPrefixedText(), $user2->getName() ),
+                       [ $page->getTitle()->getPrefixedText(), $user2->getName() ],
                        null
                );
                $errors = $page->doRollback(
@@ -974,7 +938,7 @@ more stuff
                # now, try the rollback
                $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
                $token = $admin->getEditToken(
-                       array( $page->getTitle()->getPrefixedText(), $user1->getName() ),
+                       [ $page->getTitle()->getPrefixedText(), $user1->getName() ],
                        null
                );
                $errors = $page->doRollback(
@@ -1030,9 +994,9 @@ more stuff
                );
 
                # now, do a the rollback from the same user was doing the edit before
-               $resultDetails = array();
+               $resultDetails = [];
                $token = $user1->getEditToken(
-                       array( $page->getTitle()->getPrefixedText(), $user1->getName() ),
+                       [ $page->getTitle()->getPrefixedText(), $user1->getName() ],
                        null
                );
                $errors = $page->doRollback(
@@ -1044,12 +1008,12 @@ more stuff
                        $admin
                );
 
-               $this->assertEquals( array(), $errors, "Rollback failed same user" );
+               $this->assertEquals( [], $errors, "Rollback failed same user" );
 
                # now, try the rollback
-               $resultDetails = array();
+               $resultDetails = [];
                $token = $admin->getEditToken(
-                       array( $page->getTitle()->getPrefixedText(), $user1->getName() ),
+                       [ $page->getTitle()->getPrefixedText(), $user1->getName() ],
                        null
                );
                $errors = $page->doRollback(
@@ -1061,8 +1025,8 @@ more stuff
                        $admin
                );
 
-               $this->assertEquals( array( array( 'alreadyrolled', 'WikiPageTest testDoRollback',
-                       '127.0.1.11', 'Admin' ) ), $errors, "Rollback not failed" );
+               $this->assertEquals( [ [ 'alreadyrolled', 'WikiPageTest testDoRollback',
+                       '127.0.1.11', 'Admin' ] ], $errors, "Rollback not failed" );
 
                $page = new WikiPage( $page->getTitle() );
                $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
@@ -1071,29 +1035,29 @@ more stuff
        }
 
        public static function provideGetAutosummary() {
-               return array(
-                       array(
+               return [
+                       [
                                'Hello there, world!',
                                '#REDIRECT [[Foo]]',
                                0,
                                '/^Redirected page .*Foo/'
-                       ),
+                       ],
 
-                       array(
+                       [
                                null,
                                'Hello world!',
                                EDIT_NEW,
                                '/^Created page .*Hello/'
-                       ),
+                       ],
 
-                       array(
+                       [
                                'Hello there, world!',
                                '',
                                0,
                                '/^Blanked/'
-                       ),
+                       ],
 
-                       array(
+                       [
                                'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
                                eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
                                voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
@@ -1101,15 +1065,15 @@ more stuff
                                'Hello world!',
                                0,
                                '/^Replaced .*Hello/'
-                       ),
+                       ],
 
-                       array(
+                       [
                                'foo',
                                'bar',
                                0,
                                '/^$/'
-                       ),
-               );
+                       ],
+               ];
        }
 
        /**
@@ -1128,42 +1092,42 @@ more stuff
        }
 
        public static function provideGetAutoDeleteReason() {
-               return array(
-                       array(
-                               array(),
+               return [
+                       [
+                               [],
                                false,
                                false
-                       ),
+                       ],
 
-                       array(
-                               array(
-                                       array( "first edit", null ),
-                               ),
+                       [
+                               [
+                                       [ "first edit", null ],
+                               ],
                                "/first edit.*only contributor/",
                                false
-                       ),
+                       ],
 
-                       array(
-                               array(
-                                       array( "first edit", null ),
-                                       array( "second edit", null ),
-                               ),
+                       [
+                               [
+                                       [ "first edit", null ],
+                                       [ "second edit", null ],
+                               ],
                                "/second edit.*only contributor/",
                                true
-                       ),
+                       ],
 
-                       array(
-                               array(
-                                       array( "first edit", "127.0.2.22" ),
-                                       array( "second edit", "127.0.3.33" ),
-                               ),
+                       [
+                               [
+                                       [ "first edit", "127.0.2.22" ],
+                                       [ "second edit", "127.0.3.33" ],
+                               ],
                                "/second edit/",
                                true
-                       ),
+                       ],
 
-                       array(
-                               array(
-                                       array(
+                       [
+                               [
+                                       [
                                                "first edit: "
                                                        . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
                                                        . " nonumy eirmod tempor invidunt ut labore et dolore magna "
@@ -1171,22 +1135,22 @@ more stuff
                                                        . "et justo duo dolores et ea rebum. Stet clita kasd gubergren, "
                                                        . "no sea  takimata sanctus est Lorem ipsum dolor sit amet.'",
                                                null
-                                       ),
-                               ),
+                                       ],
+                               ],
                                '/first edit:.*\.\.\."/',
                                false
-                       ),
+                       ],
 
-                       array(
-                               array(
-                                       array( "first edit", "127.0.2.22" ),
-                                       array( "", "127.0.3.33" ),
-                               ),
+                       [
+                               [
+                                       [ "first edit", "127.0.2.22" ],
+                                       [ "", "127.0.3.33" ],
+                               ],
                                "/before blanking.*first edit/",
                                true
-                       ),
+                       ],
 
-               );
+               ];
        }
 
        /**
@@ -1233,14 +1197,14 @@ more stuff
        }
 
        public static function providePreSaveTransform() {
-               return array(
-                       array( 'hello this is ~~~',
+               return [
+                       [ 'hello this is ~~~',
                                "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
-                       ),
-                       array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
+                       ],
+                       [ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
                                'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
-                       ),
-               );
+                       ],
+               ];
        }
 
        /**