Merge "Revert "Log the reason why revision->getContent() returns null""
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / MutableRevisionRecordTest.php
1 <?php
2
3 namespace MediaWiki\Tests\Storage;
4
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;
11 use Title;
12 use WikitextContent;
13
14 /**
15 * @covers \MediaWiki\Storage\MutableRevisionRecord
16 */
17 class MutableRevisionRecordTest extends MediaWikiTestCase {
18
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() );
24 }
25
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() );
32 }
33
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() );
39 }
40
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() );
46 }
47
48 public function testSimpleGetMainContentWhenEmpty() {
49 $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
50 $this->setExpectedException( RevisionAccessException::class );
51 $this->assertNull( $record->getContent( 'main' ) );
52 }
53
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' ) );
59 }
60
61 public function testSimpleGetSlotWhenEmpty() {
62 $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
63 $this->assertFalse( $record->hasSlot( 'main' ) );
64
65 $this->setExpectedException( RevisionAccessException::class );
66 $record->getSlot( 'main' );
67 }
68
69 public function testSimpleSetGetSlot() {
70 $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
71 $slot = new SlotRecord(
72 (object)[ 'role_name' => 'main' ],
73 new WikitextContent( 'x' )
74 );
75 $record->setSlot( $slot );
76 $this->assertTrue( $record->hasSlot( 'main' ) );
77 $this->assertSame( $slot, $record->getSlot( 'main' ) );
78 }
79
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() );
85 }
86
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() );
92 }
93
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() );
99 }
100
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() );
106 }
107
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() );
113 }
114
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() );
121 }
122
123 }