MediaWiki  1.33.0
RevisionStoreCacheRecordTest.php
Go to the documentation of this file.
1 <?php
3 
4 use Title;
13 
20 
27  protected function newRevision( array $rowOverrides = [], $callback = false ) {
28  $title = Title::newFromText( 'Dummy' );
29  $title->resetArticleID( 17 );
30 
31  $user = new UserIdentityValue( 11, 'Tester', 0 );
32  $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
33 
34  $main = SlotRecord::newUnsaved( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
35  $aux = SlotRecord::newUnsaved( 'aux', new TextContent( 'Frumious Bandersnatch' ) );
36  $slots = new RevisionSlots( [ $main, $aux ] );
37 
38  $row = [
39  'rev_id' => '7',
40  'rev_page' => strval( $title->getArticleID() ),
41  'rev_timestamp' => '20200101000000',
42  'rev_deleted' => 0,
43  'rev_minor_edit' => 0,
44  'rev_parent_id' => '5',
45  'rev_len' => $slots->computeSize(),
46  'rev_sha1' => $slots->computeSha1(),
47  'rev_user' => '11',
48  'page_latest' => '18',
49  ];
50 
51  $row = array_merge( $row, $rowOverrides );
52 
53  if ( !$callback ) {
54  $callback = function ( $revId ) use ( $row ) {
55  return (object)$row;
56  };
57  }
58 
59  return new RevisionStoreCacheRecord(
60  $callback,
61  $title,
62  $user,
63  $comment,
64  (object)$row,
65  $slots
66  );
67  }
68 
69  public function testCallback() {
70  // Provide a callback that returns non-default values. Asserting the revision returns
71  // these values confirms callback execution and behavior. Also confirm the callback
72  // is only invoked once, even for multiple getter calls.
73  $rowOverrides = [
74  'rev_deleted' => RevisionRecord::DELETED_TEXT,
75  'rev_user' => 12,
76  ];
77  $callbackInvoked = 0;
78  $callback = function ( $revId ) use ( &$callbackInvoked, $rowOverrides ) {
79  $callbackInvoked++;
80  return (object)$rowOverrides;
81  };
82  $rev = $this->newRevision( [], $callback );
83 
84  $this->assertSame( RevisionRecord::DELETED_TEXT, $rev->getVisibility() );
85  $this->assertSame( 12, $rev->getUser()->getId() );
86  $this->assertSame( 1, $callbackInvoked );
87  }
88 
89 }
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
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
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:306
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:45
MediaWiki\Tests\Revision\RevisionStoreCacheRecordTest\newRevision
newRevision(array $rowOverrides=[], $callback=false)
Definition: RevisionStoreCacheRecordTest.php:27
Revision\RevisionStoreCacheRecord
A cached RevisionStoreRecord.
Definition: RevisionStoreCacheRecord.php:38
MediaWiki\Tests\Revision
Definition: FallbackSlotRoleHandlerTest.php:3
MediaWiki\Tests\Revision\RevisionStoreRecordTest
\MediaWiki\Revision\RevisionStoreRecord \MediaWiki\Revision\RevisionRecord
Definition: RevisionStoreRecordTest.php:21
MediaWiki\Tests\Revision\RevisionStoreCacheRecordTest\testCallback
testCallback()
Definition: RevisionStoreCacheRecordTest.php:69
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:925
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
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\RevisionStoreCacheRecordTest
\MediaWiki\Revision\RevisionStoreCacheRecord \MediaWiki\Revision\RevisionStoreRecord \MediaWiki\Revis...
Definition: RevisionStoreCacheRecordTest.php:19
Revision\RevisionStoreRecord
A RevisionRecord representing an existing revision persisted in the revision table.
Definition: RevisionStoreRecord.php:39
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:40
$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:1769
Revision\RevisionRecord\DELETED_TEXT
const DELETED_TEXT
Definition: RevisionRecord.php:48
Revision\RevisionSlots
Value object representing the set of slots belonging to a revision.
Definition: RevisionSlots.php:35
CommentStoreComment
CommentStoreComment represents a comment stored by CommentStore.
Definition: CommentStoreComment.php:29
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39