Merge "Fix wrong @return type hints in Language::tsTo… methods"
[lhc/web/wiklou.git] / tests / phpunit / includes / deferred / LinksUpdateTest.php
index 016a7aa..3309352 100644 (file)
@@ -6,13 +6,13 @@
  * ^--- make sure temporary tables are used.
  */
 class LinksUpdateTest extends MediaWikiLangTestCase {
-       protected $testingPageId;
+       protected static $testingPageId;
 
-       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(
+                       [
                                'interwiki',
                                'page_props',
                                'pagelinks',
@@ -23,7 +23,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                                'templatelinks',
                                'iwlinks',
                                'recentchanges',
-                       )
+                       ]
                );
        }
 
@@ -32,22 +32,22 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                $dbw = wfGetDB( DB_MASTER );
                $dbw->replace(
                        'interwiki',
-                       array( 'iw_prefix' ),
-                       array(
+                       [ 'iw_prefix' ],
+                       [
                                'iw_prefix' => 'linksupdatetest',
                                'iw_url' => 'http://testing.com/wiki/$1',
                                'iw_api' => 'http://testing.com/w/api.php',
                                'iw_local' => 0,
                                'iw_trans' => 0,
                                'iw_wikiid' => 'linksupdatetest',
-                       )
+                       ]
                );
                $this->setMwGlobals( 'wgRCWatchCategoryMembership', true );
        }
 
-       public function addDBData() {
+       public function addDBDataOnce() {
                $res = $this->insertPage( 'Testing' );
-               $this->testingPageId = $res['id'];
+               self::$testingPageId = $res['id'];
                $this->insertPage( 'Some_other_page' );
                $this->insertPage( 'Template:TestingTemplate' );
        }
@@ -59,7 +59,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                $po = new ParserOutput();
                $po->setTitleText( $t->getPrefixedText() );
 
-               return array( $t, $po );
+               return [ $t, $po ];
        }
 
        /**
@@ -68,7 +68,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
        public function testUpdate_pagelinks() {
                /** @var Title $t */
                /** @var ParserOutput $po */
-               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId );
+               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
 
                $po->addLink( Title::newFromText( "Foo" ) );
                $po->addLink( Title::newFromText( "Special:Foo" ) ); // special namespace should be ignored
@@ -81,12 +81,12 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                        'pagelinks',
                        'pl_namespace,
                        pl_title',
-                       'pl_from = ' . $this->testingPageId,
-                       array( array( NS_MAIN, 'Foo' ) )
+                       'pl_from = ' . self::$testingPageId,
+                       [ [ NS_MAIN, 'Foo' ] ]
                );
-               $this->assertArrayEquals( array(
+               $this->assertArrayEquals( [
                        Title::makeTitle( NS_MAIN, 'Foo' ),  // newFromText doesn't yield the same internal state....
-               ), $update->getAddedLinks() );
+               ], $update->getAddedLinks() );
 
                $po = new ParserOutput();
                $po->setTitleText( $t->getPrefixedText() );
@@ -100,19 +100,19 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                        'pagelinks',
                        'pl_namespace,
                        pl_title',
-                       'pl_from = ' . $this->testingPageId,
-                       array(
-                               array( NS_MAIN, 'Bar' ),
-                               array( NS_TALK, 'Bar' ),
-                       )
+                       'pl_from = ' . self::$testingPageId,
+                       [
+                               [ NS_MAIN, 'Bar' ],
+                               [ NS_TALK, 'Bar' ],
+                       ]
                );
-               $this->assertArrayEquals( array(
+               $this->assertArrayEquals( [
                        Title::makeTitle( NS_MAIN, 'Bar' ),
                        Title::makeTitle( NS_TALK, 'Bar' ),
-               ), $update->getAddedLinks() );
-               $this->assertArrayEquals( array(
+               ], $update->getAddedLinks() );
+               $this->assertArrayEquals( [
                        Title::makeTitle( NS_MAIN, 'Foo' ),
-               ), $update->getRemovedLinks() );
+               ], $update->getRemovedLinks() );
        }
 
        /**
@@ -120,7 +120,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
         */
        public function testUpdate_externallinks() {
                /** @var ParserOutput $po */
-               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId );
+               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
 
                $po->addExternalLink( "http://testing.com/wiki/Foo" );
 
@@ -129,10 +129,10 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                        $po,
                        'externallinks',
                        'el_to, el_index',
-                       'el_from = ' . $this->testingPageId,
-                       array(
-                               array( 'http://testing.com/wiki/Foo', 'http://com.testing./wiki/Foo' ),
-                       )
+                       'el_from = ' . self::$testingPageId,
+                       [
+                               [ 'http://testing.com/wiki/Foo', 'http://com.testing./wiki/Foo' ],
+                       ]
                );
        }
 
@@ -143,7 +143,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                /** @var ParserOutput $po */
                $this->setMwGlobals( 'wgCategoryCollation', 'uppercase' );
 
-               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId );
+               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
 
                $po->addCategory( "Foo", "FOO" );
 
@@ -152,8 +152,8 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                        $po,
                        'categorylinks',
                        'cl_to, cl_sortkey',
-                       'cl_from = ' . $this->testingPageId,
-                       array( array( 'Foo', "FOO\nTESTING" ) )
+                       'cl_from = ' . self::$testingPageId,
+                       [ [ 'Foo', "FOO\nTESTING" ] ]
                );
        }
 
@@ -169,7 +169,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                        $title,
                        $wikiPage->getParserOutput( new ParserOptions() ),
                        Title::newFromText( 'Category:Foo' ),
-                       array( array( 'Foo', '[[:Testing]] added to category' ) )
+                       [ [ 'Foo', '[[:Testing]] added to category' ] ]
                );
 
                $wikiPage->doEditContent( new WikitextContent( '[[Category:Bar]]' ), 'replaced category' );
@@ -179,19 +179,19 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                        $title,
                        $wikiPage->getParserOutput( new ParserOptions() ),
                        Title::newFromText( 'Category:Foo' ),
-                       array(
-                               array( 'Foo', '[[:Testing]] added to category' ),
-                               array( 'Foo', '[[:Testing]] removed from category' ),
-                       )
+                       [
+                               [ 'Foo', '[[:Testing]] added to category' ],
+                               [ 'Foo', '[[:Testing]] removed from category' ],
+                       ]
                );
 
                $this->assertRecentChangeByCategorization(
                        $title,
                        $wikiPage->getParserOutput( new ParserOptions() ),
                        Title::newFromText( 'Category:Bar' ),
-                       array(
-                               array( 'Bar', '[[:Testing]] added to category' ),
-                       )
+                       [
+                               [ 'Bar', '[[:Testing]] added to category' ],
+                       ]
                );
        }
 
@@ -213,7 +213,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                        $templateTitle,
                        $templatePage->getParserOutput( new ParserOptions() ),
                        Title::newFromText( 'Baz' ),
-                       array()
+                       []
                );
 
                $templatePage->doEditContent( new WikitextContent( '[[Category:Baz]]' ), 'added category' );
@@ -223,7 +223,11 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                        $templateTitle,
                        $templatePage->getParserOutput( new ParserOptions() ),
                        Title::newFromText( 'Baz' ),
-                       array( array( 'Baz', '[[:Template:TestingTemplate]] and 2 pages added to category' ) )
+                       [ [
+                               'Baz',
+                               '[[:Template:TestingTemplate]] added to category, ' .
+                               '[[Special:WhatLinksHere/Template:TestingTemplate|this page is included within other pages]]'
+                       ] ]
                );
        }
 
@@ -232,7 +236,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
         */
        public function testUpdate_iwlinks() {
                /** @var ParserOutput $po */
-               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId );
+               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
 
                $target = Title::makeTitleSafe( NS_MAIN, "Foo", '', 'linksupdatetest' );
                $po->addInterwikiLink( $target );
@@ -242,8 +246,8 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                        $po,
                        'iwlinks',
                        'iwl_prefix, iwl_title',
-                       'iwl_from = ' . $this->testingPageId,
-                       array( array( 'linksupdatetest', 'Foo' ) )
+                       'iwl_from = ' . self::$testingPageId,
+                       [ [ 'linksupdatetest', 'Foo' ] ]
                );
        }
 
@@ -252,7 +256,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
         */
        public function testUpdate_templatelinks() {
                /** @var ParserOutput $po */
-               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId );
+               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
 
                $po->addTemplate( Title::newFromText( "Template:Foo" ), 23, 42 );
 
@@ -262,8 +266,8 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                        'templatelinks',
                        'tl_namespace,
                        tl_title',
-                       'tl_from = ' . $this->testingPageId,
-                       array( array( NS_TEMPLATE, 'Foo' ) )
+                       'tl_from = ' . self::$testingPageId,
+                       [ [ NS_TEMPLATE, 'Foo' ] ]
                );
        }
 
@@ -272,7 +276,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
         */
        public function testUpdate_imagelinks() {
                /** @var ParserOutput $po */
-               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId );
+               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
 
                $po->addImage( "Foo.png" );
 
@@ -281,8 +285,8 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                        $po,
                        'imagelinks',
                        'il_to',
-                       'il_from = ' . $this->testingPageId,
-                       array( array( 'Foo.png' ) )
+                       'il_from = ' . self::$testingPageId,
+                       [ [ 'Foo.png' ] ]
                );
        }
 
@@ -290,12 +294,12 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
         * @covers ParserOutput::addLanguageLink
         */
        public function testUpdate_langlinks() {
-               $this->setMwGlobals( array(
+               $this->setMwGlobals( [
                        'wgCapitalLinks' => true,
-               ) );
+               ] );
 
                /** @var ParserOutput $po */
-               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId );
+               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
 
                $po->addLanguageLink( Title::newFromText( "en:Foo" )->getFullText() );
 
@@ -304,8 +308,8 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                        $po,
                        'langlinks',
                        'll_lang, ll_title',
-                       'll_from = ' . $this->testingPageId,
-                       array( array( 'En', 'Foo' ) )
+                       'll_from = ' . self::$testingPageId,
+                       [ [ 'En', 'Foo' ] ]
                );
        }
 
@@ -316,22 +320,22 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                global $wgPagePropsHaveSortkey;
 
                /** @var ParserOutput $po */
-               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId );
+               list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
 
-               $fields = array( 'pp_propname', 'pp_value' );
-               $expected = array();
+               $fields = [ 'pp_propname', 'pp_value' ];
+               $expected = [];
 
                $po->setProperty( "bool", true );
-               $expected[] = array( "bool", true );
+               $expected[] = [ "bool", true ];
 
                $po->setProperty( "float", 4.0 + 1.0 / 4.0 );
-               $expected[] = array( "float", 4.0 + 1.0 / 4.0 );
+               $expected[] = [ "float", 4.0 + 1.0 / 4.0 ];
 
                $po->setProperty( "int", -7 );
-               $expected[] = array( "int", -7 );
+               $expected[] = [ "int", -7 ];
 
                $po->setProperty( "string", "33 bar" );
-               $expected[] = array( "string", "33 bar" );
+               $expected[] = [ "string", "33 bar" ];
 
                // compute expected sortkey values
                if ( $wgPagePropsHaveSortkey ) {
@@ -349,7 +353,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                }
 
                $this->assertLinksUpdate(
-                       $t, $po, 'page_props', $fields, 'pp_page = ' . $this->testingPageId, $expected );
+                       $t, $po, 'page_props', $fields, 'pp_page = ' . self::$testingPageId, $expected );
        }
 
        public function testUpdate_page_props_without_sortkey() {
@@ -380,11 +384,11 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
                $this->assertSelect(
                        'recentchanges',
                        'rc_title, rc_comment',
-                       array(
+                       [
                                'rc_type' => RC_CATEGORIZE,
                                'rc_namespace' => NS_CATEGORY,
                                'rc_title' => $categoryTitle->getDBkey()
-                       ),
+                       ],
                        $expectedRows
                );
        }