MediaWiki  1.30.0
PageArchiveTest.php
Go to the documentation of this file.
1 <?php
2 
17  private $archivedPage;
18 
23  private $ipEditor;
24 
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(),
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 
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 }
IP\toHex
static toHex( $ip)
Return a zero-padded upper case hexadecimal representation of an IP address.
Definition: IP.php:417
PageArchiveTest\$ipEditor
$ipEditor
A logged out user who edited the page before it was archived.
Definition: PageArchiveTest.php:23
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:268
PageArchive
Used to show archived pages and eventually restore them.
Definition: PageArchive.php:28
PageArchiveTest\$archivedPage
$archivedPage
Definition: PageArchiveTest.php:17
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:37
$res
$res
Definition: database.txt:21
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:236
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Revision
Definition: Revision.php:33
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2856
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
PageArchiveTest\setUp
setUp()
Definition: PageArchiveTest.php:49
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
ContentHandler\makeContent
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Definition: ContentHandler.php:129
PageArchiveTest\$ipRevId
$ipRevId
Revision ID of the IP edit.
Definition: PageArchiveTest.php:29
PageArchiveTest
Test class for page archiving.
Definition: PageArchiveTest.php:13
EDIT_NEW
const EDIT_NEW
Definition: Defines.php:153
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
PageArchiveTest\testUndeleteRevisions
testUndeleteRevisions()
PageArchive::undelete.
Definition: PageArchiveTest.php:82
$rev
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1750
PageArchiveTest\__construct
__construct( $name=null, array $data=[], $dataName='')
Definition: PageArchiveTest.php:31
array
the array() calling protocol came about after MediaWiki 1.4rc1.