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 // First create our dummy page
54 $page = Title
::newFromText( 'PageArchiveTest_thePage' );
55 $page = new WikiPage( $page );
56 $content = ContentHandler
::makeContent(
59 CONTENT_MODEL_WIKITEXT
61 $page->doEditContent( $content, 'testing', EDIT_NEW
);
64 $this->ipEditor
= '2600:387:ed7:947e:8c16:a1ad:dd34:1dd7';
65 $rev = new Revision( [
66 'text' => 'Lorem Ipsum',
67 'comment' => 'just a test',
68 'page' => $page->getId(),
69 'user_text' => $this->ipEditor
,
71 $dbw = wfGetDB( DB_MASTER
);
72 $this->ipRevId
= $rev->insertOn( $dbw );
75 $page->doDeleteArticleReal( 'Just a test deletion' );
77 $this->archivedPage
= new PageArchive( $page->getTitle() );
81 * @covers PageArchive::undelete
82 * @covers PageArchive::undeleteRevisions
84 public function testUndeleteRevisions() {
85 // First make sure old revisions are archived
86 $dbr = wfGetDB( DB_REPLICA
);
87 $res = $dbr->select( 'archive', '*', [ 'ar_rev_id' => $this->ipRevId
] );
88 $row = $res->fetchObject();
89 $this->assertEquals( $this->ipEditor
, $row->ar_user_text
);
91 // Should not be in revision
92 $res = $dbr->select( 'revision', '*', [ 'rev_id' => $this->ipRevId
] );
93 $this->assertFalse( $res->fetchObject() );
95 // Should not be in ip_changes
96 $res = $dbr->select( 'ip_changes', '*', [ 'ipc_rev_id' => $this->ipRevId
] );
97 $this->assertFalse( $res->fetchObject() );
100 $this->archivedPage
->undelete( [] );
102 // Should be back in revision
103 $res = $dbr->select( 'revision', '*', [ 'rev_id' => $this->ipRevId
] );
104 $row = $res->fetchObject();
105 $this->assertEquals( $this->ipEditor
, $row->rev_user_text
);
107 // Should be back in ip_changes
108 $res = $dbr->select( 'ip_changes', '*', [ 'ipc_rev_id' => $this->ipRevId
] );
109 $row = $res->fetchObject();
110 $this->assertEquals( IP
::toHex( $this->ipEditor
), $row->ipc_hex
);
114 * @covers PageArchive::listRevisions
116 public function testListRevisions() {
117 $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD
);
118 $this->overrideMwServices();
120 $revisions = $this->archivedPage
->listRevisions();
121 $this->assertEquals( 2, $revisions->numRows() );
123 // Get the rows as arrays
124 $row1 = (array)$revisions->current();
125 $row2 = (array)$revisions->next();
126 // Unset the timestamps (we assume they will be right...
127 $this->assertInternalType( 'string', $row1['ar_timestamp'] );
128 $this->assertInternalType( 'string', $row2['ar_timestamp'] );
129 unset( $row1['ar_timestamp'] );
130 unset( $row2['ar_timestamp'] );
134 'ar_minor_edit' => '0',
136 'ar_user_text' => '2600:387:ed7:947e:8c16:a1ad:dd34:1dd7',
140 'ar_sha1' => '0qdrpxl537ivfnx4gcpnzz0285yxryy',
142 'ar_comment_text' => 'just a test',
143 'ar_comment_data' => null,
144 'ar_comment_cid' => null,
145 'ar_content_format' => null,
146 'ar_content_model' => null,
149 'ar_namespace' => '0',
150 'ar_title' => 'PageArchiveTest_thePage',
153 'ar_parent_id' => '2',
159 'ar_minor_edit' => '0',
161 'ar_user_text' => '127.0.0.1',
165 'ar_sha1' => 'pr0s8e18148pxhgjfa0gjrvpy8fiyxc',
167 'ar_comment_text' => 'testing',
168 'ar_comment_data' => null,
169 'ar_comment_cid' => null,
170 'ar_content_format' => null,
171 'ar_content_model' => null,
174 'ar_namespace' => '0',
175 'ar_title' => 'PageArchiveTest_thePage',
178 'ar_parent_id' => '0',
185 * @covers PageArchive::listPagesBySearch
187 public function testListPagesBySearch() {
188 $pages = PageArchive
::listPagesBySearch( 'PageArchiveTest_thePage' );
189 $this->assertSame( 1, $pages->numRows() );
191 $page = (array)$pages->current();
195 'ar_namespace' => '0',
196 'ar_title' => 'PageArchiveTest_thePage',
204 * @covers PageArchive::listPagesBySearch
206 public function testListPagesByPrefix() {
207 $pages = PageArchive
::listPagesByPrefix( 'PageArchiveTest' );
208 $this->assertSame( 1, $pages->numRows() );
210 $page = (array)$pages->current();
214 'ar_namespace' => '0',
215 'ar_title' => 'PageArchiveTest_thePage',
223 * @covers PageArchive::getTextFromRow
225 public function testGetTextFromRow() {
226 $row = (object)[ 'ar_text_id' => 2 ];
227 $text = $this->archivedPage
->getTextFromRow( $row );
228 $this->assertSame( 'testing', $text );
232 * @covers PageArchive::getLastRevisionText
234 public function testGetLastRevisionText() {
235 $text = $this->archivedPage
->getLastRevisionText();
236 $this->assertSame( 'Lorem Ipsum', $text );
240 * @covers PageArchive::isDeleted
242 public function testIsDeleted() {
243 $this->assertTrue( $this->archivedPage
->isDeleted() );