Mock CommentStore in some RevisionTest tests
[lhc/web/wiklou.git] / tests / phpunit / includes / RevisionTest.php
1 <?php
2
3 use MediaWiki\Storage\BlobStoreFactory;
4 use MediaWiki\Storage\MutableRevisionRecord;
5 use MediaWiki\Storage\RevisionAccessException;
6 use MediaWiki\Storage\RevisionRecord;
7 use MediaWiki\Storage\RevisionStore;
8 use MediaWiki\Storage\SlotRecord;
9 use MediaWiki\Storage\SqlBlobStore;
10 use Wikimedia\Rdbms\IDatabase;
11 use Wikimedia\Rdbms\LoadBalancer;
12
13 /**
14 * Test cases in RevisionTest should not interact with the Database.
15 * For test cases that need Database interaction see RevisionDbTestBase.
16 */
17 class RevisionTest extends MediaWikiTestCase {
18
19 public function provideConstructFromArray() {
20 yield 'with text' => [
21 [
22 'text' => 'hello world.',
23 'content_model' => CONTENT_MODEL_JAVASCRIPT
24 ],
25 ];
26 yield 'with content' => [
27 [
28 'content' => new JavaScriptContent( 'hellow world.' )
29 ],
30 ];
31 // FIXME: test with and without user ID, and with a user object.
32 // We can't prepare that here though, since we don't yet have a dummy DB
33 }
34
35 /**
36 * @param string $model
37 * @return Title
38 */
39 public function getMockTitle( $model = CONTENT_MODEL_WIKITEXT ) {
40 $mock = $this->getMockBuilder( Title::class )
41 ->disableOriginalConstructor()
42 ->getMock();
43 $mock->expects( $this->any() )
44 ->method( 'getNamespace' )
45 ->will( $this->returnValue( $this->getDefaultWikitextNS() ) );
46 $mock->expects( $this->any() )
47 ->method( 'getPrefixedText' )
48 ->will( $this->returnValue( 'RevisionTest' ) );
49 $mock->expects( $this->any() )
50 ->method( 'getDBkey' )
51 ->will( $this->returnValue( 'RevisionTest' ) );
52 $mock->expects( $this->any() )
53 ->method( 'getArticleID' )
54 ->will( $this->returnValue( 23 ) );
55 $mock->expects( $this->any() )
56 ->method( 'getModel' )
57 ->will( $this->returnValue( $model ) );
58
59 return $mock;
60 }
61
62 /**
63 * @dataProvider provideConstructFromArray
64 * @covers Revision::__construct
65 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
66 */
67 public function testConstructFromArray( $rowArray ) {
68 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
69 $this->assertNotNull( $rev->getContent(), 'no content object available' );
70 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContent()->getModel() );
71 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() );
72 }
73
74 /**
75 * @covers Revision::__construct
76 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
77 */
78 public function testConstructFromEmptyArray() {
79 $rev = new Revision( [], 0, $this->getMockTitle() );
80 $this->assertNull( $rev->getContent(), 'no content object should be available' );
81 }
82
83 /**
84 * @covers Revision::__construct
85 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
86 */
87 public function testConstructFromArrayWithBadPageId() {
88 MediaWiki\suppressWarnings();
89 $rev = new Revision( [ 'page' => 77777777 ] );
90 $this->assertSame( 77777777, $rev->getPage() );
91 MediaWiki\restoreWarnings();
92 }
93
94 public function provideConstructFromArray_userSetAsExpected() {
95 yield 'no user defaults to wgUser' => [
96 [
97 'content' => new JavaScriptContent( 'hello world.' ),
98 ],
99 null,
100 null,
101 ];
102 yield 'user text and id' => [
103 [
104 'content' => new JavaScriptContent( 'hello world.' ),
105 'user_text' => 'SomeTextUserName',
106 'user' => 99,
107
108 ],
109 99,
110 'SomeTextUserName',
111 ];
112 yield 'user text only' => [
113 [
114 'content' => new JavaScriptContent( 'hello world.' ),
115 'user_text' => '111.111.111.111',
116 ],
117 0,
118 '111.111.111.111',
119 ];
120 }
121
122 /**
123 * @dataProvider provideConstructFromArray_userSetAsExpected
124 * @covers Revision::__construct
125 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
126 *
127 * @param array $rowArray
128 * @param mixed $expectedUserId null to expect the current wgUser ID
129 * @param mixed $expectedUserName null to expect the current wgUser name
130 */
131 public function testConstructFromArray_userSetAsExpected(
132 array $rowArray,
133 $expectedUserId,
134 $expectedUserName
135 ) {
136 $testUser = $this->getTestUser()->getUser();
137 $this->setMwGlobals( 'wgUser', $testUser );
138 if ( $expectedUserId === null ) {
139 $expectedUserId = $testUser->getId();
140 }
141 if ( $expectedUserName === null ) {
142 $expectedUserName = $testUser->getName();
143 }
144
145 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
146 $this->assertEquals( $expectedUserId, $rev->getUser() );
147 $this->assertEquals( $expectedUserName, $rev->getUserText() );
148 }
149
150 public function provideConstructFromArrayThrowsExceptions() {
151 yield 'content and text_id both not empty' => [
152 [
153 'content' => new WikitextContent( 'GOAT' ),
154 'text_id' => 'someid',
155 ],
156 new MWException( "Text already stored in external store (id someid), " .
157 "can't serialize content object" )
158 ];
159 yield 'unknown user id and no user name' => [
160 [
161 'content' => new JavaScriptContent( 'hello world.' ),
162 'user' => 9989,
163 ],
164 new MWException( 'user_text not given, and unknown user ID 9989' )
165 ];
166 yield 'with bad content object (class)' => [
167 [ 'content' => new stdClass() ],
168 new MWException( 'content field must contain a Content object.' )
169 ];
170 yield 'with bad content object (string)' => [
171 [ 'content' => 'ImAGoat' ],
172 new MWException( 'content field must contain a Content object.' )
173 ];
174 yield 'bad row format' => [
175 'imastring, not a row',
176 new InvalidArgumentException(
177 '$row must be a row object, an associative array, or a RevisionRecord'
178 )
179 ];
180 }
181
182 /**
183 * @dataProvider provideConstructFromArrayThrowsExceptions
184 * @covers Revision::__construct
185 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
186 */
187 public function testConstructFromArrayThrowsExceptions( $rowArray, Exception $expectedException ) {
188 $this->setExpectedException(
189 get_class( $expectedException ),
190 $expectedException->getMessage(),
191 $expectedException->getCode()
192 );
193 new Revision( $rowArray, 0, $this->getMockTitle() );
194 }
195
196 /**
197 * @covers Revision::__construct
198 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
199 */
200 public function testConstructFromNothing() {
201 $this->setExpectedException(
202 InvalidArgumentException::class
203 );
204 new Revision( [] );
205 }
206
207 public function provideConstructFromRow() {
208 yield 'Full construction' => [
209 [
210 'rev_id' => '42',
211 'rev_page' => '23',
212 'rev_text_id' => '2',
213 'rev_timestamp' => '20171017114835',
214 'rev_user_text' => '127.0.0.1',
215 'rev_user' => '0',
216 'rev_minor_edit' => '0',
217 'rev_deleted' => '0',
218 'rev_len' => '46',
219 'rev_parent_id' => '1',
220 'rev_sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
221 'rev_comment_text' => 'Goat Comment!',
222 'rev_comment_data' => null,
223 'rev_comment_cid' => null,
224 'rev_content_format' => 'GOATFORMAT',
225 'rev_content_model' => 'GOATMODEL',
226 ],
227 function ( RevisionTest $testCase, Revision $rev ) {
228 $testCase->assertSame( 42, $rev->getId() );
229 $testCase->assertSame( 23, $rev->getPage() );
230 $testCase->assertSame( 2, $rev->getTextId() );
231 $testCase->assertSame( '20171017114835', $rev->getTimestamp() );
232 $testCase->assertSame( '127.0.0.1', $rev->getUserText() );
233 $testCase->assertSame( 0, $rev->getUser() );
234 $testCase->assertSame( false, $rev->isMinor() );
235 $testCase->assertSame( false, $rev->isDeleted( Revision::DELETED_TEXT ) );
236 $testCase->assertSame( 46, $rev->getSize() );
237 $testCase->assertSame( 1, $rev->getParentId() );
238 $testCase->assertSame( 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z', $rev->getSha1() );
239 $testCase->assertSame( 'Goat Comment!', $rev->getComment() );
240 $testCase->assertSame( 'GOATFORMAT', $rev->getContentFormat() );
241 $testCase->assertSame( 'GOATMODEL', $rev->getContentModel() );
242 }
243 ];
244 yield 'default field values' => [
245 [
246 'rev_id' => '42',
247 'rev_page' => '23',
248 'rev_text_id' => '2',
249 'rev_timestamp' => '20171017114835',
250 'rev_user_text' => '127.0.0.1',
251 'rev_user' => '0',
252 'rev_minor_edit' => '0',
253 'rev_deleted' => '0',
254 'rev_comment_text' => 'Goat Comment!',
255 'rev_comment_data' => null,
256 'rev_comment_cid' => null,
257 ],
258 function ( RevisionTest $testCase, Revision $rev ) {
259 // parent ID may be null
260 $testCase->assertSame( null, $rev->getParentId(), 'revision id' );
261
262 // given fields
263 $testCase->assertSame( $rev->getTimestamp(), '20171017114835', 'timestamp' );
264 $testCase->assertSame( $rev->getUserText(), '127.0.0.1', 'user name' );
265 $testCase->assertSame( $rev->getUser(), 0, 'user id' );
266 $testCase->assertSame( $rev->getComment(), 'Goat Comment!' );
267 $testCase->assertSame( false, $rev->isMinor(), 'minor edit' );
268 $testCase->assertSame( 0, $rev->getVisibility(), 'visibility flags' );
269
270 // computed fields
271 $testCase->assertNotNull( $rev->getSize(), 'size' );
272 $testCase->assertNotNull( $rev->getSha1(), 'hash' );
273
274 // NOTE: model and format will be detected based on the namespace of the (mock) title
275 $testCase->assertSame( 'text/x-wiki', $rev->getContentFormat(), 'format' );
276 $testCase->assertSame( 'wikitext', $rev->getContentModel(), 'model' );
277 }
278 ];
279 }
280
281 /**
282 * @dataProvider provideConstructFromRow
283 * @covers Revision::__construct
284 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
285 */
286 public function testConstructFromRow( array $arrayData, $assertions ) {
287 $data = 'Hello goat.'; // needs to match model and format
288
289 $blobStore = $this->getMockBuilder( SqlBlobStore::class )
290 ->disableOriginalConstructor()
291 ->getMock();
292
293 $blobStore->method( 'getBlob' )
294 ->will( $this->returnValue( $data ) );
295
296 $blobStore->method( 'getTextIdFromAddress' )
297 ->will( $this->returnCallback(
298 function ( $address ) {
299 // Turn "tt:1234" into 12345.
300 // Note that this must be functional so we can test getTextId().
301 // Ideally, we'd un-mock getTextIdFromAddress and use its actual implementation.
302 $parts = explode( ':', $address );
303 return (int)array_pop( $parts );
304 }
305 ) );
306
307 // Note override internal service, so RevisionStore uses it as well.
308 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
309
310 $row = (object)$arrayData;
311 $rev = new Revision( $row, 0, $this->getMockTitle() );
312 $assertions( $this, $rev );
313 }
314
315 /**
316 * @covers Revision::__construct
317 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
318 */
319 public function testConstructFromRowWithBadPageId() {
320 MediaWiki\suppressWarnings();
321 $rev = new Revision( (object)[ 'rev_page' => 77777777 ] );
322 $this->assertSame( 77777777, $rev->getPage() );
323 MediaWiki\restoreWarnings();
324 }
325
326 public function provideGetRevisionText() {
327 yield 'Generic test' => [
328 'This is a goat of revision text.',
329 [
330 'old_flags' => '',
331 'old_text' => 'This is a goat of revision text.',
332 ],
333 ];
334 }
335
336 public function provideGetId() {
337 yield [
338 [],
339 null
340 ];
341 yield [
342 [ 'id' => 998 ],
343 998
344 ];
345 }
346
347 /**
348 * @dataProvider provideGetId
349 * @covers Revision::getId
350 */
351 public function testGetId( $rowArray, $expectedId ) {
352 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
353 $this->assertEquals( $expectedId, $rev->getId() );
354 }
355
356 public function provideSetId() {
357 yield [ '123', 123 ];
358 yield [ 456, 456 ];
359 }
360
361 /**
362 * @dataProvider provideSetId
363 * @covers Revision::setId
364 */
365 public function testSetId( $input, $expected ) {
366 $rev = new Revision( [], 0, $this->getMockTitle() );
367 $rev->setId( $input );
368 $this->assertSame( $expected, $rev->getId() );
369 }
370
371 public function provideSetUserIdAndName() {
372 yield [ '123', 123, 'GOaT' ];
373 yield [ 456, 456, 'GOaT' ];
374 }
375
376 /**
377 * @dataProvider provideSetUserIdAndName
378 * @covers Revision::setUserIdAndName
379 */
380 public function testSetUserIdAndName( $inputId, $expectedId, $name ) {
381 $rev = new Revision( [], 0, $this->getMockTitle() );
382 $rev->setUserIdAndName( $inputId, $name );
383 $this->assertSame( $expectedId, $rev->getUser( Revision::RAW ) );
384 $this->assertEquals( $name, $rev->getUserText( Revision::RAW ) );
385 }
386
387 public function provideGetTextId() {
388 yield [ [], null ];
389 yield [ [ 'text_id' => '123' ], 123 ];
390 yield [ [ 'text_id' => 456 ], 456 ];
391 }
392
393 /**
394 * @dataProvider provideGetTextId
395 * @covers Revision::getTextId()
396 */
397 public function testGetTextId( $rowArray, $expected ) {
398 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
399 $this->assertSame( $expected, $rev->getTextId() );
400 }
401
402 public function provideGetParentId() {
403 yield [ [], null ];
404 yield [ [ 'parent_id' => '123' ], 123 ];
405 yield [ [ 'parent_id' => 456 ], 456 ];
406 }
407
408 /**
409 * @dataProvider provideGetParentId
410 * @covers Revision::getParentId()
411 */
412 public function testGetParentId( $rowArray, $expected ) {
413 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
414 $this->assertSame( $expected, $rev->getParentId() );
415 }
416
417 /**
418 * @covers Revision::getRevisionText
419 * @dataProvider provideGetRevisionText
420 */
421 public function testGetRevisionText( $expected, $rowData, $prefix = 'old_', $wiki = false ) {
422 $this->assertEquals(
423 $expected,
424 Revision::getRevisionText( (object)$rowData, $prefix, $wiki ) );
425 }
426
427 public function provideGetRevisionTextWithZlibExtension() {
428 yield 'Generic gzip test' => [
429 'This is a small goat of revision text.',
430 [
431 'old_flags' => 'gzip',
432 'old_text' => gzdeflate( 'This is a small goat of revision text.' ),
433 ],
434 ];
435 }
436
437 /**
438 * @covers Revision::getRevisionText
439 * @dataProvider provideGetRevisionTextWithZlibExtension
440 */
441 public function testGetRevisionWithZlibExtension( $expected, $rowData ) {
442 $this->checkPHPExtension( 'zlib' );
443 $this->testGetRevisionText( $expected, $rowData );
444 }
445
446 private function getWANObjectCache() {
447 return new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
448 }
449
450 /**
451 * @return SqlBlobStore
452 */
453 private function getBlobStore() {
454 /** @var LoadBalancer $lb */
455 $lb = $this->getMockBuilder( LoadBalancer::class )
456 ->disableOriginalConstructor()
457 ->getMock();
458
459 $cache = $this->getWANObjectCache();
460
461 $blobStore = new SqlBlobStore( $lb, $cache );
462 return $blobStore;
463 }
464
465 private function mockBlobStoreFactory( $blobStore ) {
466 /** @var LoadBalancer $lb */
467 $factory = $this->getMockBuilder( BlobStoreFactory::class )
468 ->disableOriginalConstructor()
469 ->getMock();
470 $factory->expects( $this->any() )
471 ->method( 'newBlobStore' )
472 ->willReturn( $blobStore );
473 $factory->expects( $this->any() )
474 ->method( 'newSqlBlobStore' )
475 ->willReturn( $blobStore );
476 return $factory;
477 }
478
479 /**
480 * @return RevisionStore
481 */
482 private function getRevisionStore() {
483 /** @var LoadBalancer $lb */
484 $lb = $this->getMockBuilder( LoadBalancer::class )
485 ->disableOriginalConstructor()
486 ->getMock();
487
488 $cache = $this->getWANObjectCache();
489
490 $blobStore = new RevisionStore( $lb, $this->getBlobStore(), $cache );
491 return $blobStore;
492 }
493
494 public function provideGetRevisionTextWithLegacyEncoding() {
495 yield 'Utf8Native' => [
496 "Wiki est l'\xc3\xa9cole superieur !",
497 'fr',
498 'iso-8859-1',
499 [
500 'old_flags' => 'utf-8',
501 'old_text' => "Wiki est l'\xc3\xa9cole superieur !",
502 ]
503 ];
504 yield 'Utf8Legacy' => [
505 "Wiki est l'\xc3\xa9cole superieur !",
506 'fr',
507 'iso-8859-1',
508 [
509 'old_flags' => '',
510 'old_text' => "Wiki est l'\xe9cole superieur !",
511 ]
512 ];
513 }
514
515 /**
516 * @covers Revision::getRevisionText
517 * @dataProvider provideGetRevisionTextWithLegacyEncoding
518 */
519 public function testGetRevisionWithLegacyEncoding( $expected, $lang, $encoding, $rowData ) {
520 $blobStore = $this->getBlobStore();
521 $blobStore->setLegacyEncoding( $encoding, Language::factory( $lang ) );
522 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
523
524 $this->testGetRevisionText( $expected, $rowData );
525 }
526
527 public function provideGetRevisionTextWithGzipAndLegacyEncoding() {
528 /**
529 * WARNING!
530 * Do not set the external flag!
531 * Otherwise, getRevisionText will hit the live database (if ExternalStore is enabled)!
532 */
533 yield 'Utf8NativeGzip' => [
534 "Wiki est l'\xc3\xa9cole superieur !",
535 'fr',
536 'iso-8859-1',
537 [
538 'old_flags' => 'gzip,utf-8',
539 'old_text' => gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" ),
540 ]
541 ];
542 yield 'Utf8LegacyGzip' => [
543 "Wiki est l'\xc3\xa9cole superieur !",
544 'fr',
545 'iso-8859-1',
546 [
547 'old_flags' => 'gzip',
548 'old_text' => gzdeflate( "Wiki est l'\xe9cole superieur !" ),
549 ]
550 ];
551 }
552
553 /**
554 * @covers Revision::getRevisionText
555 * @dataProvider provideGetRevisionTextWithGzipAndLegacyEncoding
556 */
557 public function testGetRevisionWithGzipAndLegacyEncoding( $expected, $lang, $encoding, $rowData ) {
558 $this->checkPHPExtension( 'zlib' );
559
560 $blobStore = $this->getBlobStore();
561 $blobStore->setLegacyEncoding( $encoding, Language::factory( $lang ) );
562 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
563
564 $this->testGetRevisionText( $expected, $rowData );
565 }
566
567 /**
568 * @covers Revision::compressRevisionText
569 */
570 public function testCompressRevisionTextUtf8() {
571 $row = new stdClass;
572 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
573 $row->old_flags = Revision::compressRevisionText( $row->old_text );
574 $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
575 "Flags should contain 'utf-8'" );
576 $this->assertFalse( false !== strpos( $row->old_flags, 'gzip' ),
577 "Flags should not contain 'gzip'" );
578 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
579 $row->old_text, "Direct check" );
580 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
581 Revision::getRevisionText( $row ), "getRevisionText" );
582 }
583
584 /**
585 * @covers Revision::compressRevisionText
586 */
587 public function testCompressRevisionTextUtf8Gzip() {
588 $this->checkPHPExtension( 'zlib' );
589
590 $blobStore = $this->getBlobStore();
591 $blobStore->setCompressBlobs( true );
592 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
593
594 $row = new stdClass;
595 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
596 $row->old_flags = Revision::compressRevisionText( $row->old_text );
597 $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
598 "Flags should contain 'utf-8'" );
599 $this->assertTrue( false !== strpos( $row->old_flags, 'gzip' ),
600 "Flags should contain 'gzip'" );
601 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
602 gzinflate( $row->old_text ), "Direct check" );
603 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
604 Revision::getRevisionText( $row ), "getRevisionText" );
605 }
606
607 /**
608 * @covers Revision::loadFromTitle
609 */
610 public function testLoadFromTitle() {
611 $title = $this->getMockTitle();
612
613 $conditions = [
614 'rev_id=page_latest',
615 'page_namespace' => $title->getNamespace(),
616 'page_title' => $title->getDBkey()
617 ];
618
619 $row = (object)[
620 'rev_id' => '42',
621 'rev_page' => $title->getArticleID(),
622 'rev_text_id' => '2',
623 'rev_timestamp' => '20171017114835',
624 'rev_user_text' => '127.0.0.1',
625 'rev_user' => '0',
626 'rev_minor_edit' => '0',
627 'rev_deleted' => '0',
628 'rev_len' => '46',
629 'rev_parent_id' => '1',
630 'rev_sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
631 'rev_comment_text' => 'Goat Comment!',
632 'rev_comment_data' => null,
633 'rev_comment_cid' => null,
634 'rev_content_format' => 'GOATFORMAT',
635 'rev_content_model' => 'GOATMODEL',
636 ];
637
638 $db = $this->getMock( IDatabase::class );
639 $db->expects( $this->any() )
640 ->method( 'getDomainId' )
641 ->will( $this->returnValue( wfWikiID() ) );
642 $db->expects( $this->once() )
643 ->method( 'selectRow' )
644 ->with(
645 $this->equalTo( [ 'revision', 'page', 'user' ] ),
646 // We don't really care about the fields are they come from the selectField methods
647 $this->isType( 'array' ),
648 $this->equalTo( $conditions ),
649 // Method name
650 $this->stringContains( 'fetchRevisionRowFromConds' ),
651 // We don't really care about the options here
652 $this->isType( 'array' ),
653 // We don't really care about the join conds are they come from the joinCond methods
654 $this->isType( 'array' )
655 )
656 ->willReturn( $row );
657
658 $revision = Revision::loadFromTitle( $db, $title );
659
660 $this->assertEquals( $title->getArticleID(), $revision->getTitle()->getArticleID() );
661 $this->assertEquals( $row->rev_id, $revision->getId() );
662 $this->assertEquals( $row->rev_len, $revision->getSize() );
663 $this->assertEquals( $row->rev_sha1, $revision->getSha1() );
664 $this->assertEquals( $row->rev_parent_id, $revision->getParentId() );
665 $this->assertEquals( $row->rev_timestamp, $revision->getTimestamp() );
666 $this->assertEquals( $row->rev_comment_text, $revision->getComment() );
667 $this->assertEquals( $row->rev_user_text, $revision->getUserText() );
668 }
669
670 public function provideDecompressRevisionText() {
671 yield '(no legacy encoding), false in false out' => [ false, false, [], false ];
672 yield '(no legacy encoding), empty in empty out' => [ false, '', [], '' ];
673 yield '(no legacy encoding), empty in empty out' => [ false, 'A', [], 'A' ];
674 yield '(no legacy encoding), string in with gzip flag returns string' => [
675 // gzip string below generated with gzdeflate( 'AAAABBAAA' )
676 false, "sttttr\002\022\000", [ 'gzip' ], 'AAAABBAAA',
677 ];
678 yield '(no legacy encoding), string in with object flag returns false' => [
679 // gzip string below generated with serialize( 'JOJO' )
680 false, "s:4:\"JOJO\";", [ 'object' ], false,
681 ];
682 yield '(no legacy encoding), serialized object in with object flag returns string' => [
683 false,
684 // Using a TitleValue object as it has a getText method (which is needed)
685 serialize( new TitleValue( 0, 'HHJJDDFF' ) ),
686 [ 'object' ],
687 'HHJJDDFF',
688 ];
689 yield '(no legacy encoding), serialized object in with object & gzip flag returns string' => [
690 false,
691 // Using a TitleValue object as it has a getText method (which is needed)
692 gzdeflate( serialize( new TitleValue( 0, '8219JJJ840' ) ) ),
693 [ 'object', 'gzip' ],
694 '8219JJJ840',
695 ];
696 yield '(ISO-8859-1 encoding), string in string out' => [
697 'ISO-8859-1',
698 iconv( 'utf-8', 'ISO-8859-1', "1®Àþ1" ),
699 [],
700 '1®Àþ1',
701 ];
702 yield '(ISO-8859-1 encoding), serialized object in with gzip flags returns string' => [
703 'ISO-8859-1',
704 gzdeflate( iconv( 'utf-8', 'ISO-8859-1', "4®Àþ4" ) ),
705 [ 'gzip' ],
706 '4®Àþ4',
707 ];
708 yield '(ISO-8859-1 encoding), serialized object in with object flags returns string' => [
709 'ISO-8859-1',
710 serialize( new TitleValue( 0, iconv( 'utf-8', 'ISO-8859-1', "3®Àþ3" ) ) ),
711 [ 'object' ],
712 '3®Àþ3',
713 ];
714 yield '(ISO-8859-1 encoding), serialized object in with object & gzip flags returns string' => [
715 'ISO-8859-1',
716 gzdeflate( serialize( new TitleValue( 0, iconv( 'utf-8', 'ISO-8859-1', "2®Àþ2" ) ) ) ),
717 [ 'gzip', 'object' ],
718 '2®Àþ2',
719 ];
720 }
721
722 /**
723 * @dataProvider provideDecompressRevisionText
724 * @covers Revision::decompressRevisionText
725 *
726 * @param bool $legacyEncoding
727 * @param mixed $text
728 * @param array $flags
729 * @param mixed $expected
730 */
731 public function testDecompressRevisionText( $legacyEncoding, $text, $flags, $expected ) {
732 $blobStore = $this->getBlobStore();
733 if ( $legacyEncoding ) {
734 $blobStore->setLegacyEncoding( $legacyEncoding, Language::factory( 'en' ) );
735 }
736
737 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
738 $this->assertSame(
739 $expected,
740 Revision::decompressRevisionText( $text, $flags )
741 );
742 }
743
744 /**
745 * @covers Revision::getRevisionText
746 */
747 public function testGetRevisionText_returnsFalseWhenNoTextField() {
748 $this->assertFalse( Revision::getRevisionText( new stdClass() ) );
749 }
750
751 public function provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal() {
752 yield 'Just text' => [
753 (object)[ 'old_text' => 'SomeText' ],
754 'old_',
755 'SomeText'
756 ];
757 // gzip string below generated with gzdeflate( 'AAAABBAAA' )
758 yield 'gzip text' => [
759 (object)[
760 'old_text' => "sttttr\002\022\000",
761 'old_flags' => 'gzip'
762 ],
763 'old_',
764 'AAAABBAAA'
765 ];
766 yield 'gzip text and different prefix' => [
767 (object)[
768 'jojo_text' => "sttttr\002\022\000",
769 'jojo_flags' => 'gzip'
770 ],
771 'jojo_',
772 'AAAABBAAA'
773 ];
774 }
775
776 /**
777 * @dataProvider provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal
778 * @covers Revision::getRevisionText
779 */
780 public function testGetRevisionText_returnsDecompressedTextFieldWhenNotExternal(
781 $row,
782 $prefix,
783 $expected
784 ) {
785 $this->assertSame( $expected, Revision::getRevisionText( $row, $prefix ) );
786 }
787
788 public function provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts() {
789 yield 'Just some text' => [ 'someNonUrlText' ];
790 yield 'No second URL part' => [ 'someProtocol://' ];
791 }
792
793 /**
794 * @dataProvider provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts
795 * @covers Revision::getRevisionText
796 */
797 public function testGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts(
798 $text
799 ) {
800 $this->assertFalse(
801 Revision::getRevisionText(
802 (object)[
803 'old_text' => $text,
804 'old_flags' => 'external',
805 ]
806 )
807 );
808 }
809
810 /**
811 * @covers Revision::getRevisionText
812 */
813 public function testGetRevisionText_external_noOldId() {
814 $this->setService(
815 'ExternalStoreFactory',
816 new ExternalStoreFactory( [ 'ForTesting' ] )
817 );
818 $this->assertSame(
819 'AAAABBAAA',
820 Revision::getRevisionText(
821 (object)[
822 'old_text' => 'ForTesting://cluster1/12345',
823 'old_flags' => 'external,gzip',
824 ]
825 )
826 );
827 }
828
829 /**
830 * @covers Revision::getRevisionText
831 */
832 public function testGetRevisionText_external_oldId() {
833 $cache = $this->getWANObjectCache();
834 $this->setService( 'MainWANObjectCache', $cache );
835
836 $this->setService(
837 'ExternalStoreFactory',
838 new ExternalStoreFactory( [ 'ForTesting' ] )
839 );
840
841 $lb = $this->getMockBuilder( LoadBalancer::class )
842 ->disableOriginalConstructor()
843 ->getMock();
844
845 $blobStore = new SqlBlobStore( $lb, $cache );
846 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
847
848 $this->assertSame(
849 'AAAABBAAA',
850 Revision::getRevisionText(
851 (object)[
852 'old_text' => 'ForTesting://cluster1/12345',
853 'old_flags' => 'external,gzip',
854 'old_id' => '7777',
855 ]
856 )
857 );
858
859 $cacheKey = $cache->makeKey( 'revisiontext', 'textid', 'tt:7777' );
860 $this->assertSame( 'AAAABBAAA', $cache->get( $cacheKey ) );
861 }
862
863 /**
864 * @covers Revision::userJoinCond
865 */
866 public function testUserJoinCond() {
867 $this->hideDeprecated( 'Revision::userJoinCond' );
868 $this->assertEquals(
869 [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
870 Revision::userJoinCond()
871 );
872 }
873
874 /**
875 * @covers Revision::pageJoinCond
876 */
877 public function testPageJoinCond() {
878 $this->hideDeprecated( 'Revision::pageJoinCond' );
879 $this->assertEquals(
880 [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
881 Revision::pageJoinCond()
882 );
883 }
884
885 private function overrideCommentStore() {
886 $mockStore = $this->getMockBuilder( CommentStore::class )
887 ->disableOriginalConstructor()
888 ->getMock();
889 $mockStore->expects( $this->any() )
890 ->method( 'getFields' )
891 ->willReturn( [ 'commentstore' => 'fields' ] );
892 $mockStore->expects( $this->any() )
893 ->method( 'getJoin' )
894 ->willReturn( [
895 'tables' => [ 'commentstore' => 'table' ],
896 'fields' => [ 'commentstore' => 'field' ],
897 'joins' => [ 'commentstore' => 'join' ],
898 ] );
899
900 $this->setService( 'CommentStore', $mockStore );
901 }
902
903 public function provideSelectFields() {
904 yield [
905 true,
906 [
907 'rev_id',
908 'rev_page',
909 'rev_text_id',
910 'rev_timestamp',
911 'rev_user_text',
912 'rev_user',
913 'rev_minor_edit',
914 'rev_deleted',
915 'rev_len',
916 'rev_parent_id',
917 'rev_sha1',
918 'commentstore' => 'fields',
919 'rev_content_format',
920 'rev_content_model',
921 ]
922 ];
923 yield [
924 false,
925 [
926 'rev_id',
927 'rev_page',
928 'rev_text_id',
929 'rev_timestamp',
930 'rev_user_text',
931 'rev_user',
932 'rev_minor_edit',
933 'rev_deleted',
934 'rev_len',
935 'rev_parent_id',
936 'rev_sha1',
937 'commentstore' => 'fields',
938 ]
939 ];
940 }
941
942 /**
943 * @dataProvider provideSelectFields
944 * @covers Revision::selectFields
945 */
946 public function testSelectFields( $contentHandlerUseDB, $expected ) {
947 $this->hideDeprecated( 'Revision::selectFields' );
948 $this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB );
949 $this->overrideCommentStore();
950 $this->assertEquals( $expected, Revision::selectFields() );
951 }
952
953 public function provideSelectArchiveFields() {
954 yield [
955 true,
956 [
957 'ar_id',
958 'ar_page_id',
959 'ar_rev_id',
960 'ar_text',
961 'ar_text_id',
962 'ar_timestamp',
963 'ar_user_text',
964 'ar_user',
965 'ar_minor_edit',
966 'ar_deleted',
967 'ar_len',
968 'ar_parent_id',
969 'ar_sha1',
970 'commentstore' => 'fields',
971 'ar_content_format',
972 'ar_content_model',
973 ]
974 ];
975 yield [
976 false,
977 [
978 'ar_id',
979 'ar_page_id',
980 'ar_rev_id',
981 'ar_text',
982 'ar_text_id',
983 'ar_timestamp',
984 'ar_user_text',
985 'ar_user',
986 'ar_minor_edit',
987 'ar_deleted',
988 'ar_len',
989 'ar_parent_id',
990 'ar_sha1',
991 'commentstore' => 'fields',
992 ]
993 ];
994 }
995
996 /**
997 * @dataProvider provideSelectArchiveFields
998 * @covers Revision::selectArchiveFields
999 */
1000 public function testSelectArchiveFields( $contentHandlerUseDB, $expected ) {
1001 $this->hideDeprecated( 'Revision::selectArchiveFields' );
1002 $this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB );
1003 $this->overrideCommentStore();
1004 $this->assertEquals( $expected, Revision::selectArchiveFields() );
1005 }
1006
1007 /**
1008 * @covers Revision::selectTextFields
1009 */
1010 public function testSelectTextFields() {
1011 $this->hideDeprecated( 'Revision::selectTextFields' );
1012 $this->assertEquals(
1013 [
1014 'old_text',
1015 'old_flags',
1016 ],
1017 Revision::selectTextFields()
1018 );
1019 }
1020
1021 /**
1022 * @covers Revision::selectPageFields
1023 */
1024 public function testSelectPageFields() {
1025 $this->hideDeprecated( 'Revision::selectPageFields' );
1026 $this->assertEquals(
1027 [
1028 'page_namespace',
1029 'page_title',
1030 'page_id',
1031 'page_latest',
1032 'page_is_redirect',
1033 'page_len',
1034 ],
1035 Revision::selectPageFields()
1036 );
1037 }
1038
1039 /**
1040 * @covers Revision::selectUserFields
1041 */
1042 public function testSelectUserFields() {
1043 $this->hideDeprecated( 'Revision::selectUserFields' );
1044 $this->assertEquals(
1045 [
1046 'user_name',
1047 ],
1048 Revision::selectUserFields()
1049 );
1050 }
1051
1052 public function provideGetArchiveQueryInfo() {
1053 yield 'wgContentHandlerUseDB false' => [
1054 [
1055 'wgContentHandlerUseDB' => false,
1056 ],
1057 [
1058 'tables' => [
1059 'archive',
1060 'commentstore' => 'table',
1061 ],
1062 'fields' => [
1063 'ar_id',
1064 'ar_page_id',
1065 'ar_namespace',
1066 'ar_title',
1067 'ar_rev_id',
1068 'ar_text',
1069 'ar_text_id',
1070 'ar_timestamp',
1071 'ar_user_text',
1072 'ar_user',
1073 'ar_minor_edit',
1074 'ar_deleted',
1075 'ar_len',
1076 'ar_parent_id',
1077 'ar_sha1',
1078 'commentstore' => 'field'
1079 ],
1080 'joins' => [ 'commentstore' => 'join' ],
1081 ]
1082 ];
1083 yield 'wgContentHandlerUseDB true' => [
1084 [
1085 'wgContentHandlerUseDB' => true,
1086 ],
1087 [
1088 'tables' => [
1089 'archive',
1090 'commentstore' => 'table',
1091 ],
1092 'fields' => [
1093 'ar_id',
1094 'ar_page_id',
1095 'ar_namespace',
1096 'ar_title',
1097 'ar_rev_id',
1098 'ar_text',
1099 'ar_text_id',
1100 'ar_timestamp',
1101 'ar_user_text',
1102 'ar_user',
1103 'ar_minor_edit',
1104 'ar_deleted',
1105 'ar_len',
1106 'ar_parent_id',
1107 'ar_sha1',
1108 'commentstore' => 'field',
1109 'ar_content_format',
1110 'ar_content_model',
1111 ],
1112 'joins' => [ 'commentstore' => 'join' ],
1113 ]
1114 ];
1115 }
1116
1117 /**
1118 * @covers Revision::getArchiveQueryInfo
1119 * @dataProvider provideGetArchiveQueryInfo
1120 */
1121 public function testGetArchiveQueryInfo( $globals, $expected ) {
1122 $this->setMwGlobals( $globals );
1123 $this->overrideCommentStore();
1124
1125 $revisionStore = $this->getRevisionStore();
1126 $revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] );
1127 $this->setService( 'RevisionStore', $revisionStore );
1128 $this->assertEquals(
1129 $expected,
1130 Revision::getArchiveQueryInfo()
1131 );
1132 }
1133
1134 public function provideGetQueryInfo() {
1135 yield 'wgContentHandlerUseDB false, opts none' => [
1136 [
1137 'wgContentHandlerUseDB' => false,
1138 ],
1139 [],
1140 [
1141 'tables' => [ 'revision', 'commentstore' => 'table' ],
1142 'fields' => [
1143 'rev_id',
1144 'rev_page',
1145 'rev_text_id',
1146 'rev_timestamp',
1147 'rev_user_text',
1148 'rev_user',
1149 'rev_minor_edit',
1150 'rev_deleted',
1151 'rev_len',
1152 'rev_parent_id',
1153 'rev_sha1',
1154 'commentstore' => 'field',
1155 ],
1156 'joins' => [ 'commentstore' => 'join' ],
1157 ],
1158 ];
1159 yield 'wgContentHandlerUseDB false, opts page' => [
1160 [
1161 'wgContentHandlerUseDB' => false,
1162 ],
1163 [ 'page' ],
1164 [
1165 'tables' => [ 'revision', 'commentstore' => 'table', 'page' ],
1166 'fields' => [
1167 'rev_id',
1168 'rev_page',
1169 'rev_text_id',
1170 'rev_timestamp',
1171 'rev_user_text',
1172 'rev_user',
1173 'rev_minor_edit',
1174 'rev_deleted',
1175 'rev_len',
1176 'rev_parent_id',
1177 'rev_sha1',
1178 'commentstore' => 'field',
1179 'page_namespace',
1180 'page_title',
1181 'page_id',
1182 'page_latest',
1183 'page_is_redirect',
1184 'page_len',
1185 ],
1186 'joins' => [
1187 'page' => [
1188 'INNER JOIN',
1189 [ 'page_id = rev_page' ],
1190 ],
1191 'commentstore' => 'join',
1192 ],
1193 ],
1194 ];
1195 yield 'wgContentHandlerUseDB false, opts user' => [
1196 [
1197 'wgContentHandlerUseDB' => false,
1198 ],
1199 [ 'user' ],
1200 [
1201 'tables' => [ 'revision', 'commentstore' => 'table', 'user' ],
1202 'fields' => [
1203 'rev_id',
1204 'rev_page',
1205 'rev_text_id',
1206 'rev_timestamp',
1207 'rev_user_text',
1208 'rev_user',
1209 'rev_minor_edit',
1210 'rev_deleted',
1211 'rev_len',
1212 'rev_parent_id',
1213 'rev_sha1',
1214 'commentstore' => 'field',
1215 'user_name',
1216 ],
1217 'joins' => [
1218 'user' => [
1219 'LEFT JOIN',
1220 [
1221 'rev_user != 0',
1222 'user_id = rev_user',
1223 ],
1224 ],
1225 'commentstore' => 'join',
1226 ],
1227 ],
1228 ];
1229 yield 'wgContentHandlerUseDB false, opts text' => [
1230 [
1231 'wgContentHandlerUseDB' => false,
1232 ],
1233 [ 'text' ],
1234 [
1235 'tables' => [ 'revision', 'commentstore' => 'table', 'text' ],
1236 'fields' => [
1237 'rev_id',
1238 'rev_page',
1239 'rev_text_id',
1240 'rev_timestamp',
1241 'rev_user_text',
1242 'rev_user',
1243 'rev_minor_edit',
1244 'rev_deleted',
1245 'rev_len',
1246 'rev_parent_id',
1247 'rev_sha1',
1248 'commentstore' => 'field',
1249 'old_text',
1250 'old_flags',
1251 ],
1252 'joins' => [
1253 'text' => [
1254 'INNER JOIN',
1255 [ 'rev_text_id=old_id' ],
1256 ],
1257 'commentstore' => 'join',
1258 ],
1259 ],
1260 ];
1261 yield 'wgContentHandlerUseDB false, opts 3' => [
1262 [
1263 'wgContentHandlerUseDB' => false,
1264 ],
1265 [ 'text', 'page', 'user' ],
1266 [
1267 'tables' => [ 'revision', 'commentstore' => 'table', 'page', 'user', 'text' ],
1268 'fields' => [
1269 'rev_id',
1270 'rev_page',
1271 'rev_text_id',
1272 'rev_timestamp',
1273 'rev_user_text',
1274 'rev_user',
1275 'rev_minor_edit',
1276 'rev_deleted',
1277 'rev_len',
1278 'rev_parent_id',
1279 'rev_sha1',
1280 'commentstore' => 'field',
1281 'page_namespace',
1282 'page_title',
1283 'page_id',
1284 'page_latest',
1285 'page_is_redirect',
1286 'page_len',
1287 'user_name',
1288 'old_text',
1289 'old_flags',
1290 ],
1291 'joins' => [
1292 'page' => [
1293 'INNER JOIN',
1294 [ 'page_id = rev_page' ],
1295 ],
1296 'user' => [
1297 'LEFT JOIN',
1298 [
1299 'rev_user != 0',
1300 'user_id = rev_user',
1301 ],
1302 ],
1303 'text' => [
1304 'INNER JOIN',
1305 [ 'rev_text_id=old_id' ],
1306 ],
1307 'commentstore' => 'join',
1308 ],
1309 ],
1310 ];
1311 yield 'wgContentHandlerUseDB true, opts none' => [
1312 [
1313 'wgContentHandlerUseDB' => true,
1314 ],
1315 [],
1316 [
1317 'tables' => [ 'revision', 'commentstore' => 'table' ],
1318 'fields' => [
1319 'rev_id',
1320 'rev_page',
1321 'rev_text_id',
1322 'rev_timestamp',
1323 'rev_user_text',
1324 'rev_user',
1325 'rev_minor_edit',
1326 'rev_deleted',
1327 'rev_len',
1328 'rev_parent_id',
1329 'rev_sha1',
1330 'commentstore' => 'field',
1331 'rev_content_format',
1332 'rev_content_model',
1333 ],
1334 'joins' => [ 'commentstore' => 'join' ],
1335 ],
1336 ];
1337 }
1338
1339 /**
1340 * @covers Revision::getQueryInfo
1341 * @dataProvider provideGetQueryInfo
1342 */
1343 public function testGetQueryInfo( $globals, $options, $expected ) {
1344 $this->setMwGlobals( $globals );
1345 $this->overrideCommentStore();
1346
1347 $revisionStore = $this->getRevisionStore();
1348 $revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] );
1349 $this->setService( 'RevisionStore', $revisionStore );
1350
1351 $this->assertEquals(
1352 $expected,
1353 Revision::getQueryInfo( $options )
1354 );
1355 }
1356
1357 /**
1358 * @covers Revision::getSize
1359 */
1360 public function testGetSize() {
1361 $title = $this->getMockTitle();
1362
1363 $rec = new MutableRevisionRecord( $title );
1364 $rev = new Revision( $rec, 0, $title );
1365
1366 $this->assertSame( 0, $rev->getSize(), 'Size of no slots is 0' );
1367
1368 $rec->setSize( 13 );
1369 $this->assertSame( 13, $rev->getSize() );
1370 }
1371
1372 /**
1373 * @covers Revision::getSize
1374 */
1375 public function testGetSize_failure() {
1376 $title = $this->getMockTitle();
1377
1378 $rec = $this->getMockBuilder( RevisionRecord::class )
1379 ->disableOriginalConstructor()
1380 ->getMock();
1381
1382 $rec->method( 'getSize' )
1383 ->willThrowException( new RevisionAccessException( 'Oops!' ) );
1384
1385 $rev = new Revision( $rec, 0, $title );
1386 $this->assertNull( $rev->getSize() );
1387 }
1388
1389 /**
1390 * @covers Revision::getSha1
1391 */
1392 public function testGetSha1() {
1393 $title = $this->getMockTitle();
1394
1395 $rec = new MutableRevisionRecord( $title );
1396 $rev = new Revision( $rec, 0, $title );
1397
1398 $emptyHash = SlotRecord::base36Sha1( '' );
1399 $this->assertSame( $emptyHash, $rev->getSha1(), 'Sha1 of no slots is hash of empty string' );
1400
1401 $rec->setSha1( 'deadbeef' );
1402 $this->assertSame( 'deadbeef', $rev->getSha1() );
1403 }
1404
1405 /**
1406 * @covers Revision::getSha1
1407 */
1408 public function testGetSha1_failure() {
1409 $title = $this->getMockTitle();
1410
1411 $rec = $this->getMockBuilder( RevisionRecord::class )
1412 ->disableOriginalConstructor()
1413 ->getMock();
1414
1415 $rec->method( 'getSha1' )
1416 ->willThrowException( new RevisionAccessException( 'Oops!' ) );
1417
1418 $rev = new Revision( $rec, 0, $title );
1419 $this->assertNull( $rev->getSha1() );
1420 }
1421
1422 /**
1423 * @covers Revision::getContent
1424 */
1425 public function testGetContent() {
1426 $title = $this->getMockTitle();
1427
1428 $rec = new MutableRevisionRecord( $title );
1429 $rev = new Revision( $rec, 0, $title );
1430
1431 $this->assertNull( $rev->getContent(), 'Content of no slots is null' );
1432
1433 $content = new TextContent( 'Hello Kittens!' );
1434 $rec->setContent( 'main', $content );
1435 $this->assertSame( $content, $rev->getContent() );
1436 }
1437
1438 /**
1439 * @covers Revision::getContent
1440 */
1441 public function testGetContent_failure() {
1442 $title = $this->getMockTitle();
1443
1444 $rec = $this->getMockBuilder( RevisionRecord::class )
1445 ->disableOriginalConstructor()
1446 ->getMock();
1447
1448 $rec->method( 'getContent' )
1449 ->willThrowException( new RevisionAccessException( 'Oops!' ) );
1450
1451 $rev = new Revision( $rec, 0, $title );
1452 $this->assertNull( $rev->getContent() );
1453 }
1454
1455 }