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
83 public function testUndeleteRevisions() {
84 // First make sure old revisions are archived
85 $dbr = wfGetDB( DB_REPLICA
);
86 $res = $dbr->select( 'archive', '*', [ 'ar_rev_id' => $this->ipRevId
] );
87 $row = $res->fetchObject();
88 $this->assertEquals( $this->ipEditor
, $row->ar_user_text
);
90 // Should not be in revision
91 $res = $dbr->select( 'revision', '*', [ 'rev_id' => $this->ipRevId
] );
92 $this->assertFalse( $res->fetchObject() );
94 // Should not be in ip_changes
95 $res = $dbr->select( 'ip_changes', '*', [ 'ipc_rev_id' => $this->ipRevId
] );
96 $this->assertFalse( $res->fetchObject() );
99 $this->archivedPage
->undelete( [] );
101 // Should be back in revision
102 $res = $dbr->select( 'revision', '*', [ 'rev_id' => $this->ipRevId
] );
103 $row = $res->fetchObject();
104 $this->assertEquals( $this->ipEditor
, $row->rev_user_text
);
106 // Should be back in ip_changes
107 $res = $dbr->select( 'ip_changes', '*', [ 'ipc_rev_id' => $this->ipRevId
] );
108 $row = $res->fetchObject();
109 $this->assertEquals( IP
::toHex( $this->ipEditor
), $row->ipc_hex
);
113 * @covers PageArchive::listRevisions
115 public function testListRevisions() {
116 $revisions = $this->archivedPage
->listRevisions();
117 $this->assertEquals( 2, $revisions->numRows() );
119 // Get the rows as arrays
120 $row1 = (array)$revisions->current();
121 $row2 = (array)$revisions->next();
122 // Unset the timestamps (we assume they will be right...
123 $this->assertInternalType( 'string', $row1['ar_timestamp'] );
124 $this->assertInternalType( 'string', $row2['ar_timestamp'] );
125 unset( $row1['ar_timestamp'] );
126 unset( $row2['ar_timestamp'] );
130 'ar_minor_edit' => '0',
132 'ar_user_text' => '2600:387:ed7:947e:8c16:a1ad:dd34:1dd7',
136 'ar_sha1' => '0qdrpxl537ivfnx4gcpnzz0285yxryy',
138 'ar_comment_text' => 'just a test',
139 'ar_comment_data' => null,
140 'ar_comment_cid' => null,
141 'ar_content_format' => null,
142 'ar_content_model' => null,
149 'ar_minor_edit' => '0',
151 'ar_user_text' => '127.0.0.1',
155 'ar_sha1' => 'pr0s8e18148pxhgjfa0gjrvpy8fiyxc',
157 'ar_comment_text' => 'testing',
158 'ar_comment_data' => null,
159 'ar_comment_cid' => null,
160 'ar_content_format' => null,
161 'ar_content_model' => null,