4 * Test class for page archiving.
6 * @group ContentHandler
8 * ^--- important, causes temporary tables to be used instead of the real database
11 * ^--- important, causes tests not to fail with timeout
13 class PageArchiveTest
extends MediaWikiTestCase
{
16 * @var PageArchive $archivedPage
18 private $archivedPage;
21 * A logged out user who edited the page before it was archived.
22 * @var string $ipEditor
27 * Revision ID of the IP edit
32 function __construct( $name = null, array $data = [], $dataName = '' ) {
33 parent
::__construct( $name, $data, $dataName );
35 $this->tablesUsed
= array_merge(
50 protected function setUp() {
53 $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD
);
54 $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', MIGRATION_OLD
);
55 $this->setMwGlobals( 'wgMultiContentRevisionSchemaMigrationStage', SCHEMA_COMPAT_OLD
);
56 $this->overrideMwServices();
58 // First create our dummy page
59 $page = Title
::newFromText( 'PageArchiveTest_thePage' );
60 $page = new WikiPage( $page );
61 $content = ContentHandler
::makeContent(
64 CONTENT_MODEL_WIKITEXT
66 $page->doEditContent( $content, 'testing', EDIT_NEW
);
69 $this->ipEditor
= '2600:387:ed7:947e:8c16:a1ad:dd34:1dd7';
70 $rev = new Revision( [
71 'text' => 'Lorem Ipsum',
72 'comment' => 'just a test',
73 'page' => $page->getId(),
74 'user_text' => $this->ipEditor
,
76 $dbw = wfGetDB( DB_MASTER
);
77 $this->ipRevId
= $rev->insertOn( $dbw );
80 $page->doDeleteArticleReal( 'Just a test deletion' );
82 $this->archivedPage
= new PageArchive( $page->getTitle() );
86 * @covers PageArchive::undelete
87 * @covers PageArchive::undeleteRevisions
89 public function testUndeleteRevisions() {
90 // First make sure old revisions are archived
91 $dbr = wfGetDB( DB_REPLICA
);
92 $arQuery = Revision
::getArchiveQueryInfo();
96 [ 'ar_rev_id' => $this->ipRevId
],
101 $row = $res->fetchObject();
102 $this->assertEquals( $this->ipEditor
, $row->ar_user_text
);
104 // Should not be in revision
105 $res = $dbr->select( 'revision', '1', [ 'rev_id' => $this->ipRevId
] );
106 $this->assertFalse( $res->fetchObject() );
108 // Should not be in ip_changes
109 $res = $dbr->select( 'ip_changes', '1', [ 'ipc_rev_id' => $this->ipRevId
] );
110 $this->assertFalse( $res->fetchObject() );
113 $this->archivedPage
->undelete( [] );
115 // Should be back in revision
116 $revQuery = Revision
::getQueryInfo();
120 [ 'rev_id' => $this->ipRevId
],
125 $row = $res->fetchObject();
126 $this->assertEquals( $this->ipEditor
, $row->rev_user_text
);
128 // Should be back in ip_changes
129 $res = $dbr->select( 'ip_changes', [ 'ipc_hex' ], [ 'ipc_rev_id' => $this->ipRevId
] );
130 $row = $res->fetchObject();
131 $this->assertEquals( IP
::toHex( $this->ipEditor
), $row->ipc_hex
);
135 * @covers PageArchive::listRevisions
137 public function testListRevisions() {
138 $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD
);
139 $this->setMwGlobals( 'wgMultiContentRevisionSchemaMigrationStage', SCHEMA_COMPAT_OLD
);
140 $this->overrideMwServices();
142 $revisions = $this->archivedPage
->listRevisions();
143 $this->assertEquals( 2, $revisions->numRows() );
145 // Get the rows as arrays
146 $row1 = (array)$revisions->current();
147 $row2 = (array)$revisions->next();
148 // Unset the timestamps (we assume they will be right...
149 $this->assertInternalType( 'string', $row1['ar_timestamp'] );
150 $this->assertInternalType( 'string', $row2['ar_timestamp'] );
151 unset( $row1['ar_timestamp'] );
152 unset( $row2['ar_timestamp'] );
156 'ar_minor_edit' => '0',
158 'ar_user_text' => '2600:387:ed7:947e:8c16:a1ad:dd34:1dd7',
163 'ar_sha1' => '0qdrpxl537ivfnx4gcpnzz0285yxryy',
165 'ar_comment_text' => 'just a test',
166 'ar_comment_data' => null,
167 'ar_comment_cid' => null,
168 'ar_content_format' => null,
169 'ar_content_model' => null,
172 'ar_namespace' => '0',
173 'ar_title' => 'PageArchiveTest_thePage',
175 'ar_parent_id' => '2',
181 'ar_minor_edit' => '0',
183 'ar_user_text' => '127.0.0.1',
188 'ar_sha1' => 'pr0s8e18148pxhgjfa0gjrvpy8fiyxc',
190 'ar_comment_text' => 'testing',
191 'ar_comment_data' => null,
192 'ar_comment_cid' => null,
193 'ar_content_format' => null,
194 'ar_content_model' => null,
197 'ar_namespace' => '0',
198 'ar_title' => 'PageArchiveTest_thePage',
200 'ar_parent_id' => '0',
207 * @covers PageArchive::listPagesBySearch
209 public function testListPagesBySearch() {
210 $pages = PageArchive
::listPagesBySearch( 'PageArchiveTest_thePage' );
211 $this->assertSame( 1, $pages->numRows() );
213 $page = (array)$pages->current();
217 'ar_namespace' => '0',
218 'ar_title' => 'PageArchiveTest_thePage',
226 * @covers PageArchive::listPagesBySearch
228 public function testListPagesByPrefix() {
229 $pages = PageArchive
::listPagesByPrefix( 'PageArchiveTest' );
230 $this->assertSame( 1, $pages->numRows() );
232 $page = (array)$pages->current();
236 'ar_namespace' => '0',
237 'ar_title' => 'PageArchiveTest_thePage',
245 * @covers PageArchive::getTextFromRow
247 public function testGetTextFromRow() {
248 $row = (object)[ 'ar_text_id' => 2 ];
249 $text = $this->archivedPage
->getTextFromRow( $row );
250 $this->assertSame( 'testing', $text );
254 * @covers PageArchive::getLastRevisionText
256 public function testGetLastRevisionText() {
257 $text = $this->archivedPage
->getLastRevisionText();
258 $this->assertSame( 'Lorem Ipsum', $text );
262 * @covers PageArchive::isDeleted
264 public function testIsDeleted() {
265 $this->assertTrue( $this->archivedPage
->isDeleted() );