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->assertFalse( $record->hasSlot( 'main' ) );
65 $this->setExpectedException( RevisionAccessException
::class );
66 $record->getSlot( 'main' );
69 public function testSimpleSetGetSlot() {
70 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
71 $slot = SlotRecord
::newUnsaved(
73 new WikitextContent( 'x' )
75 $record->setSlot( $slot );
76 $this->assertTrue( $record->hasSlot( 'main' ) );
77 $this->assertSame( $slot, $record->getSlot( 'main' ) );
80 public function testSimpleSetGetMinor() {
81 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
82 $this->assertFalse( $record->isMinor() );
83 $record->setMinorEdit( true );
84 $this->assertSame( true, $record->isMinor() );
87 public function testSimpleSetGetTimestamp() {
88 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
89 $this->assertNull( $record->getTimestamp() );
90 $record->setTimestamp( '20180101010101' );
91 $this->assertSame( '20180101010101', $record->getTimestamp() );
94 public function testSimpleSetGetVisibility() {
95 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
96 $this->assertSame( 0, $record->getVisibility() );
97 $record->setVisibility( RevisionRecord
::DELETED_USER
);
98 $this->assertSame( RevisionRecord
::DELETED_USER
, $record->getVisibility() );
101 public function testSimpleSetGetSha1() {
102 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
103 $this->assertSame( 'phoiac9h4m842xq45sp7s6u21eteeq1', $record->getSha1() );
104 $record->setSha1( 'someHash' );
105 $this->assertSame( 'someHash', $record->getSha1() );
108 public function testSimpleSetGetSize() {
109 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
110 $this->assertSame( 0, $record->getSize() );
111 $record->setSize( 775 );
112 $this->assertSame( 775, $record->getSize() );
115 public function testSimpleSetGetComment() {
116 $record = new MutableRevisionRecord( Title
::newFromText( 'Foo' ) );
117 $comment = new CommentStoreComment( 1, 'foo' );
118 $this->assertNull( $record->getComment() );
119 $record->setComment( $comment );
120 $this->assertSame( $comment, $record->getComment() );