Add tests for various simple Revision get and is methods
authoraddshore <addshorewiki@gmail.com>
Thu, 9 Nov 2017 11:45:51 +0000 (11:45 +0000)
committerAddshore <addshorewiki@gmail.com>
Thu, 9 Nov 2017 13:07:12 +0000 (13:07 +0000)
These tests dont cover all code paths for these methods
in some cases but it does ensure that tests actually call
them / test basical functionality.

Some of these methods are touched in
I4f24e7fbb683cb51f3fd8b250732bae9c7541ba2
hence adding some test coverage now.

Change-Id: I7eb67cb5876f89034238591c0a98f4ec6d890a40

tests/phpunit/includes/RevisionIntegrationTest.php

index ad211c6..403983c 100644 (file)
@@ -1077,4 +1077,147 @@ class RevisionIntegrationTest extends MediaWikiTestCase {
                $this->assertNull( $rev->getTitle() );
        }
 
+       /**
+        * @covers Revision::isMinor
+        */
+       public function testIsMinor_true() {
+               // Use a sysop to ensure we can mark edits as minor
+               $sysop = $this->getTestSysop()->getUser();
+
+               $this->testPage->doEditContent(
+                       new WikitextContent( __METHOD__ ),
+                       __METHOD__,
+                       EDIT_MINOR,
+                       false,
+                       $sysop
+               );
+               $rev = $this->testPage->getRevision();
+
+               $this->assertSame( true, $rev->isMinor() );
+       }
+
+       /**
+        * @covers Revision::isMinor
+        */
+       public function testIsMinor_false() {
+               $this->testPage->doEditContent(
+                       new WikitextContent( __METHOD__ ),
+                       __METHOD__,
+                       0
+               );
+               $rev = $this->testPage->getRevision();
+
+               $this->assertSame( false, $rev->isMinor() );
+       }
+
+       /**
+        * @covers Revision::getTimestamp
+        */
+       public function testGetTimestamp() {
+               $testTimestamp = wfTimestampNow();
+
+               $this->testPage->doEditContent(
+                       new WikitextContent( __METHOD__ ),
+                       __METHOD__
+               );
+               $rev = $this->testPage->getRevision();
+
+               $this->assertInternalType( 'string', $rev->getTimestamp() );
+               $this->assertTrue( strlen( $rev->getTimestamp() ) == strlen( 'YYYYMMDDHHMMSS' ) );
+               $this->assertContains( substr( $testTimestamp, 0, 10 ), $rev->getTimestamp() );
+       }
+
+       /**
+        * @covers Revision::getUser
+        * @covers Revision::getUserText
+        */
+       public function testGetUserAndText() {
+               $sysop = $this->getTestSysop()->getUser();
+
+               $this->testPage->doEditContent(
+                       new WikitextContent( __METHOD__ ),
+                       __METHOD__,
+                       0,
+                       false,
+                       $sysop
+               );
+               $rev = $this->testPage->getRevision();
+
+               $this->assertSame( $sysop->getId(), $rev->getUser() );
+               $this->assertSame( $sysop->getName(), $rev->getUserText() );
+       }
+
+       /**
+        * @covers Revision::isDeleted
+        */
+       public function testIsDeleted_nothingDeleted() {
+               $rev = $this->testPage->getRevision();
+
+               $this->assertSame( false, $rev->isDeleted( Revision::DELETED_TEXT ) );
+               $this->assertSame( false, $rev->isDeleted( Revision::DELETED_COMMENT ) );
+               $this->assertSame( false, $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
+               $this->assertSame( false, $rev->isDeleted( Revision::DELETED_USER ) );
+       }
+
+       /**
+        * @covers Revision::getVisibility
+        */
+       public function testGetVisibility_nothingDeleted() {
+               $rev = $this->testPage->getRevision();
+
+               $this->assertSame( 0, $rev->getVisibility() );
+       }
+
+       /**
+        * @covers Revision::getComment
+        */
+       public function testGetComment_notDeleted() {
+               $expectedSummary = 'goatlicious summary';
+
+               $this->testPage->doEditContent(
+                       new WikitextContent( __METHOD__ ),
+                       $expectedSummary
+               );
+               $rev = $this->testPage->getRevision();
+
+               $this->assertSame( $expectedSummary, $rev->getComment() );
+       }
+
+       /**
+        * This is a simple blanket test for all simple getters and is methods to provide some
+        * coverage before the split of Revision into multiple classes for MCR work.
+        * @covers Revision::isUnpatrolled
+        */
+       public function testIsUnpatrolled_true() {
+               $rev = $this->testPage->getRevision();
+
+               $this->assertSame( 0, $rev->isUnpatrolled() );
+       }
+
+       /**
+        * This is a simple blanket test for all simple content getters and is methods to provide some
+        * coverage before the split of Revision into multiple classes for MCR work.
+        * @covers Revision::getContent
+        * @covers Revision::getSerializedData
+        * @covers Revision::getContentModel
+        * @covers Revision::getContentFormat
+        * @covers Revision::getContentHandler
+        */
+       public function testSimpleContentGetters() {
+               $expectedText = 'testSimpleContentGetters in Revision. Goats love MCR...';
+               $expectedSummary = 'goatlicious testSimpleContentGetters summary';
+
+               $this->testPage->doEditContent(
+                       new WikitextContent( $expectedText ),
+                       $expectedSummary
+               );
+               $rev = $this->testPage->getRevision();
+
+               $this->assertSame( $expectedText, $rev->getContent()->getNativeData() );
+               $this->assertSame( $expectedText, $rev->getSerializedData() );
+               $this->assertSame( $this->testPage->getContentModel(), $rev->getContentModel() );
+               $this->assertSame( $this->testPage->getContent()->getDefaultFormat(), $rev->getContentFormat() );
+               $this->assertSame( $this->testPage->getContentHandler(), $rev->getContentHandler() );
+       }
+
 }