From 42a456ce482f35a895c20caede247537310c9c6f Mon Sep 17 00:00:00 2001 From: addshore Date: Thu, 26 Oct 2017 13:03:43 +0100 Subject: [PATCH] Add test for Revision::insertOn The success test indicates a change in behaviour of the insertOn method once I4f24e7fbb683cb51f3fd8b250732bae9c7541ba2 is applied. Change-Id: I987d64c5bc3788b7d6b0a858ff39e97fae38de3c --- .../includes/RevisionIntegrationTest.php | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tests/phpunit/includes/RevisionIntegrationTest.php b/tests/phpunit/includes/RevisionIntegrationTest.php index 9dcd0cf908..10186edf28 100644 --- a/tests/phpunit/includes/RevisionIntegrationTest.php +++ b/tests/phpunit/includes/RevisionIntegrationTest.php @@ -151,6 +151,78 @@ class RevisionIntegrationTest extends MediaWikiTestCase { $this->assertEquals( $orig->getSha1(), $rev->getSha1() ); } + /** + * @covers Revision::insertOn + */ + public function testInsertOn_success() { + $parentId = $this->testPage->getLatest(); + + // If an ExternalStore is set don't use it. + $this->setMwGlobals( 'wgDefaultExternalStore', false ); + + $rev = new Revision( [ + 'page' => $this->testPage->getId(), + 'title' => $this->testPage->getTitle(), + 'text' => 'Revision Text', + 'comment' => 'Revision comment', + ] ); + + $revId = $rev->insertOn( wfGetDB( DB_MASTER ) ); + + $this->assertInternalType( 'integer', $revId ); + $this->assertInternalType( 'integer', $rev->getTextId() ); + $this->assertSame( $revId, $rev->getId() ); + + $this->assertSelect( + 'text', + [ 'old_id', 'old_text' ], + "old_id = {$rev->getTextId()}", + [ [ strval( $rev->getTextId() ), 'Revision Text' ] ] + ); + $this->assertSelect( + 'revision', + [ + 'rev_id', + 'rev_page', + 'rev_text_id', + 'rev_user', + 'rev_minor_edit', + 'rev_deleted', + 'rev_len', + 'rev_parent_id', + 'rev_sha1', + ], + "rev_id = {$rev->getId()}", + [ [ + strval( $rev->getId() ), + strval( $this->testPage->getId() ), + strval( $rev->getTextId() ), + '0', + '0', + '0', + '13', + strval( $parentId ), + 's0ngbdoxagreuf2vjtuxzwdz64n29xm', + ] ] + ); + } + + /** + * @covers Revision::insertOn + */ + public function testInsertOn_exceptionOnNoPage() { + // If an ExternalStore is set don't use it. + $this->setMwGlobals( 'wgDefaultExternalStore', false ); + $this->setExpectedException( + MWException::class, + "Cannot insert revision: page ID must be nonzero" + ); + + $rev = new Revision( [] ); + + $rev->insertOn( wfGetDB( DB_MASTER ) ); + } + /** * @covers Revision::newFromTitle */ -- 2.20.1