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
{
15 * @var WikiPage $archivedPage
17 private $archivedPage;
20 * A logged out user who edited the page before it was archived.
21 * @var string $ipEditor
26 * Revision ID of the IP edit
31 function __construct( $name = null, array $data = [], $dataName = '' ) {
32 parent
::__construct( $name, $data, $dataName );
34 $this->tablesUsed
= array_merge(
49 protected function setUp() {
52 // First create our dummy page
53 $page = Title
::newFromText( 'PageArchiveTest_thePage' );
54 $page = new WikiPage( $page );
55 $content = ContentHandler
::makeContent(
58 CONTENT_MODEL_WIKITEXT
60 $page->doEditContent( $content, 'testing', EDIT_NEW
);
63 $this->ipEditor
= '2600:387:ed7:947e:8c16:a1ad:dd34:1dd7';
64 $rev = new Revision( [
65 'text' => 'Lorem Ipsum',
66 'comment' => 'just a test',
67 'page' => $page->getId(),
68 'user_text' => $this->ipEditor
,
70 $dbw = wfGetDB( DB_MASTER
);
71 $this->ipRevId
= $rev->insertOn( $dbw );
74 $page->doDeleteArticleReal( 'Just a test deletion' );
76 $this->archivedPage
= new PageArchive( $page->getTitle() );
80 * @covers PageArchive::undelete
82 public function testUndeleteRevisions() {
83 // First make sure old revisions are archived
84 $dbr = wfGetDB( DB_REPLICA
);
85 $res = $dbr->select( 'archive', '*', [ 'ar_rev_id' => $this->ipRevId
] );
86 $row = $res->fetchObject();
87 $this->assertEquals( $this->ipEditor
, $row->ar_user_text
);
89 // Should not be in revision
90 $res = $dbr->select( 'revision', '*', [ 'rev_id' => $this->ipRevId
] );
91 $this->assertFalse( $res->fetchObject() );
93 // Should not be in ip_changes
94 $res = $dbr->select( 'ip_changes', '*', [ 'ipc_rev_id' => $this->ipRevId
] );
95 $this->assertFalse( $res->fetchObject() );
98 $this->archivedPage
->undelete( [] );
100 // Should be back in revision
101 $res = $dbr->select( 'revision', '*', [ 'rev_id' => $this->ipRevId
] );
102 $row = $res->fetchObject();
103 $this->assertEquals( $this->ipEditor
, $row->rev_user_text
);
105 // Should be back in ip_changes
106 $res = $dbr->select( 'ip_changes', '*', [ 'ipc_rev_id' => $this->ipRevId
] );
107 $row = $res->fetchObject();
108 $this->assertEquals( IP
::toHex( $this->ipEditor
), $row->ipc_hex
);