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->overrideMwServices();
57 // First create our dummy page
58 $page = Title
::newFromText( 'PageArchiveTest_thePage' );
59 $page = new WikiPage( $page );
60 $content = ContentHandler
::makeContent(
63 CONTENT_MODEL_WIKITEXT
65 $page->doEditContent( $content, 'testing', EDIT_NEW
);
68 $this->ipEditor
= '2600:387:ed7:947e:8c16:a1ad:dd34:1dd7';
69 $rev = new Revision( [
70 'text' => 'Lorem Ipsum',
71 'comment' => 'just a test',
72 'page' => $page->getId(),
73 'user_text' => $this->ipEditor
,
75 $dbw = wfGetDB( DB_MASTER
);
76 $this->ipRevId
= $rev->insertOn( $dbw );
79 $page->doDeleteArticleReal( 'Just a test deletion' );
81 $this->archivedPage
= new PageArchive( $page->getTitle() );
85 * @covers PageArchive::undelete
86 * @covers PageArchive::undeleteRevisions
88 public function testUndeleteRevisions() {
89 // First make sure old revisions are archived
90 $dbr = wfGetDB( DB_REPLICA
);
91 $arQuery = Revision
::getArchiveQueryInfo();
95 [ 'ar_rev_id' => $this->ipRevId
],
100 $row = $res->fetchObject();
101 $this->assertEquals( $this->ipEditor
, $row->ar_user_text
);
103 // Should not be in revision
104 $res = $dbr->select( 'revision', '1', [ 'rev_id' => $this->ipRevId
] );
105 $this->assertFalse( $res->fetchObject() );
107 // Should not be in ip_changes
108 $res = $dbr->select( 'ip_changes', '1', [ 'ipc_rev_id' => $this->ipRevId
] );
109 $this->assertFalse( $res->fetchObject() );
112 $this->archivedPage
->undelete( [] );
114 // Should be back in revision
115 $revQuery = Revision
::getQueryInfo();
119 [ 'rev_id' => $this->ipRevId
],
124 $row = $res->fetchObject();
125 $this->assertEquals( $this->ipEditor
, $row->rev_user_text
);
127 // Should be back in ip_changes
128 $res = $dbr->select( 'ip_changes', [ 'ipc_hex' ], [ 'ipc_rev_id' => $this->ipRevId
] );
129 $row = $res->fetchObject();
130 $this->assertEquals( IP
::toHex( $this->ipEditor
), $row->ipc_hex
);
134 * @covers PageArchive::listRevisions
136 public function testListRevisions() {
137 $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD
);
138 $this->overrideMwServices();
140 $revisions = $this->archivedPage
->listRevisions();
141 $this->assertEquals( 2, $revisions->numRows() );
143 // Get the rows as arrays
144 $row1 = (array)$revisions->current();
145 $row2 = (array)$revisions->next();
146 // Unset the timestamps (we assume they will be right...
147 $this->assertInternalType( 'string', $row1['ar_timestamp'] );
148 $this->assertInternalType( 'string', $row2['ar_timestamp'] );
149 unset( $row1['ar_timestamp'] );
150 unset( $row2['ar_timestamp'] );
154 'ar_minor_edit' => '0',
156 'ar_user_text' => '2600:387:ed7:947e:8c16:a1ad:dd34:1dd7',
161 'ar_sha1' => '0qdrpxl537ivfnx4gcpnzz0285yxryy',
163 'ar_comment_text' => 'just a test',
164 'ar_comment_data' => null,
165 'ar_comment_cid' => null,
166 'ar_content_format' => null,
167 'ar_content_model' => null,
170 'ar_namespace' => '0',
171 'ar_title' => 'PageArchiveTest_thePage',
173 'ar_parent_id' => '2',
179 'ar_minor_edit' => '0',
181 'ar_user_text' => '127.0.0.1',
186 'ar_sha1' => 'pr0s8e18148pxhgjfa0gjrvpy8fiyxc',
188 'ar_comment_text' => 'testing',
189 'ar_comment_data' => null,
190 'ar_comment_cid' => null,
191 'ar_content_format' => null,
192 'ar_content_model' => null,
195 'ar_namespace' => '0',
196 'ar_title' => 'PageArchiveTest_thePage',
198 'ar_parent_id' => '0',
205 * @covers PageArchive::listPagesBySearch
207 public function testListPagesBySearch() {
208 $pages = PageArchive
::listPagesBySearch( 'PageArchiveTest_thePage' );
209 $this->assertSame( 1, $pages->numRows() );
211 $page = (array)$pages->current();
215 'ar_namespace' => '0',
216 'ar_title' => 'PageArchiveTest_thePage',
224 * @covers PageArchive::listPagesBySearch
226 public function testListPagesByPrefix() {
227 $pages = PageArchive
::listPagesByPrefix( 'PageArchiveTest' );
228 $this->assertSame( 1, $pages->numRows() );
230 $page = (array)$pages->current();
234 'ar_namespace' => '0',
235 'ar_title' => 'PageArchiveTest_thePage',
243 * @covers PageArchive::getTextFromRow
245 public function testGetTextFromRow() {
246 $row = (object)[ 'ar_text_id' => 2 ];
247 $text = $this->archivedPage
->getTextFromRow( $row );
248 $this->assertSame( 'testing', $text );
252 * @covers PageArchive::getLastRevisionText
254 public function testGetLastRevisionText() {
255 $text = $this->archivedPage
->getLastRevisionText();
256 $this->assertSame( 'Lorem Ipsum', $text );
260 * @covers PageArchive::isDeleted
262 public function testIsDeleted() {
263 $this->assertTrue( $this->archivedPage
->isDeleted() );