From aab3e3be884ec98155788c9b9a2d3ed14fbadd43 Mon Sep 17 00:00:00 2001 From: addshore Date: Tue, 24 Oct 2017 14:41:21 +0100 Subject: [PATCH] Run RevisionIntegrationTest for both ContentHandlerUseDB settings core used to have a test case that ran various Revision tests with and without ContentHandlerUseDB set, however it did not run due to the class / file having a bad name. This patch reintroduces the running on Revision tests for both ContentHandlerUseDB settings. The global has to be set in setup / before the page used for testing is created, else this page will be created with the wrong values in the DB for use in the tests. Change-Id: Ied1023e22eeac413fa86ea6946aa31619fd66319 --- tests/common/TestsAutoLoader.php | 1 + .../includes/RevisionContentHandlerDbTest.php | 14 +++++++ ...grationTest.php => RevisionDbTestBase.php} | 42 ++++++------------- .../RevisionNoContentHandlerDbTest.php | 14 +++++++ ...{RevisionUnitTest.php => RevisionTest.php} | 9 ++-- 5 files changed, 47 insertions(+), 33 deletions(-) create mode 100644 tests/phpunit/includes/RevisionContentHandlerDbTest.php rename tests/phpunit/includes/{RevisionIntegrationTest.php => RevisionDbTestBase.php} (98%) create mode 100644 tests/phpunit/includes/RevisionNoContentHandlerDbTest.php rename tests/phpunit/includes/{RevisionUnitTest.php => RevisionTest.php} (97%) diff --git a/tests/common/TestsAutoLoader.php b/tests/common/TestsAutoLoader.php index ca31fbc7ec..f7bf7a6f57 100644 --- a/tests/common/TestsAutoLoader.php +++ b/tests/common/TestsAutoLoader.php @@ -64,6 +64,7 @@ $wgAutoloadClasses += [ 'LessFileCompilationTest' => "$testDir/phpunit/LessFileCompilationTest.php", # tests/phpunit/includes + 'RevisionDbTestBase' => "$testDir/phpunit/includes/RevisionDbTestBase.php", 'RevisionTestModifyableContent' => "$testDir/phpunit/includes/RevisionTestModifyableContent.php", 'RevisionTestModifyableContentHandler' => "$testDir/phpunit/includes/RevisionTestModifyableContentHandler.php", 'TestLogger' => "$testDir/phpunit/includes/TestLogger.php", diff --git a/tests/phpunit/includes/RevisionContentHandlerDbTest.php b/tests/phpunit/includes/RevisionContentHandlerDbTest.php new file mode 100644 index 0000000000..fa0153d3e0 --- /dev/null +++ b/tests/phpunit/includes/RevisionContentHandlerDbTest.php @@ -0,0 +1,14 @@ +setMwGlobals( 'wgContentHandlerUseDB', $this->getContentHandlerUseDB() ); + MWNamespace::clearCaches(); // Reset namespace cache $wgContLang->resetNamespaces(); if ( !$this->testPage ) { - $this->testPage = WikiPage::factory( Title::newFromText( 'UTPage' ) ); + /** + * We have to create a new page for each subclass as the page creation may result + * in different DB fields being filled based on configuration. + */ + $this->testPage = $this->createPage( __CLASS__, __CLASS__ ); } } @@ -85,6 +91,8 @@ class RevisionIntegrationTest extends MediaWikiTestCase { $wgContLang->resetNamespaces(); } + abstract protected function getContentHandlerUseDB(); + private function makeRevisionWithProps( $props = null ) { if ( $props === null ) { $props = []; @@ -280,38 +288,16 @@ class RevisionIntegrationTest extends MediaWikiTestCase { 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; @@ -323,9 +309,7 @@ class RevisionIntegrationTest extends MediaWikiTestCase { * @dataProvider provideNewFromArchiveRow * @covers Revision::newFromArchiveRow */ - public function testNewFromArchiveRow( $contentHandlerUseDB, $selectModifier ) { - $this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB ); - + public function testNewFromArchiveRow( $selectModifier ) { $page = $this->createPage( 'RevisionStorageTest_testNewFromArchiveRow', 'Lorem Ipsum', diff --git a/tests/phpunit/includes/RevisionNoContentHandlerDbTest.php b/tests/phpunit/includes/RevisionNoContentHandlerDbTest.php new file mode 100644 index 0000000000..c980a487f7 --- /dev/null +++ b/tests/phpunit/includes/RevisionNoContentHandlerDbTest.php @@ -0,0 +1,14 @@ + [ @@ -90,7 +91,7 @@ class RevisionUnitTest extends MediaWikiTestCase { 'rev_content_format' => 'GOATFORMAT', 'rev_content_model' => 'GOATMODEL', ], - function ( RevisionUnitTest $testCase, Revision $rev ) { + function ( RevisionTest $testCase, Revision $rev ) { $testCase->assertSame( 2, $rev->getId() ); $testCase->assertSame( 1, $rev->getPage() ); $testCase->assertSame( 2, $rev->getTextId() ); @@ -121,7 +122,7 @@ class RevisionUnitTest extends MediaWikiTestCase { 'rev_comment_data' => null, 'rev_comment_cid' => null, ], - function ( RevisionUnitTest $testCase, Revision $rev ) { + function ( RevisionTest $testCase, Revision $rev ) { $testCase->assertNull( $rev->getSize() ); $testCase->assertNull( $rev->getParentId() ); $testCase->assertNull( $rev->getSha1() ); -- 2.20.1