MediaWiki  1.32.5
RevisionArchiveRecordTest.php
Go to the documentation of this file.
1 <?php
2 
4 
6 use InvalidArgumentException;
15 use Title;
16 
22 
24 
30  protected function newRevision( array $rowOverrides = [] ) {
31  $title = Title::newFromText( 'Dummy' );
32  $title->resetArticleID( 17 );
33 
34  $user = new UserIdentityValue( 11, 'Tester', 0 );
35  $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
36 
37  $main = SlotRecord::newUnsaved( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
38  $aux = SlotRecord::newUnsaved( 'aux', new TextContent( 'Frumious Bandersnatch' ) );
39  $slots = new RevisionSlots( [ $main, $aux ] );
40 
41  $row = [
42  'ar_id' => '5',
43  'ar_rev_id' => '7',
44  'ar_page_id' => strval( $title->getArticleID() ),
45  'ar_timestamp' => '20200101000000',
46  'ar_deleted' => 0,
47  'ar_minor_edit' => 0,
48  'ar_parent_id' => '5',
49  'ar_len' => $slots->computeSize(),
50  'ar_sha1' => $slots->computeSha1(),
51  ];
52 
53  foreach ( $rowOverrides as $field => $value ) {
54  $field = preg_replace( '/^rev_/', 'ar_', $field );
55  $row[$field] = $value;
56  }
57 
58  return new RevisionArchiveRecord( $title, $user, $comment, (object)$row, $slots );
59  }
60 
61  public function provideConstructor() {
62  $title = Title::newFromText( 'Dummy' );
63  $title->resetArticleID( 17 );
64 
65  $user = new UserIdentityValue( 11, 'Tester', 0 );
66  $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
67 
68  $main = SlotRecord::newUnsaved( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
69  $aux = SlotRecord::newUnsaved( 'aux', new TextContent( 'Frumious Bandersnatch' ) );
70  $slots = new RevisionSlots( [ $main, $aux ] );
71 
72  $protoRow = [
73  'ar_id' => '5',
74  'ar_rev_id' => '7',
75  'ar_page_id' => strval( $title->getArticleID() ),
76  'ar_timestamp' => '20200101000000',
77  'ar_deleted' => 0,
78  'ar_minor_edit' => 0,
79  'ar_parent_id' => '5',
80  'ar_len' => $slots->computeSize(),
81  'ar_sha1' => $slots->computeSha1(),
82  ];
83 
84  $row = $protoRow;
85  yield 'all info' => [
86  $title,
87  $user,
88  $comment,
89  (object)$row,
90  $slots,
91  'acmewiki'
92  ];
93 
94  $row = $protoRow;
95  $row['ar_minor_edit'] = '1';
96  $row['ar_deleted'] = strval( RevisionRecord::DELETED_USER );
97 
98  yield 'minor deleted' => [
99  $title,
100  $user,
101  $comment,
102  (object)$row,
103  $slots
104  ];
105 
106  $row = $protoRow;
107  unset( $row['ar_parent'] );
108 
109  yield 'no parent' => [
110  $title,
111  $user,
112  $comment,
113  (object)$row,
114  $slots
115  ];
116 
117  $row = $protoRow;
118  $row['ar_len'] = null;
119  $row['ar_sha1'] = '';
120 
121  yield 'ar_len is null, ar_sha1 is ""' => [
122  $title,
123  $user,
124  $comment,
125  (object)$row,
126  $slots
127  ];
128 
129  $row = $protoRow;
130  yield 'no length, no hash' => [
131  Title::newFromText( 'DummyDoesNotExist' ),
132  $user,
133  $comment,
134  (object)$row,
135  $slots
136  ];
137  }
138 
149  public function testConstructorAndGetters(
150  Title $title,
152  CommentStoreComment $comment,
153  $row,
154  RevisionSlots $slots,
155  $wikiId = false
156  ) {
157  $rec = new RevisionArchiveRecord( $title, $user, $comment, $row, $slots, $wikiId );
158 
159  $this->assertSame( $title, $rec->getPageAsLinkTarget(), 'getPageAsLinkTarget' );
160  $this->assertSame( $user, $rec->getUser( RevisionRecord::RAW ), 'getUser' );
161  $this->assertSame( $comment, $rec->getComment(), 'getComment' );
162 
163  $this->assertSame( $slots->getSlotRoles(), $rec->getSlotRoles(), 'getSlotRoles' );
164  $this->assertSame( $wikiId, $rec->getWikiId(), 'getWikiId' );
165 
166  $this->assertSame( (int)$row->ar_id, $rec->getArchiveId(), 'getArchiveId' );
167  $this->assertSame( (int)$row->ar_rev_id, $rec->getId(), 'getId' );
168  $this->assertSame( (int)$row->ar_page_id, $rec->getPageId(), 'getId' );
169  $this->assertSame( $row->ar_timestamp, $rec->getTimestamp(), 'getTimestamp' );
170  $this->assertSame( (int)$row->ar_deleted, $rec->getVisibility(), 'getVisibility' );
171  $this->assertSame( (bool)$row->ar_minor_edit, $rec->isMinor(), 'getIsMinor' );
172 
173  if ( isset( $row->ar_parent_id ) ) {
174  $this->assertSame( (int)$row->ar_parent_id, $rec->getParentId(), 'getParentId' );
175  } else {
176  $this->assertSame( 0, $rec->getParentId(), 'getParentId' );
177  }
178 
179  if ( isset( $row->ar_len ) ) {
180  $this->assertSame( (int)$row->ar_len, $rec->getSize(), 'getSize' );
181  } else {
182  $this->assertSame( $slots->computeSize(), $rec->getSize(), 'getSize' );
183  }
184 
185  if ( !empty( $row->ar_sha1 ) ) {
186  $this->assertSame( $row->ar_sha1, $rec->getSha1(), 'getSha1' );
187  } else {
188  $this->assertSame( $slots->computeSha1(), $rec->getSha1(), 'getSha1' );
189  }
190  }
191 
192  public function provideConstructorFailure() {
193  $title = Title::newFromText( 'Dummy' );
194  $title->resetArticleID( 17 );
195 
196  $user = new UserIdentityValue( 11, 'Tester', 0 );
197 
198  $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
199 
200  $main = SlotRecord::newUnsaved( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
201  $aux = SlotRecord::newUnsaved( 'aux', new TextContent( 'Frumious Bandersnatch' ) );
202  $slots = new RevisionSlots( [ $main, $aux ] );
203 
204  $protoRow = [
205  'ar_id' => '5',
206  'ar_rev_id' => '7',
207  'ar_page_id' => strval( $title->getArticleID() ),
208  'ar_timestamp' => '20200101000000',
209  'ar_deleted' => 0,
210  'ar_minor_edit' => 0,
211  'ar_parent_id' => '5',
212  'ar_len' => $slots->computeSize(),
213  'ar_sha1' => $slots->computeSha1(),
214  ];
215 
216  yield 'not a row' => [
217  $title,
218  $user,
219  $comment,
220  'not a row',
221  $slots,
222  'acmewiki'
223  ];
224 
225  $row = $protoRow;
226  $row['ar_timestamp'] = 'kittens';
227 
228  yield 'bad timestamp' => [
229  $title,
230  $user,
231  $comment,
232  (object)$row,
233  $slots
234  ];
235 
236  $row = $protoRow;
237 
238  yield 'bad wiki' => [
239  $title,
240  $user,
241  $comment,
242  (object)$row,
243  $slots,
244  12345
245  ];
246 
247  // NOTE: $title->getArticleID does *not* have to match ar_page_id in all cases!
248  }
249 
260  public function testConstructorFailure(
261  Title $title,
263  CommentStoreComment $comment,
264  $row,
265  RevisionSlots $slots,
266  $wikiId = false
267  ) {
268  $this->setExpectedException( InvalidArgumentException::class );
269  new RevisionArchiveRecord( $title, $user, $comment, $row, $slots, $wikiId );
270  }
271 
272 }
MediaWiki\User\UserIdentityValue
Value object representing a user's identity.
Definition: UserIdentityValue.php:32
CommentStoreComment\newUnsavedComment
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
Definition: CommentStoreComment.php:66
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:244
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:280
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:45
MediaWiki\Tests\Revision\RevisionArchiveRecordTest
\MediaWiki\Revision\RevisionArchiveRecord \MediaWiki\Revision\RevisionRecord
Definition: RevisionArchiveRecordTest.php:21
MediaWiki\Tests\Revision\RevisionRecordTests
trait RevisionRecordTests
\MediaWiki\Revision\RevisionRecord
Definition: RevisionRecordTests.php:23
MediaWiki\Tests\Revision\RevisionArchiveRecordTest\newRevision
newRevision(array $rowOverrides=[])
Definition: RevisionArchiveRecordTest.php:30
MediaWiki\Tests\Revision
Definition: McrReadNewRevisionStoreDbTest.php:2
Revision\RevisionSlots\computeSha1
computeSha1()
Computes the combined hash of the revisions's slots.
Definition: RevisionSlots.php:190
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:32
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
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
MediaWikiTestCase
Definition: MediaWikiTestCase.php:16
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Revision\RevisionRecord\RAW
const RAW
Definition: RevisionRecord.php:59
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
Revision\SlotRecord\newUnsaved
static newUnsaved( $role, Content $content)
Constructs a new Slot from a Content object for a new revision.
Definition: SlotRecord.php:129
MediaWiki\Tests\Revision\RevisionArchiveRecordTest\provideConstructor
provideConstructor()
Definition: RevisionArchiveRecordTest.php:61
Revision\RevisionArchiveRecord
A RevisionRecord representing a revision of a deleted page persisted in the archive table.
Definition: RevisionArchiveRecord.php:40
Revision\RevisionRecord\DELETED_USER
const DELETED_USER
Definition: RevisionRecord.php:50
$value
$value
Definition: styleTest.css.php:49
Revision\SlotRecord\MAIN
const MAIN
Definition: SlotRecord.php:41
TextContent
Content object implementation for representing flat text.
Definition: TextContent.php:37
Title
Represents a title within MediaWiki.
Definition: Title.php:39
Revision\RevisionSlots\computeSize
computeSize()
Computes the total nominal size of the revision's slots, in bogo-bytes.
Definition: RevisionSlots.php:148
Revision\RevisionSlots\getSlotRoles
getSlotRoles()
Returns the slot names (roles) of all slots present in this revision.
Definition: RevisionSlots.php:135
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Revision\RevisionSlots
Value object representing the set of slots belonging to a revision.
Definition: RevisionSlots.php:35
MediaWiki\Tests\Revision\RevisionArchiveRecordTest\provideConstructorFailure
provideConstructorFailure()
Definition: RevisionArchiveRecordTest.php:192
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
object
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Definition: globals.txt:25
MediaWiki\Tests\Revision\RevisionArchiveRecordTest\testConstructorAndGetters
testConstructorAndGetters(Title $title, UserIdentity $user, CommentStoreComment $comment, $row, RevisionSlots $slots, $wikiId=false)
provideConstructor
Definition: RevisionArchiveRecordTest.php:149
CommentStoreComment
CommentStoreComment represents a comment stored by CommentStore.
Definition: CommentStoreComment.php:29
MediaWiki\Tests\Revision\RevisionArchiveRecordTest\testConstructorFailure
testConstructorFailure(Title $title, UserIdentity $user, CommentStoreComment $comment, $row, RevisionSlots $slots, $wikiId=false)
provideConstructorFailure
Definition: RevisionArchiveRecordTest.php:260
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39