MediaWiki REL1_33
RevisionStoreCacheRecordTest.php
Go to the documentation of this file.
1<?php
3
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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
CommentStoreComment represents a comment stored by CommentStore.
Page revision base class.
Value object representing the set of slots belonging to a revision.
A RevisionRecord representing an existing revision persisted in the revision table.
Value object representing a content slot associated with a page revision.
\MediaWiki\Revision\RevisionStoreCacheRecord \MediaWiki\Revision\RevisionStoreRecord \MediaWiki\Revis...
\MediaWiki\Revision\RevisionStoreRecord \MediaWiki\Revision\RevisionRecord
Value object representing a user's identity.
Content object implementation for representing flat text.
Represents a title within MediaWiki.
Definition Title.php:40
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
return true to allow those checks to and false if checking is done & $user
Definition hooks.txt:1510
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:1779
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:37
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))