MediaWiki  REL1_31
MutableRevisionRecordTest.php
Go to the documentation of this file.
1 <?php
2 
4 
6 use InvalidArgumentException;
14 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  $record = new MutableRevisionRecord( $title );
38 
39  if ( isset( $rowOverrides['rev_deleted'] ) ) {
40  $record->setVisibility( $rowOverrides['rev_deleted'] );
41  }
42 
43  if ( isset( $rowOverrides['rev_id'] ) ) {
44  $record->setId( $rowOverrides['rev_id'] );
45  }
46 
47  if ( isset( $rowOverrides['rev_page'] ) ) {
48  $record->setPageId( $rowOverrides['rev_page'] );
49  }
50 
51  $record->setContent( 'main', new TextContent( 'Lorem Ipsum' ) );
52  $record->setComment( $comment );
53  $record->setUser( $user );
54 
55  return $record;
56  }
57 
58  public function provideConstructor() {
59  $title = Title::newFromText( 'Dummy' );
60  $title->resetArticleID( 17 );
61 
62  yield [
63  $title,
64  'acmewiki'
65  ];
66  }
67 
74  public function testConstructorAndGetters(
75  Title $title,
76  $wikiId = false
77  ) {
78  $rec = new MutableRevisionRecord( $title, $wikiId );
79 
80  $this->assertSame( $title, $rec->getPageAsLinkTarget(), 'getPageAsLinkTarget' );
81  $this->assertSame( $wikiId, $rec->getWikiId(), 'getWikiId' );
82  }
83 
84  public function provideConstructorFailure() {
85  $title = Title::newFromText( 'Dummy' );
86  $title->resetArticleID( 17 );
87 
88  yield 'not a wiki id' => [
89  $title,
90  null
91  ];
92  }
93 
100  public function testConstructorFailure(
101  Title $title,
102  $wikiId = false
103  ) {
104  $this->setExpectedException( InvalidArgumentException::class );
105  new MutableRevisionRecord( $title, $wikiId );
106  }
107 
108  public function testSetGetId() {
109  $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
110  $this->assertNull( $record->getId() );
111  $record->setId( 888 );
112  $this->assertSame( 888, $record->getId() );
113  }
114 
115  public function testSetGetUser() {
116  $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
117  $user = $this->getTestSysop()->getUser();
118  $this->assertNull( $record->getUser() );
119  $record->setUser( $user );
120  $this->assertSame( $user, $record->getUser() );
121  }
122 
123  public function testSetGetPageId() {
124  $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
125  $this->assertSame( 0, $record->getPageId() );
126  $record->setPageId( 999 );
127  $this->assertSame( 999, $record->getPageId() );
128  }
129 
130  public function testSetGetParentId() {
131  $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
132  $this->assertNull( $record->getParentId() );
133  $record->setParentId( 100 );
134  $this->assertSame( 100, $record->getParentId() );
135  }
136 
137  public function testGetMainContentWhenEmpty() {
138  $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
139  $this->setExpectedException( RevisionAccessException::class );
140  $this->assertNull( $record->getContent( 'main' ) );
141  }
142 
143  public function testSetGetMainContent() {
144  $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
145  $content = new WikitextContent( 'Badger' );
146  $record->setContent( 'main', $content );
147  $this->assertSame( $content, $record->getContent( 'main' ) );
148  }
149 
150  public function testGetSlotWhenEmpty() {
151  $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
152  $this->assertFalse( $record->hasSlot( 'main' ) );
153 
154  $this->setExpectedException( RevisionAccessException::class );
155  $record->getSlot( 'main' );
156  }
157 
158  public function testSetGetSlot() {
159  $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
160  $slot = SlotRecord::newUnsaved(
161  'main',
162  new WikitextContent( 'x' )
163  );
164  $record->setSlot( $slot );
165  $this->assertTrue( $record->hasSlot( 'main' ) );
166  $this->assertSame( $slot, $record->getSlot( 'main' ) );
167  }
168 
169  public function testSetGetMinor() {
170  $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
171  $this->assertFalse( $record->isMinor() );
172  $record->setMinorEdit( true );
173  $this->assertSame( true, $record->isMinor() );
174  }
175 
176  public function testSetGetTimestamp() {
177  $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
178  $this->assertNull( $record->getTimestamp() );
179  $record->setTimestamp( '20180101010101' );
180  $this->assertSame( '20180101010101', $record->getTimestamp() );
181  }
182 
183  public function testSetGetVisibility() {
184  $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
185  $this->assertSame( 0, $record->getVisibility() );
186  $record->setVisibility( RevisionRecord::DELETED_USER );
187  $this->assertSame( RevisionRecord::DELETED_USER, $record->getVisibility() );
188  }
189 
190  public function testSetGetSha1() {
191  $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
192  $this->assertSame( 'phoiac9h4m842xq45sp7s6u21eteeq1', $record->getSha1() );
193  $record->setSha1( 'someHash' );
194  $this->assertSame( 'someHash', $record->getSha1() );
195  }
196 
197  public function testSetGetSize() {
198  $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
199  $this->assertSame( 0, $record->getSize() );
200  $record->setSize( 775 );
201  $this->assertSame( 775, $record->getSize() );
202  }
203 
204  public function testSetGetComment() {
205  $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
206  $comment = new CommentStoreComment( 1, 'foo' );
207  $this->assertNull( $record->getComment() );
208  $record->setComment( $comment );
209  $this->assertSame( $comment, $record->getComment() );
210  }
211 
212 }
MediaWiki\User\UserIdentityValue
Value object representing a user's identity.
Definition: UserIdentityValue.php:32
$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:247
CommentStoreComment\newUnsavedComment
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
Definition: CommentStoreComment.php:65
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:273
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetPageId
testSetGetPageId()
Definition: MutableRevisionRecordTest.php:123
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetMinor
testSetGetMinor()
Definition: MutableRevisionRecordTest.php:169
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
array
the array() calling protocol came about after MediaWiki 1.4rc1.
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetTimestamp
testSetGetTimestamp()
Definition: MutableRevisionRecordTest.php:176
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testGetSlotWhenEmpty
testGetSlotWhenEmpty()
Definition: MutableRevisionRecordTest.php:150
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testConstructorFailure
testConstructorFailure(Title $title, $wikiId=false)
provideConstructorFailure
Definition: MutableRevisionRecordTest.php:100
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetParentId
testSetGetParentId()
Definition: MutableRevisionRecordTest.php:130
MediaWiki\Tests\Storage\MutableRevisionRecordTest\provideConstructor
provideConstructor()
Definition: MutableRevisionRecordTest.php:58
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetId
testSetGetId()
Definition: MutableRevisionRecordTest.php:108
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetComment
testSetGetComment()
Definition: MutableRevisionRecordTest.php:204
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:37
MediaWiki\Tests\Storage
Definition: BlobStoreFactoryTest.php:3
MediaWiki\Tests\Storage\MutableRevisionRecordTest\newRevision
newRevision(array $rowOverrides=[])
Definition: MutableRevisionRecordTest.php:30
MediaWiki\Tests\Storage\MutableRevisionRecordTest
\MediaWiki\Storage\MutableRevisionRecord \MediaWiki\Storage\RevisionRecord
Definition: MutableRevisionRecordTest.php:21
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
MediaWiki\Storage\SlotRecord\newUnsaved
static newUnsaved( $role, Content $content)
Constructs a new Slot from a Content object for a new revision.
Definition: SlotRecord.php:124
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:33
MediaWiki\Storage\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:44
MediaWiki\Storage\RevisionAccessException
Exception representing a failure to look up a revision.
Definition: RevisionAccessException.php:32
MediaWiki\Tests\Storage\MutableRevisionRecordTest\provideConstructorFailure
provideConstructorFailure()
Definition: MutableRevisionRecordTest.php:84
MediaWikiTestCase\getTestSysop
static getTestSysop()
Convenience method for getting an immutable admin test user.
Definition: MediaWikiTestCase.php:177
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetSlot
testSetGetSlot()
Definition: MutableRevisionRecordTest.php:158
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetVisibility
testSetGetVisibility()
Definition: MutableRevisionRecordTest.php:183
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testConstructorAndGetters
testConstructorAndGetters(Title $title, $wikiId=false)
provideConstructor
Definition: MutableRevisionRecordTest.php:74
TextContent
Content object implementation for representing flat text.
Definition: TextContent.php:35
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetMainContent
testSetGetMainContent()
Definition: MutableRevisionRecordTest.php:143
Title
Represents a title within MediaWiki.
Definition: Title.php:39
MediaWiki\Storage\MutableRevisionRecord
Mutable RevisionRecord implementation, for building new revision entries programmatically.
Definition: MutableRevisionRecord.php:39
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testGetMainContentWhenEmpty
testGetMainContentWhenEmpty()
Definition: MutableRevisionRecordTest.php:137
MediaWiki\Storage\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:38
MediaWiki\Storage\RevisionRecord\DELETED_USER
const DELETED_USER
Definition: RevisionRecord.php:49
MediaWiki\Tests\Storage\RevisionRecordTests
trait RevisionRecordTests
\MediaWiki\Storage\RevisionRecord
Definition: RevisionRecordTests.php:24
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:56
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetSize
testSetGetSize()
Definition: MutableRevisionRecordTest.php:197
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetUser
testSetGetUser()
Definition: MutableRevisionRecordTest.php:115
CommentStoreComment
CommentStoreComment represents a comment stored by CommentStore.
Definition: CommentStoreComment.php:28
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetSha1
testSetGetSha1()
Definition: MutableRevisionRecordTest.php:190