Tests for WikiPage::updateRevisionOn
authoraddshore <addshorewiki@gmail.com>
Mon, 4 Dec 2017 15:31:57 +0000 (16:31 +0100)
committerKunal Mehta <legoktm@member.fsf.org>
Tue, 5 Dec 2017 19:29:19 +0000 (11:29 -0800)
Bug: T180989
Change-Id: I245d9d467e3113bf49e06ee5c725205d4225671a

tests/phpunit/includes/page/WikiPageDbTestBase.php

index be8b444..9d349b7 100644 (file)
@@ -1486,4 +1486,63 @@ more stuff
                $this->assertSame( $expectedComment, $result->getComment( Revision::RAW ) );
        }
 
                $this->assertSame( $expectedComment, $result->getComment( Revision::RAW ) );
        }
 
+       /**
+        * @covers WikiPage::updateRevisionOn
+        */
+       public function testUpdateRevisionOn_existingPage() {
+               $user = $this->getTestSysop()->getUser();
+               $page = $this->createPage( __METHOD__, 'StartText' );
+
+               $revision = new Revision(
+                       [
+                               'id' => 9989,
+                               'page' => $page->getId(),
+                               'title' => $page->getTitle(),
+                               'comment' => __METHOD__,
+                               'minor_edit' => true,
+                               'text' => __METHOD__ . '-text',
+                               'len' => strlen( __METHOD__ . '-text' ),
+                               'user' => $user->getId(),
+                               'user_text' => $user->getName(),
+                               'timestamp' => '20170707040404',
+                               'content_model' => CONTENT_MODEL_WIKITEXT,
+                               'content_format' => CONTENT_FORMAT_WIKITEXT,
+                       ]
+               );
+
+               $result = $page->updateRevisionOn( $this->db, $revision );
+               $this->assertTrue( $result );
+               $this->assertSame( 9989, $page->getLatest() );
+               $this->assertEquals( $revision, $page->getRevision() );
+       }
+
+       /**
+        * @covers WikiPage::updateRevisionOn
+        */
+       public function testUpdateRevisionOn_NonExistingPage() {
+               $user = $this->getTestSysop()->getUser();
+               $page = $this->createPage( __METHOD__, 'StartText' );
+               $page->doDeleteArticle( 'reason' );
+
+               $revision = new Revision(
+                       [
+                               'id' => 9989,
+                               'page' => $page->getId(),
+                               'title' => $page->getTitle(),
+                               'comment' => __METHOD__,
+                               'minor_edit' => true,
+                               'text' => __METHOD__ . '-text',
+                               'len' => strlen( __METHOD__ . '-text' ),
+                               'user' => $user->getId(),
+                               'user_text' => $user->getName(),
+                               'timestamp' => '20170707040404',
+                               'content_model' => CONTENT_MODEL_WIKITEXT,
+                               'content_format' => CONTENT_FORMAT_WIKITEXT,
+                       ]
+               );
+
+               $result = $page->updateRevisionOn( $this->db, $revision );
+               $this->assertFalse( $result );
+       }
+
 }
 }