From 7b166db4a83c76fce9e8995cfa3f7a4d39d58596 Mon Sep 17 00:00:00 2001 From: addshore Date: Tue, 17 Oct 2017 13:09:08 +0100 Subject: [PATCH] Revision tests, make test for constructFromRowArray a unit test Change-Id: I52aa62a442011b612966bb294015730a05702cd3 --- .../includes/RevisionIntegrationTest.php | 21 ------ tests/phpunit/includes/RevisionUnitTest.php | 72 +++++++++++++++++++ 2 files changed, 72 insertions(+), 21 deletions(-) diff --git a/tests/phpunit/includes/RevisionIntegrationTest.php b/tests/phpunit/includes/RevisionIntegrationTest.php index 41302e0c8a..9dcd0cf908 100644 --- a/tests/phpunit/includes/RevisionIntegrationTest.php +++ b/tests/phpunit/includes/RevisionIntegrationTest.php @@ -151,27 +151,6 @@ class RevisionIntegrationTest extends MediaWikiTestCase { $this->assertEquals( $orig->getSha1(), $rev->getSha1() ); } - /** - * @covers Revision::__construct - */ - public function testConstructFromRow() { - $latestRevisionId = $this->testPage->getLatest(); - $latestRevision = $this->testPage->getRevision(); - - $dbr = wfGetDB( DB_REPLICA ); - $res = $dbr->select( - 'revision', - Revision::selectFields(), - [ 'rev_id' => $latestRevisionId ] - ); - $this->assertTrue( is_object( $res ), 'query failed' ); - - $row = $res->fetchObject(); - $res->free(); - - $this->assertRevEquals( $latestRevision, new Revision( $row ) ); - } - /** * @covers Revision::newFromTitle */ diff --git a/tests/phpunit/includes/RevisionUnitTest.php b/tests/phpunit/includes/RevisionUnitTest.php index 6a30335fdf..53725bd173 100644 --- a/tests/phpunit/includes/RevisionUnitTest.php +++ b/tests/phpunit/includes/RevisionUnitTest.php @@ -70,6 +70,78 @@ class RevisionUnitTest extends MediaWikiTestCase { new Revision( $rowArray ); } + public function provideConstructFromRow() { + yield 'Full construction' => [ + [ + 'rev_id' => '2', + 'rev_page' => '1', + 'rev_text_id' => '2', + 'rev_timestamp' => '20171017114835', + 'rev_user_text' => '127.0.0.1', + 'rev_user' => '0', + 'rev_minor_edit' => '0', + 'rev_deleted' => '0', + 'rev_len' => '46', + 'rev_parent_id' => '1', + 'rev_sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z', + 'rev_comment_text' => 'Goat Comment!', + 'rev_comment_data' => null, + 'rev_comment_cid' => null, + 'rev_content_format' => 'GOATFORMAT', + 'rev_content_model' => 'GOATMODEL', + ], + function ( RevisionUnitTest $testCase, Revision $rev ) { + $testCase->assertSame( 2, $rev->getId() ); + $testCase->assertSame( 1, $rev->getPage() ); + $testCase->assertSame( 2, $rev->getTextId() ); + $testCase->assertSame( '20171017114835', $rev->getTimestamp() ); + $testCase->assertSame( '127.0.0.1', $rev->getUserText() ); + $testCase->assertSame( 0, $rev->getUser() ); + $testCase->assertSame( false, $rev->isMinor() ); + $testCase->assertSame( false, $rev->isDeleted( Revision::DELETED_TEXT ) ); + $testCase->assertSame( 46, $rev->getSize() ); + $testCase->assertSame( 1, $rev->getParentId() ); + $testCase->assertSame( 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z', $rev->getSha1() ); + $testCase->assertSame( 'Goat Comment!', $rev->getComment() ); + $testCase->assertSame( 'GOATFORMAT', $rev->getContentFormat() ); + $testCase->assertSame( 'GOATMODEL', $rev->getContentModel() ); + } + ]; + yield 'null fields' => [ + [ + 'rev_id' => '2', + 'rev_page' => '1', + 'rev_text_id' => '2', + 'rev_timestamp' => '20171017114835', + 'rev_user_text' => '127.0.0.1', + 'rev_user' => '0', + 'rev_minor_edit' => '0', + 'rev_deleted' => '0', + 'rev_comment_text' => 'Goat Comment!', + 'rev_comment_data' => null, + 'rev_comment_cid' => null, + ], + function ( RevisionUnitTest $testCase, Revision $rev ) { + $testCase->assertNull( $rev->getSize() ); + $testCase->assertNull( $rev->getParentId() ); + $testCase->assertNull( $rev->getSha1() ); + $testCase->assertSame( 'text/x-wiki', $rev->getContentFormat() ); + $testCase->assertSame( 'wikitext', $rev->getContentModel() ); + } + ]; + } + + /** + * @dataProvider provideConstructFromRow + * @covers Revision::__construct + * @covers Revision::constructFromDbRowObject + */ + public function testConstructFromRow( array $arrayData, $assertions ) { + $row = (object)$arrayData; + $rev = new Revision( $row ); + $assertions( $this, $rev ); + } + public function provideGetRevisionText() { yield 'Generic test' => [ 'This is a goat of revision text.', -- 2.20.1