MediaWiki  master
RevisionStoreCacheRecordTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Title;
14 
21 
28  protected function newRevision( array $rowOverrides = [], $callback = false ) {
29  $title = Title::newFromText( 'Dummy' );
30  $title->resetArticleID( 17 );
31 
32  $user = new UserIdentityValue( 11, 'Tester', 0 );
33  $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
34 
35  $main = SlotRecord::newUnsaved( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
36  $aux = SlotRecord::newUnsaved( 'aux', new TextContent( 'Frumious Bandersnatch' ) );
37  $slots = new RevisionSlots( [ $main, $aux ] );
38 
39  $row = [
40  'rev_id' => '7',
41  'rev_page' => strval( $title->getArticleID() ),
42  'rev_timestamp' => '20200101000000',
43  'rev_deleted' => 0,
44  'rev_minor_edit' => 0,
45  'rev_parent_id' => '5',
46  'rev_len' => $slots->computeSize(),
47  'rev_sha1' => $slots->computeSha1(),
48  'rev_user' => '11',
49  'page_latest' => '18',
50  ];
51 
52  $row = array_merge( $row, $rowOverrides );
53 
54  if ( !$callback ) {
55  $callback = function ( $revId ) use ( $row ) {
56  return (object)$row;
57  };
58  }
59 
60  return new RevisionStoreCacheRecord(
61  $callback,
62  $title,
63  $user,
64  $comment,
65  (object)$row,
66  $slots
67  );
68  }
69 
70  public function testCallback() {
71  // Provide a callback that returns non-default values. Asserting the revision returns
72  // these values confirms callback execution and behavior. Also confirm the callback
73  // is only invoked once, even for multiple getter calls.
74  $rowOverrides = [
75  'rev_deleted' => RevisionRecord::DELETED_TEXT,
76  'rev_user' => 12,
77  ];
78  $callbackInvoked = 0;
79  $callback = function ( $revId ) use ( &$callbackInvoked, $rowOverrides ) {
80  $callbackInvoked++;
81  return (object)$rowOverrides;
82  };
83  $rev = $this->newRevision( [], $callback );
84 
85  $this->assertSame( RevisionRecord::DELETED_TEXT, $rev->getVisibility() );
86  $this->assertSame( 12, $rev->getUser()->getId() );
87  $this->assertSame( 1, $callbackInvoked );
88  }
89 
90 }
\MediaWiki\Revision\RevisionStoreRecord \MediaWiki\Revision\RevisionRecord
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
\MediaWiki\Revision\RevisionStoreCacheRecord \MediaWiki\Revision\RevisionStoreRecord \MediaWiki\Revis...
Value object representing a user&#39;s identity.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
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:1747
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
static newUnsaved( $role, Content $content)
Constructs a new Slot from a Content object for a new revision.
Definition: SlotRecord.php:129
Value object representing the set of slots belonging to a revision.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1454
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:321