3 namespace MediaWiki\Tests\Storage
;
5 use CommentStoreComment
;
6 use MediaWiki\Storage\MutableRevisionRecord
;
7 use MediaWiki\Storage\RevisionAccessException
;
8 use MediaWiki\Storage\RevisionRecord
;
9 use MediaWiki\Storage\SlotRecord
;
10 use MediaWikiTestCase
;
15 * @covers \MediaWiki\Storage\MutableRevisionRecord
17 class MutableRevisionRecordTest
extends MediaWikiTestCase
{
19 public function testSimpleSetGetId() {
20 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
21 $this->assertNull( $record->getId() );
22 $record->setId( 888 );
23 $this->assertSame( 888, $record->getId() );
26 public function testSimpleSetGetUser() {
27 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
28 $user = $this->getTestSysop()->getUser();
29 $this->assertNull( $record->getUser() );
30 $record->setUser( $user );
31 $this->assertSame( $user, $record->getUser() );
34 public function testSimpleSetGetPageId() {
35 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
36 $this->assertSame( 0, $record->getPageId() );
37 $record->setPageId( 999 );
38 $this->assertSame( 999, $record->getPageId() );
41 public function testSimpleSetGetParentId() {
42 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
43 $this->assertNull( $record->getParentId() );
44 $record->setParentId( 100 );
45 $this->assertSame( 100, $record->getParentId() );
48 public function testSimpleGetMainContentWhenEmpty() {
49 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
50 $this->setExpectedException( RevisionAccessException
::class );
51 $this->assertNull( $record->getContent( 'main' ) );
54 public function testSimpleSetGetMainContent() {
55 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
56 $content = new WikitextContent( 'Badger' );
57 $record->setContent( 'main', $content );
58 $this->assertSame( $content, $record->getContent( 'main' ) );
61 public function testSimpleGetSlotWhenEmpty() {
62 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
63 $this->setExpectedException( RevisionAccessException
::class );
64 $record->getSlot( 'main' );
67 public function testSimpleSetGetSlot() {
68 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
69 $slot = new SlotRecord(
70 (object)[ 'role_name' => 'main' ],
71 new WikitextContent( 'x' )
73 $record->setSlot( $slot );
74 $this->assertSame( $slot, $record->getSlot( 'main' ) );
77 public function testSimpleSetGetMinor() {
78 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
79 $this->assertFalse( $record->isMinor() );
80 $record->setMinorEdit( true );
81 $this->assertSame( true, $record->isMinor() );
84 public function testSimpleSetGetTimestamp() {
85 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
86 $this->assertNull( $record->getTimestamp() );
87 $record->setTimestamp( '20180101010101' );
88 $this->assertSame( '20180101010101', $record->getTimestamp() );
91 public function testSimpleSetGetVisibility() {
92 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
93 $this->assertSame( 0, $record->getVisibility() );
94 $record->setVisibility( RevisionRecord
::DELETED_USER
);
95 $this->assertSame( RevisionRecord
::DELETED_USER
, $record->getVisibility() );
98 public function testSimpleSetGetSha1() {
99 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
100 $this->assertSame( 'phoiac9h4m842xq45sp7s6u21eteeq1', $record->getSha1() );
101 $record->setSha1( 'someHash' );
102 $this->assertSame( 'someHash', $record->getSha1() );
105 public function testSimpleSetGetSize() {
106 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
107 $this->assertSame( 0, $record->getSize() );
108 $record->setSize( 775 );
109 $this->assertSame( 775, $record->getSize() );
112 public function testSimpleSetGetComment() {
113 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
114 $comment = new CommentStoreComment( 1, 'foo' );
115 $this->assertNull( $record->getComment() );
116 $record->setComment( $comment );
117 $this->assertSame( $comment, $record->getComment() );