$this->tablesUsed,
[ 'page',
'revision',
+ 'archive',
+ 'ip_changes',
'text',
'recentchanges',
$this->assertEquals( "one", $page->getContent()->getNativeData() );
}
+ /**
+ * Tests tagging for edits that do rollback action
+ * @covers WikiPage::doRollback
+ */
+ public function testDoRollbackTagging() {
+ if ( !in_array( 'mw-rollback', ChangeTags::getSoftwareTags() ) ) {
+ $this->markTestSkipped( 'Rollback tag deactivated, skipped the test.' );
+ }
+
+ $admin = new User();
+ $admin->setName( 'Administrator' );
+ $admin->addToDatabase();
+
+ $text = 'First line';
+ $page = $this->newPage( 'WikiPageTest_testDoRollbackTagging' );
+ $page->doEditContent(
+ ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
+ 'Added first line',
+ EDIT_NEW,
+ false,
+ $admin
+ );
+
+ $secondUser = new User();
+ $secondUser->setName( '92.65.217.32' );
+ $text .= '\n\nSecond line';
+ $page = new WikiPage( $page->getTitle() );
+ $page->doEditContent(
+ ContentHandler::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
+ 'Adding second line',
+ 0,
+ false,
+ $secondUser
+ );
+
+ // Now, try the rollback
+ $admin->addGroup( 'sysop' ); // Make the test user a sysop
+ $token = $admin->getEditToken( 'rollback' );
+ $errors = $page->doRollback(
+ $secondUser->getName(),
+ 'testing rollback',
+ $token,
+ false,
+ $resultDetails,
+ $admin
+ );
+
+ // If doRollback completed without errors
+ if ( $errors === [] ) {
+ $tags = $resultDetails[ 'tags' ];
+ $this->assertContains( 'mw-rollback', $tags );
+ }
+ }
+
public static function provideGetAutoDeleteReason() {
return [
[
$page = WikiPage::factory( $title );
$this->assertEquals( 'WikiPage', get_class( $page ) );
}
+
+ /**
+ * @dataProvider provideCommentMigrationOnDeletion
+ * @param int $wstage
+ * @param int $rstage
+ */
+ public function testCommentMigrationOnDeletion( $wstage, $rstage ) {
+ $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', $wstage );
+ $dbr = wfGetDB( DB_REPLICA );
+
+ $page = $this->createPage(
+ "WikiPageTest_testCommentMigrationOnDeletion",
+ "foo",
+ CONTENT_MODEL_WIKITEXT
+ );
+ $revid = $page->getLatest();
+ if ( $wstage > MIGRATION_OLD ) {
+ $comment_id = $dbr->selectField(
+ 'revision_comment_temp',
+ 'revcomment_comment_id',
+ [ 'revcomment_rev' => $revid ],
+ __METHOD__
+ );
+ }
+
+ $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', $rstage );
+
+ $page->doDeleteArticle( "testing deletion" );
+
+ if ( $rstage > MIGRATION_OLD ) {
+ // Didn't leave behind any 'revision_comment_temp' rows
+ $n = $dbr->selectField(
+ 'revision_comment_temp', 'COUNT(*)', [ 'revcomment_rev' => $revid ], __METHOD__
+ );
+ $this->assertEquals( 0, $n, 'no entry in revision_comment_temp after deletion' );
+
+ // Copied or upgraded the comment_id, as applicable
+ $ar_comment_id = $dbr->selectField(
+ 'archive',
+ 'ar_comment_id',
+ [ 'ar_rev_id' => $revid ],
+ __METHOD__
+ );
+ if ( $wstage > MIGRATION_OLD ) {
+ $this->assertSame( $comment_id, $ar_comment_id );
+ } else {
+ $this->assertNotEquals( 0, $ar_comment_id );
+ }
+ }
+
+ // Copied rev_comment, if applicable
+ if ( $rstage <= MIGRATION_WRITE_BOTH && $wstage <= MIGRATION_WRITE_BOTH ) {
+ $ar_comment = $dbr->selectField(
+ 'archive',
+ 'ar_comment',
+ [ 'ar_rev_id' => $revid ],
+ __METHOD__
+ );
+ $this->assertSame( 'testing', $ar_comment );
+ }
+ }
+
+ public static function provideCommentMigrationOnDeletion() {
+ return [
+ [ MIGRATION_OLD, MIGRATION_OLD ],
+ [ MIGRATION_OLD, MIGRATION_WRITE_BOTH ],
+ [ MIGRATION_OLD, MIGRATION_WRITE_NEW ],
+ [ MIGRATION_WRITE_BOTH, MIGRATION_OLD ],
+ [ MIGRATION_WRITE_BOTH, MIGRATION_WRITE_BOTH ],
+ [ MIGRATION_WRITE_BOTH, MIGRATION_WRITE_NEW ],
+ [ MIGRATION_WRITE_BOTH, MIGRATION_NEW ],
+ [ MIGRATION_WRITE_NEW, MIGRATION_WRITE_BOTH ],
+ [ MIGRATION_WRITE_NEW, MIGRATION_WRITE_NEW ],
+ [ MIGRATION_WRITE_NEW, MIGRATION_NEW ],
+ [ MIGRATION_NEW, MIGRATION_WRITE_BOTH ],
+ [ MIGRATION_NEW, MIGRATION_WRITE_NEW ],
+ [ MIGRATION_NEW, MIGRATION_NEW ],
+ ];
+ }
+
}