From fbb4f341f94f32c6de5b851fc6c6a4a4dd149210 Mon Sep 17 00:00:00 2001 From: addshore Date: Tue, 17 Oct 2017 12:35:28 +0100 Subject: [PATCH] RevisionIntegrationTest more newFromArchiveRow tests There were a couple of code paths that were not tested before for different combinations of selected fields, these are now covered. Change-Id: Ifd438e5c97a5f32a1744c58bd4cf0303ddb32cfc --- .../includes/RevisionIntegrationTest.php | 76 +++++++++++++++++-- 1 file changed, 70 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/includes/RevisionIntegrationTest.php b/tests/phpunit/includes/RevisionIntegrationTest.php index ac7331a0f5..41302e0c8a 100644 --- a/tests/phpunit/includes/RevisionIntegrationTest.php +++ b/tests/phpunit/includes/RevisionIntegrationTest.php @@ -225,16 +225,52 @@ class RevisionIntegrationTest extends MediaWikiTestCase { $this->assertRevEquals( $orig, $rev ); } - public function provideTrueFalse() { - yield [ true ]; - yield [ false ]; + public function provideNewFromArchiveRow() { + yield [ + true, + function ( $f ) { + return $f; + }, + ]; + yield [ + false, + function ( $f ) { + return $f; + }, + ]; + yield [ + true, + function ( $f ) { + return $f + [ 'ar_namespace', 'ar_title' ]; + }, + ]; + yield [ + false, + function ( $f ) { + return $f + [ 'ar_namespace', 'ar_title' ]; + }, + ]; + yield [ + true, + function ( $f ) { + unset( $f['ar_text_id'] ); + return $f; + }, + ]; + yield [ + false, + function ( $f ) { + unset( $f['ar_text_id'] ); + return $f; + }, + ]; } /** - * @dataProvider provideTrueFalse + * @dataProvider provideNewFromArchiveRow * @covers Revision::newFromArchiveRow */ - public function testNewFromArchiveRow( $contentHandlerUseDB ) { + public function testNewFromArchiveRow( $contentHandlerUseDB, $selectModifier ) { $this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB ); $page = $this->createPage( @@ -246,8 +282,9 @@ class RevisionIntegrationTest extends MediaWikiTestCase { $page->doDeleteArticle( 'test Revision::newFromArchiveRow' ); $dbr = wfGetDB( DB_REPLICA ); + $selectFields = $selectModifier( Revision::selectArchiveFields() ); $res = $dbr->select( - 'archive', Revision::selectArchiveFields(), [ 'ar_rev_id' => $orig->getId() ] + 'archive', $selectFields, [ 'ar_rev_id' => $orig->getId() ] ); $this->assertTrue( is_object( $res ), 'query failed' ); @@ -259,6 +296,33 @@ class RevisionIntegrationTest extends MediaWikiTestCase { $this->assertRevEquals( $orig, $rev ); } + /** + * @covers Revision::newFromArchiveRow + */ + public function testNewFromArchiveRowOverrides() { + $page = $this->createPage( + 'RevisionStorageTest_testNewFromArchiveRow', + 'Lorem Ipsum', + CONTENT_MODEL_WIKITEXT + ); + $orig = $page->getRevision(); + $page->doDeleteArticle( 'test Revision::newFromArchiveRow' ); + + $dbr = wfGetDB( DB_REPLICA ); + $res = $dbr->select( + 'archive', Revision::selectArchiveFields(), [ 'ar_rev_id' => $orig->getId() ] + ); + $this->assertTrue( is_object( $res ), 'query failed' ); + + $row = $res->fetchObject(); + $res->free(); + + $rev = Revision::newFromArchiveRow( $row, [ 'comment' => 'SOMEOVERRIDE' ] ); + + $this->assertNotEquals( $orig->getComment(), $rev->getComment() ); + $this->assertEquals( 'SOMEOVERRIDE', $rev->getComment() ); + } + /** * @covers Revision::newFromId */ -- 2.20.1