Merge "Accessor to get EditPage parent revision ID"
[lhc/web/wiklou.git] / tests / phpunit / includes / deferred / LinksUpdateTest.php
index bbd196d..25ee5ec 100644 (file)
@@ -19,7 +19,8 @@ class LinksUpdateTest extends MediaWikiTestCase {
                                'externallinks',
                                'imagelinks',
                                'templatelinks',
-                               'iwlinks'
+                               'iwlinks',
+                               'recentchanges',
                        )
                );
        }
@@ -39,6 +40,13 @@ class LinksUpdateTest extends MediaWikiTestCase {
                                'iw_wikiid' => 'linksupdatetest',
                        )
                );
+               $this->setMwGlobals( 'wgRCWatchCategoryMembership', true );
+       }
+
+       public function addDBData() {
+               $this->insertPage( 'Testing' );
+               $this->insertPage( 'Some_other_page' );
+               $this->insertPage( 'Template:TestingTemplate' );
        }
 
        protected function makeTitleAndParserOutput( $name, $id ) {
@@ -133,6 +141,61 @@ class LinksUpdateTest extends MediaWikiTestCase {
                ) );
        }
 
+       public function testOnAddingAndRemovingCategory_recentChangesRowIsAdded() {
+               $this->setMwGlobals( 'wgCategoryCollation', 'uppercase' );
+
+               $title = Title::newFromText( 'Testing' );
+               $wikiPage = new WikiPage( $title );
+               $wikiPage->doEditContent( new WikitextContent( '[[Category:Foo]]' ), 'added category' );
+
+               $this->assertRecentChangeByCategorization(
+                       $title,
+                       $wikiPage->getParserOutput( new ParserOptions() ),
+                       Title::newFromText( 'Category:Foo' ),
+                       array( array( 'Foo', '[[:Testing]] added to category' ) )
+               );
+
+               $wikiPage->doEditContent( new WikitextContent( '[[Category:Bar]]' ), 'added category' );
+               $this->assertRecentChangeByCategorization(
+                       $title,
+                       $wikiPage->getParserOutput( new ParserOptions() ),
+                       Title::newFromText( 'Category:Foo' ),
+                       array(
+                               array( 'Foo', '[[:Testing]] added to category' ),
+                               array( 'Foo', '[[:Testing]] removed from category' ),
+                       )
+               );
+
+               $this->assertRecentChangeByCategorization(
+                       $title,
+                       $wikiPage->getParserOutput( new ParserOptions() ),
+                       Title::newFromText( 'Category:Bar' ),
+                       array(
+                               array( 'Bar', '[[:Testing]] added to category' ),
+                       )
+               );
+       }
+
+       public function testOnAddingAndRemovingCategoryToTemplates_embeddingPagesAreIgnored() {
+               $this->setMwGlobals( 'wgCategoryCollation', 'uppercase' );
+
+               $templateTitle = Title::newFromText( 'Template:TestingTemplate' );
+               $templatePage = new WikiPage( $templateTitle );
+
+               $wikiPage = new WikiPage( Title::newFromText( 'Testing' ) );
+               $wikiPage->doEditContent( new WikitextContent( '{{TestingTemplate}}' ), 'added template' );
+               $otherWikiPage = new WikiPage( Title::newFromText( 'Some_other_page' ) );
+               $otherWikiPage->doEditContent( new WikitextContent( '{{TestingTemplate}}' ), 'added template' );
+               $templatePage->doEditContent( new WikitextContent( '[[Category:Foo]]' ), 'added category' );
+
+               $this->assertRecentChangeByCategorization(
+                       $templateTitle,
+                       $templatePage->getParserOutput( new ParserOptions() ),
+                       Title::newFromText( 'Foo' ),
+                       array( array( 'Foo', '[[:Template:TestingTemplate]] and 2 pages added to category' ) )
+               );
+       }
+
        /**
         * @covers ParserOutput::addInterwikiLink
         */
@@ -263,4 +326,26 @@ class LinksUpdateTest extends MediaWikiTestCase {
                $this->assertSelect( $table, $fields, $condition, $expectedRows );
                return $update;
        }
+
+       protected function assertRecentChangeByCategorization(
+               Title $pageTitle, ParserOutput $parserOutput, Title $categoryTitle, $expectedRows
+       ) {
+               $update = new LinksUpdate( $pageTitle, $parserOutput );
+               $revision = Revision::newFromTitle( $pageTitle );
+               $update->setRevision( $revision );
+               $update->beginTransaction();
+               $update->doUpdate();
+               $update->commitTransaction();
+
+               $this->assertSelect(
+                       'recentchanges',
+                       'rc_title, rc_comment',
+                       array(
+                               'rc_type' => RC_CATEGORIZE,
+                               'rc_namespace' => NS_CATEGORY,
+                               'rc_title' => $categoryTitle->getDBkey()
+                       ),
+                       $expectedRows
+               );
+       }
 }