]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - tests/phpunit/includes/PageArchiveTest.php
MediaWiki 1.30.2-scripts
[autoinstallsdev/mediawiki.git] / tests / phpunit / includes / PageArchiveTest.php
1 <?php
2
3 /**
4  * Test class for page archiving.
5  *
6  * @group ContentHandler
7  * @group Database
8  * ^--- important, causes temporary tables to be used instead of the real database
9  *
10  * @group medium
11  * ^--- important, causes tests not to fail with timeout
12  */
13 class PageArchiveTest extends MediaWikiTestCase {
14         /**
15          * @var WikiPage $archivedPage
16          */
17         private $archivedPage;
18
19         /**
20          * A logged out user who edited the page before it was archived.
21          * @var string $ipEditor
22          */
23         private $ipEditor;
24
25         /**
26          * Revision ID of the IP edit
27          * @var int $ipRevId
28          */
29         private $ipRevId;
30
31         function __construct( $name = null, array $data = [], $dataName = '' ) {
32                 parent::__construct( $name, $data, $dataName );
33
34                 $this->tablesUsed = array_merge(
35                         $this->tablesUsed,
36                         [
37                                 'page',
38                                 'revision',
39                                 'ip_changes',
40                                 'text',
41                                 'archive',
42                                 'recentchanges',
43                                 'logging',
44                                 'page_props',
45                         ]
46                 );
47         }
48
49         protected function setUp() {
50                 parent::setUp();
51
52                 // First create our dummy page
53                 $page = Title::newFromText( 'PageArchiveTest_thePage' );
54                 $page = new WikiPage( $page );
55                 $content = ContentHandler::makeContent(
56                         'testing',
57                         $page->getTitle(),
58                         CONTENT_MODEL_WIKITEXT
59                 );
60                 $page->doEditContent( $content, 'testing', EDIT_NEW );
61
62                 // Insert IP revision
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,
69                 ] );
70                 $dbw = wfGetDB( DB_MASTER );
71                 $this->ipRevId = $rev->insertOn( $dbw );
72
73                 // Delete the page
74                 $page->doDeleteArticleReal( 'Just a test deletion' );
75
76                 $this->archivedPage = new PageArchive( $page->getTitle() );
77         }
78
79         /**
80          * @covers PageArchive::undelete
81          */
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 );
88
89                 // Should not be in revision
90                 $res = $dbr->select( 'revision', '*', [ 'rev_id' => $this->ipRevId ] );
91                 $this->assertFalse( $res->fetchObject() );
92
93                 // Should not be in ip_changes
94                 $res = $dbr->select( 'ip_changes', '*', [ 'ipc_rev_id' => $this->ipRevId ] );
95                 $this->assertFalse( $res->fetchObject() );
96
97                 // Restore the page
98                 $this->archivedPage->undelete( [] );
99
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 );
104
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 );
109         }
110 }