MediaWiki
REL1_31
MutableRevisionRecordTest.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\Tests\Storage
;
4
5
use
CommentStoreComment
;
6
use InvalidArgumentException;
7
use
MediaWiki\Storage\MutableRevisionRecord
;
8
use
MediaWiki\Storage\RevisionAccessException
;
9
use
MediaWiki\Storage\RevisionRecord
;
10
use
MediaWiki\Storage\SlotRecord
;
11
use
MediaWiki\User\UserIdentityValue
;
12
use
MediaWikiTestCase
;
13
use
TextContent
;
14
use
Title
;
15
use
WikitextContent
;
16
21
class
MutableRevisionRecordTest
extends
MediaWikiTestCase
{
22
23
use
RevisionRecordTests
;
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
}
CommentStoreComment
CommentStoreComment represents a comment stored by CommentStore.
Definition
CommentStoreComment.php:28
MediaWikiTestCase
Definition
MediaWikiTestCase.php:17
MediaWikiTestCase\getTestSysop
static getTestSysop()
Convenience method for getting an immutable admin test user.
Definition
MediaWikiTestCase.php:177
MediaWiki\Storage\MutableRevisionRecord
Mutable RevisionRecord implementation, for building new revision entries programmatically.
Definition
MutableRevisionRecord.php:39
MediaWiki\Storage\RevisionAccessException
Exception representing a failure to look up a revision.
Definition
RevisionAccessException.php:32
MediaWiki\Storage\RevisionRecord
Page revision base class.
Definition
RevisionRecord.php:44
MediaWiki\Storage\SlotRecord
Value object representing a content slot associated with a page revision.
Definition
SlotRecord.php:38
MediaWiki\Tests\Storage\MutableRevisionRecordTest
\MediaWiki\Storage\MutableRevisionRecord \MediaWiki\Storage\RevisionRecord
Definition
MutableRevisionRecordTest.php:21
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetTimestamp
testSetGetTimestamp()
Definition
MutableRevisionRecordTest.php:176
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testGetSlotWhenEmpty
testGetSlotWhenEmpty()
Definition
MutableRevisionRecordTest.php:150
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetPageId
testSetGetPageId()
Definition
MutableRevisionRecordTest.php:123
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetSha1
testSetGetSha1()
Definition
MutableRevisionRecordTest.php:190
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetMainContent
testSetGetMainContent()
Definition
MutableRevisionRecordTest.php:143
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\testSetGetVisibility
testSetGetVisibility()
Definition
MutableRevisionRecordTest.php:183
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testConstructorAndGetters
testConstructorAndGetters(Title $title, $wikiId=false)
provideConstructor
Definition
MutableRevisionRecordTest.php:74
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetUser
testSetGetUser()
Definition
MutableRevisionRecordTest.php:115
MediaWiki\Tests\Storage\MutableRevisionRecordTest\provideConstructorFailure
provideConstructorFailure()
Definition
MutableRevisionRecordTest.php:84
MediaWiki\Tests\Storage\MutableRevisionRecordTest\newRevision
newRevision(array $rowOverrides=[])
Definition
MutableRevisionRecordTest.php:30
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetMinor
testSetGetMinor()
Definition
MutableRevisionRecordTest.php:169
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetSlot
testSetGetSlot()
Definition
MutableRevisionRecordTest.php:158
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetId
testSetGetId()
Definition
MutableRevisionRecordTest.php:108
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testGetMainContentWhenEmpty
testGetMainContentWhenEmpty()
Definition
MutableRevisionRecordTest.php:137
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetSize
testSetGetSize()
Definition
MutableRevisionRecordTest.php:197
MediaWiki\Tests\Storage\MutableRevisionRecordTest\testSetGetComment
testSetGetComment()
Definition
MutableRevisionRecordTest.php:204
MediaWiki\Tests\Storage\MutableRevisionRecordTest\provideConstructor
provideConstructor()
Definition
MutableRevisionRecordTest.php:58
MediaWiki\User\UserIdentityValue
Value object representing a user's identity.
Definition
UserIdentityValue.php:32
TextContent
Content object implementation for representing flat text.
Definition
TextContent.php:35
Title
Represents a title within MediaWiki.
Definition
Title.php:39
WikitextContent
Content object for wiki text pages.
Definition
WikitextContent.php:33
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition
hooks.txt:964
MediaWiki\Tests\Storage
Definition
BlobStoreFactoryTest.php:3
MediaWiki\Tests\Storage\RevisionRecordTests
trait RevisionRecordTests
\MediaWiki\Storage\RevisionRecord
Definition
RevisionRecordTests.php:24
tests
phpunit
includes
Storage
MutableRevisionRecordTest.php
Generated on Mon Nov 25 2024 15:36:36 for MediaWiki by
1.10.0