MediaWiki REL1_31
MutableRevisionRecordTest.php
Go to the documentation of this file.
1<?php
2
4
6use InvalidArgumentException;
13use TextContent;
14use 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
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}
CommentStoreComment represents a comment stored by CommentStore.
static getTestSysop()
Convenience method for getting an immutable admin test user.
Mutable RevisionRecord implementation, for building new revision entries programmatically.
Exception representing a failure to look up a revision.
Page revision base class.
Value object representing a content slot associated with a page revision.
\MediaWiki\Storage\MutableRevisionRecord \MediaWiki\Storage\RevisionRecord
testConstructorFailure(Title $title, $wikiId=false)
provideConstructorFailure
testConstructorAndGetters(Title $title, $wikiId=false)
provideConstructor
Value object representing a user's identity.
Content object implementation for representing flat text.
Represents a title within MediaWiki.
Definition Title.php:39
Content object for wiki text pages.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
trait RevisionRecordTests
\MediaWiki\Storage\RevisionRecord