aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit
diff options
context:
space:
mode:
authorKai_WMDE <kai.nissen@wikimedia.de>2015-05-17 18:09:59 +0200
committerKai_WMDE <kai.nissen@wikimedia.de>2015-08-13 17:58:06 +0200
commitf6879ea16edf008eb012bd4dbe133e2ba4b9338f (patch)
treee58cf2cc7f75f15576c5db4f58e1b2f55b5dce2f /tests/phpunit
parent0a9ee5d9bf0047ec65c29ee35321d96191ecbff5 (diff)
downloadmediawikicore-f6879ea16edf008eb012bd4dbe133e2ba4b9338f.tar.gz
mediawikicore-f6879ea16edf008eb012bd4dbe133e2ba4b9338f.zip
Enable users to watch category membership changes
Bug: T9148 Change-Id: I5a89d8f19804b1120f4c755d834e2da6ca12ceae
Diffstat (limited to 'tests/phpunit')
-rw-r--r--tests/phpunit/includes/changes/EnhancedChangesListTest.php43
-rw-r--r--tests/phpunit/includes/changes/TestRecentChangesHelper.php30
-rw-r--r--tests/phpunit/includes/deferred/LinksUpdateTest.php86
3 files changed, 158 insertions, 1 deletions
diff --git a/tests/phpunit/includes/changes/EnhancedChangesListTest.php b/tests/phpunit/includes/changes/EnhancedChangesListTest.php
index a14a50d2cb21..01e221f95ad5 100644
--- a/tests/phpunit/includes/changes/EnhancedChangesListTest.php
+++ b/tests/phpunit/includes/changes/EnhancedChangesListTest.php
@@ -74,6 +74,20 @@ class EnhancedChangesListTest extends MediaWikiLangTestCase {
$this->assertEquals( '', $html );
}
+ public function testCategorizationLineFormatting() {
+ $html = $this->createCategorizationLine(
+ $this->getCategorizationChange( '20150629191735', 0, 0 )
+ );
+ $this->assertNotContains( '(diff | hist)', strip_tags( $html ) );
+ }
+
+ public function testCategorizationLineFormattingWithRevision() {
+ $html = $this->createCategorizationLine(
+ $this->getCategorizationChange( '20150629191735', 1025, 1024 )
+ );
+ $this->assertContains( '(diff | hist)', strip_tags( $html ) );
+ }
+
/**
* @todo more tests for actual formatting, this is more of a smoke test
*/
@@ -116,6 +130,24 @@ class EnhancedChangesListTest extends MediaWikiLangTestCase {
}
/**
+ * @return RecentChange
+ */
+ private function getCategorizationChange( $timestamp, $thisId, $lastId ) {
+ $wikiPage = new WikiPage( Title::newFromText( 'Testpage' ) );
+ $wikiPage->doEditContent( new WikitextContent( 'Some random text' ), 'page created' );
+
+ $wikiPage = new WikiPage( Title::newFromText( 'Category:Foo' ) );
+ $wikiPage->doEditContent( new WikitextContent( 'Some random text' ), 'category page created' );
+
+ $user = $this->getTestUser();
+ $recentChange = $this->testRecentChangesHelper->makeCategorizationRecentChange(
+ $user, 'Category:Foo', $wikiPage->getId(), $thisId, $lastId, $timestamp
+ );
+
+ return $recentChange;
+ }
+
+ /**
* @return User
*/
private function getTestUser() {
@@ -128,4 +160,15 @@ class EnhancedChangesListTest extends MediaWikiLangTestCase {
return $user;
}
+ private function createCategorizationLine( $recentChange ) {
+ $enhancedChangesList = $this->newEnhancedChangesList();
+ $cacheEntry = $this->testRecentChangesHelper->getCacheEntry( $recentChange );
+
+ $reflection = new \ReflectionClass( get_class( $enhancedChangesList ) );
+ $method = $reflection->getMethod( 'recentChangesBlockLine' );
+ $method->setAccessible( true );
+
+ return $method->invokeArgs( $enhancedChangesList, array( $cacheEntry ) );
+ }
+
}
diff --git a/tests/phpunit/includes/changes/TestRecentChangesHelper.php b/tests/phpunit/includes/changes/TestRecentChangesHelper.php
index 2506087bfaa4..e59825a9f55a 100644
--- a/tests/phpunit/includes/changes/TestRecentChangesHelper.php
+++ b/tests/phpunit/includes/changes/TestRecentChangesHelper.php
@@ -97,6 +97,36 @@ class TestRecentChangesHelper {
return $change;
}
+ public function getCacheEntry( $recentChange ) {
+ $rcCacheFactory = new RCCacheEntryFactory(
+ new RequestContext(),
+ array( 'diff' => 'diff', 'cur' => 'cur', 'last' => 'last' )
+ );
+ return $rcCacheFactory->newFromRecentChange( $recentChange, false );
+ }
+
+ public function makeCategorizationRecentChange(
+ User $user, $titleText, $curid, $thisid, $lastid, $timestamp
+ ) {
+
+ $attribs = array_merge(
+ $this->getDefaultAttributes( $titleText, $timestamp ),
+ array(
+ 'rc_type' => RC_CATEGORIZE,
+ 'rc_user' => $user->getId(),
+ 'rc_user_text' => $user->getName(),
+ 'rc_this_oldid' => $thisid,
+ 'rc_last_oldid' => $lastid,
+ 'rc_cur_id' => $curid,
+ 'rc_comment' => '[[:Testpage]] added to category',
+ 'rc_old_len' => 0,
+ 'rc_new_len' => 0,
+ )
+ );
+
+ return $this->makeRecentChange( $attribs, 0, 0 );
+ }
+
private function getDefaultAttributes( $titleText, $timestamp ) {
return array(
'rc_id' => 545,
diff --git a/tests/phpunit/includes/deferred/LinksUpdateTest.php b/tests/phpunit/includes/deferred/LinksUpdateTest.php
index 02f6b2ab2d5a..efbfe6f6a9e8 100644
--- a/tests/phpunit/includes/deferred/LinksUpdateTest.php
+++ b/tests/phpunit/includes/deferred/LinksUpdateTest.php
@@ -19,7 +19,8 @@ class LinksUpdateTest extends MediaWikiTestCase {
'externallinks',
'imagelinks',
'templatelinks',
- 'iwlinks'
+ 'iwlinks',
+ 'recentchanges',
)
);
}
@@ -41,6 +42,12 @@ class LinksUpdateTest extends MediaWikiTestCase {
);
}
+ public function addDBData() {
+ $this->insertPage( 'Testing' );
+ $this->insertPage( 'Some_other_page' );
+ $this->insertPage( 'Template:TestingTemplate' );
+ }
+
protected function makeTitleAndParserOutput( $name, $id ) {
$t = Title::newFromText( $name );
$t->mArticleID = $id; # XXX: this is fugly
@@ -133,6 +140,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 +325,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
+ );
+ }
}