Use GenderCache service in ApiQueryWatchlistIntegrationTest
[lhc/web/wiklou.git] / tests / phpunit / includes / RevisionStorageTest.php
index e69660e..7d3007b 100644 (file)
  * ^--- important, causes tests not to fail with timeout
  */
 class RevisionStorageTest extends MediaWikiTestCase {
-
        /**
         * @var WikiPage $the_page
         */
-       var $the_page;
+       private $the_page;
 
-       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',
 
@@ -35,7 +34,7 @@ class RevisionStorageTest extends MediaWikiTestCase {
                                'externallinks',
                                'imagelinks',
                                'templatelinks',
-                               'iwlinks' ) );
+                               'iwlinks' ] );
        }
 
        protected function setUp() {
@@ -52,8 +51,14 @@ class RevisionStorageTest extends MediaWikiTestCase {
                MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
                $wgContLang->resetNamespaces(); # reset namespace cache
                if ( !$this->the_page ) {
-                       $this->the_page = $this->createPage( 'RevisionStorageTest_the_page', "just a dummy page", CONTENT_MODEL_WIKITEXT );
+                       $this->the_page = $this->createPage(
+                               'RevisionStorageTest_the_page',
+                               "just a dummy page",
+                               CONTENT_MODEL_WIKITEXT
+                       );
                }
+
+               $this->tablesUsed[] = 'archive';
        }
 
        protected function tearDown() {
@@ -73,7 +78,7 @@ class RevisionStorageTest extends MediaWikiTestCase {
 
        protected function makeRevision( $props = null ) {
                if ( $props === null ) {
-                       $props = array();
+                       $props = [];
                }
 
                if ( !isset( $props['content'] ) && !isset( $props['text'] ) ) {
@@ -90,7 +95,7 @@ class RevisionStorageTest extends MediaWikiTestCase {
 
                $rev = new Revision( $props );
 
-               $dbw = wfgetDB( DB_MASTER );
+               $dbw = wfGetDB( DB_MASTER );
                $rev->insertOn( $dbw );
 
                return $rev;
@@ -140,8 +145,8 @@ class RevisionStorageTest extends MediaWikiTestCase {
        public function testConstructFromRow() {
                $orig = $this->makeRevision();
 
-               $dbr = wfgetDB( DB_SLAVE );
-               $res = $dbr->select( 'revision', '*', array( 'rev_id' => $orig->getId() ) );
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select( 'revision', '*', [ 'rev_id' => $orig->getId() ] );
                $this->assertTrue( is_object( $res ), 'query failed' );
 
                $row = $res->fetchObject();
@@ -158,8 +163,8 @@ class RevisionStorageTest extends MediaWikiTestCase {
        public function testNewFromRow() {
                $orig = $this->makeRevision();
 
-               $dbr = wfgetDB( DB_SLAVE );
-               $res = $dbr->select( 'revision', '*', array( 'rev_id' => $orig->getId() ) );
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select( 'revision', '*', [ 'rev_id' => $orig->getId() ] );
                $this->assertTrue( is_object( $res ), 'query failed' );
 
                $row = $res->fetchObject();
@@ -174,12 +179,16 @@ class RevisionStorageTest extends MediaWikiTestCase {
         * @covers Revision::newFromArchiveRow
         */
        public function testNewFromArchiveRow() {
-               $page = $this->createPage( 'RevisionStorageTest_testNewFromArchiveRow', 'Lorem Ipsum', CONTENT_MODEL_WIKITEXT );
+               $page = $this->createPage(
+                       'RevisionStorageTest_testNewFromArchiveRow',
+                       'Lorem Ipsum',
+                       CONTENT_MODEL_WIKITEXT
+               );
                $orig = $page->getRevision();
                $page->doDeleteArticle( 'test Revision::newFromArchiveRow' );
 
-               $dbr = wfgetDB( DB_SLAVE );
-               $res = $dbr->select( 'archive', '*', array( 'ar_rev_id' => $orig->getId() ) );
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select( 'archive', '*', [ 'ar_rev_id' => $orig->getId() ] );
                $this->assertTrue( is_object( $res ), 'query failed' );
 
                $row = $res->fetchObject();
@@ -205,7 +214,11 @@ class RevisionStorageTest extends MediaWikiTestCase {
         * @covers Revision::fetchRevision
         */
        public function testFetchRevision() {
-               $page = $this->createPage( 'RevisionStorageTest_testFetchRevision', 'one', CONTENT_MODEL_WIKITEXT );
+               $page = $this->createPage(
+                       'RevisionStorageTest_testFetchRevision',
+                       'one',
+                       CONTENT_MODEL_WIKITEXT
+               );
 
                // Hidden process cache assertion below
                $page->getRevision()->getId();
@@ -215,8 +228,8 @@ class RevisionStorageTest extends MediaWikiTestCase {
 
                $res = Revision::fetchRevision( $page->getTitle() );
 
-               #note: order is unspecified
-               $rows = array();
+               # note: order is unspecified
+               $rows = [];
                while ( ( $row = $res->fetchObject() ) ) {
                        $rows[$row->rev_id] = $row;
                }
@@ -235,7 +248,10 @@ class RevisionStorageTest extends MediaWikiTestCase {
 
                $this->assertTrue( in_array( 'rev_id', $fields ), 'missing rev_id in list of fields' );
                $this->assertTrue( in_array( 'rev_page', $fields ), 'missing rev_page in list of fields' );
-               $this->assertTrue( in_array( 'rev_timestamp', $fields ), 'missing rev_timestamp in list of fields' );
+               $this->assertTrue(
+                       in_array( 'rev_timestamp', $fields ),
+                       'missing rev_timestamp in list of fields'
+               );
                $this->assertTrue( in_array( 'rev_user', $fields ), 'missing rev_user in list of fields' );
 
                if ( $wgContentHandlerUseDB ) {
@@ -252,7 +268,7 @@ class RevisionStorageTest extends MediaWikiTestCase {
        public function testGetPage() {
                $page = $this->the_page;
 
-               $orig = $this->makeRevision( array( 'page' => $page->getId() ) );
+               $orig = $this->makeRevision( [ 'page' => $page->getId() ] );
                $rev = Revision::newFromId( $orig->getId() );
 
                $this->assertEquals( $page->getId(), $rev->getPage() );
@@ -264,7 +280,7 @@ class RevisionStorageTest extends MediaWikiTestCase {
        public function testGetText() {
                $this->hideDeprecated( 'Revision::getText' );
 
-               $orig = $this->makeRevision( array( 'text' => 'hello hello.' ) );
+               $orig = $this->makeRevision( [ 'text' => 'hello hello.' ] );
                $rev = Revision::newFromId( $orig->getId() );
 
                $this->assertEquals( 'hello hello.', $rev->getText() );
@@ -274,16 +290,16 @@ class RevisionStorageTest extends MediaWikiTestCase {
         * @covers Revision::getContent
         */
        public function testGetContent_failure() {
-               $rev = new Revision( array(
+               $rev = new Revision( [
                        'page' => $this->the_page->getId(),
                        'content_model' => $this->the_page->getContentModel(),
                        'text_id' => 123456789, // not in the test DB
-               ) );
+               ] );
 
                $this->assertNull( $rev->getContent(),
                        "getContent() should return null if the revision's text blob could not be loaded." );
 
-               //NOTE: check this twice, once for lazy initialization, and once with the cached value.
+               // NOTE: check this twice, once for lazy initialization, and once with the cached value.
                $this->assertNull( $rev->getContent(),
                        "getContent() should return null if the revision's text blob could not be loaded." );
        }
@@ -292,24 +308,12 @@ class RevisionStorageTest extends MediaWikiTestCase {
         * @covers Revision::getContent
         */
        public function testGetContent() {
-               $orig = $this->makeRevision( array( 'text' => 'hello hello.' ) );
+               $orig = $this->makeRevision( [ 'text' => 'hello hello.' ] );
                $rev = Revision::newFromId( $orig->getId() );
 
                $this->assertEquals( 'hello hello.', $rev->getContent()->getNativeData() );
        }
 
-       /**
-        * @covers Revision::getRawText
-        */
-       public function testGetRawText() {
-               $this->hideDeprecated( 'Revision::getRawText' );
-
-               $orig = $this->makeRevision( array( 'text' => 'hello hello raw.' ) );
-               $rev = Revision::newFromId( $orig->getId() );
-
-               $this->assertEquals( 'hello hello raw.', $rev->getRawText() );
-       }
-
        /**
         * @covers Revision::getContentModel
         */
@@ -320,8 +324,8 @@ class RevisionStorageTest extends MediaWikiTestCase {
                        $this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
                }
 
-               $orig = $this->makeRevision( array( 'text' => 'hello hello.',
-                       'content_model' => CONTENT_MODEL_JAVASCRIPT ) );
+               $orig = $this->makeRevision( [ 'text' => 'hello hello.',
+                       'content_model' => CONTENT_MODEL_JAVASCRIPT ] );
                $rev = Revision::newFromId( $orig->getId() );
 
                $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() );
@@ -337,11 +341,11 @@ class RevisionStorageTest extends MediaWikiTestCase {
                        $this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
                }
 
-               $orig = $this->makeRevision( array(
+               $orig = $this->makeRevision( [
                        'text' => 'hello hello.',
                        'content_model' => CONTENT_MODEL_JAVASCRIPT,
                        'content_format' => CONTENT_FORMAT_JAVASCRIPT
-               ) );
+               ] );
                $rev = Revision::newFromId( $orig->getId() );
 
                $this->assertEquals( CONTENT_FORMAT_JAVASCRIPT, $rev->getContentFormat() );
@@ -351,7 +355,11 @@ class RevisionStorageTest extends MediaWikiTestCase {
         * @covers Revision::isCurrent
         */
        public function testIsCurrent() {
-               $page = $this->createPage( 'RevisionStorageTest_testIsCurrent', 'Lorem Ipsum', CONTENT_MODEL_WIKITEXT );
+               $page = $this->createPage(
+                       'RevisionStorageTest_testIsCurrent',
+                       'Lorem Ipsum',
+                       CONTENT_MODEL_WIKITEXT
+               );
                $rev1 = $page->getRevision();
 
                # @todo find out if this should be true
@@ -360,7 +368,10 @@ class RevisionStorageTest extends MediaWikiTestCase {
                $rev1x = Revision::newFromId( $rev1->getId() );
                $this->assertTrue( $rev1x->isCurrent() );
 
-               $page->doEditContent( ContentHandler::makeContent( 'Bla bla', $page->getTitle(), CONTENT_MODEL_WIKITEXT ), 'second rev' );
+               $page->doEditContent(
+                       ContentHandler::makeContent( 'Bla bla', $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
+                       'second rev'
+               );
                $rev2 = $page->getRevision();
 
                # @todo find out if this should be true
@@ -377,12 +388,17 @@ class RevisionStorageTest extends MediaWikiTestCase {
         * @covers Revision::getPrevious
         */
        public function testGetPrevious() {
-               $page = $this->createPage( 'RevisionStorageTest_testGetPrevious', 'Lorem Ipsum testGetPrevious', CONTENT_MODEL_WIKITEXT );
+               $page = $this->createPage(
+                       'RevisionStorageTest_testGetPrevious',
+                       'Lorem Ipsum testGetPrevious',
+                       CONTENT_MODEL_WIKITEXT
+               );
                $rev1 = $page->getRevision();
 
                $this->assertNull( $rev1->getPrevious() );
 
-               $page->doEditContent( ContentHandler::makeContent( 'Bla bla', $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
+               $page->doEditContent(
+                       ContentHandler::makeContent( 'Bla bla', $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
                        'second rev testGetPrevious' );
                $rev2 = $page->getRevision();
 
@@ -394,13 +410,19 @@ class RevisionStorageTest extends MediaWikiTestCase {
         * @covers Revision::getNext
         */
        public function testGetNext() {
-               $page = $this->createPage( 'RevisionStorageTest_testGetNext', 'Lorem Ipsum testGetNext', CONTENT_MODEL_WIKITEXT );
+               $page = $this->createPage(
+                       'RevisionStorageTest_testGetNext',
+                       'Lorem Ipsum testGetNext',
+                       CONTENT_MODEL_WIKITEXT
+               );
                $rev1 = $page->getRevision();
 
                $this->assertNull( $rev1->getNext() );
 
-               $page->doEditContent( ContentHandler::makeContent( 'Bla bla', $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
-                       'second rev testGetNext' );
+               $page->doEditContent(
+                       ContentHandler::makeContent( 'Bla bla', $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
+                       'second rev testGetNext'
+               );
                $rev2 = $page->getRevision();
 
                $this->assertNotNull( $rev1->getNext() );
@@ -411,7 +433,11 @@ class RevisionStorageTest extends MediaWikiTestCase {
         * @covers Revision::newNullRevision
         */
        public function testNewNullRevision() {
-               $page = $this->createPage( 'RevisionStorageTest_testNewNullRevision', 'some testing text', CONTENT_MODEL_WIKITEXT );
+               $page = $this->createPage(
+                       'RevisionStorageTest_testNewNullRevision',
+                       'some testing text',
+                       CONTENT_MODEL_WIKITEXT
+               );
                $orig = $page->getRevision();
 
                $dbw = wfGetDB( DB_MASTER );
@@ -425,20 +451,20 @@ class RevisionStorageTest extends MediaWikiTestCase {
        }
 
        public static function provideUserWasLastToEdit() {
-               return array(
-                       array( #0
+               return [
+                       [ # 0
                                3, true, # actually the last edit
-                       ),
-                       array( #1
+                       ],
+                       [ # 1
                                2, true, # not the current edit, but still by this user
-                       ),
-                       array( #2
+                       ],
+                       [ # 2
                                1, false, # edit by another user
-                       ),
-                       array( #3
+                       ],
+                       [ # 3
                                0, false, # first edit, by this user, but another user edited in the mean time
-                       ),
-               );
+                       ],
+               ];
        }
 
        /**
@@ -459,7 +485,7 @@ class RevisionStorageTest extends MediaWikiTestCase {
                $ns = $this->getDefaultWikitextNS();
 
                $dbw = wfGetDB( DB_MASTER );
-               $revisions = array();
+               $revisions = [];
 
                // create revisions -----------------------------
                $page = WikiPage::factory( Title::newFromText(
@@ -467,31 +493,33 @@ class RevisionStorageTest extends MediaWikiTestCase {
                $page->insertOn( $dbw );
 
                # zero
-               $revisions[0] = new Revision( array(
+               $revisions[0] = new Revision( [
                        'page' => $page->getId(),
-                       'title' => $page->getTitle(), // we need the title to determine the page's default content model
+                       // we need the title to determine the page's default content model
+                       'title' => $page->getTitle(),
                        'timestamp' => '20120101000000',
                        'user' => $userA->getId(),
                        'text' => 'zero',
                        'content_model' => CONTENT_MODEL_WIKITEXT,
                        'summary' => 'edit zero'
-               ) );
+               ] );
                $revisions[0]->insertOn( $dbw );
 
                # one
-               $revisions[1] = new Revision( array(
+               $revisions[1] = new Revision( [
                        'page' => $page->getId(),
-                       'title' => $page->getTitle(), // still need the title, because $page->getId() is 0 (there's no entry in the page table)
+                       // still need the title, because $page->getId() is 0 (there's no entry in the page table)
+                       'title' => $page->getTitle(),
                        'timestamp' => '20120101000100',
                        'user' => $userA->getId(),
                        'text' => 'one',
                        'content_model' => CONTENT_MODEL_WIKITEXT,
                        'summary' => 'edit one'
-               ) );
+               ] );
                $revisions[1]->insertOn( $dbw );
 
                # two
-               $revisions[2] = new Revision( array(
+               $revisions[2] = new Revision( [
                        'page' => $page->getId(),
                        'title' => $page->getTitle(),
                        'timestamp' => '20120101000200',
@@ -499,11 +527,11 @@ class RevisionStorageTest extends MediaWikiTestCase {
                        'text' => 'two',
                        'content_model' => CONTENT_MODEL_WIKITEXT,
                        'summary' => 'edit two'
-               ) );
+               ] );
                $revisions[2]->insertOn( $dbw );
 
                # three
-               $revisions[3] = new Revision( array(
+               $revisions[3] = new Revision( [
                        'page' => $page->getId(),
                        'title' => $page->getTitle(),
                        'timestamp' => '20120101000300',
@@ -511,11 +539,11 @@ class RevisionStorageTest extends MediaWikiTestCase {
                        'text' => 'three',
                        'content_model' => CONTENT_MODEL_WIKITEXT,
                        'summary' => 'edit three'
-               ) );
+               ] );
                $revisions[3]->insertOn( $dbw );
 
                # four
-               $revisions[4] = new Revision( array(
+               $revisions[4] = new Revision( [
                        'page' => $page->getId(),
                        'title' => $page->getTitle(),
                        'timestamp' => '20120101000200',
@@ -523,7 +551,7 @@ class RevisionStorageTest extends MediaWikiTestCase {
                        'text' => 'zero',
                        'content_model' => CONTENT_MODEL_WIKITEXT,
                        'summary' => 'edit four'
-               ) );
+               ] );
                $revisions[4]->insertOn( $dbw );
 
                // test it ---------------------------------