From: Umherirrender Date: Fri, 14 Sep 2018 18:30:30 +0000 (+0200) Subject: Ensure database is setup in MediaWikiTestCase::insertPage X-Git-Tag: 1.34.0-rc.0~4084^2 X-Git-Url: http://git.cyclocoop.org/data/%22index.php5/%40%20%27entree_url%27%20=%3E%20%27URL%20of%20your%20site%27%2C%20%27entree_url_2%27%20=%3E%20%27Site%20URL%27%2C%20%27erreur_connect_deja_existant%27%20=%3E%20%27There%20is%20already%20a%20server%20with%20that%20name%20%27%2C%20%27erreur_email_deja_existant%27%20=%3E%20%27This%20email%20address%20is%20already%20registered.%27%2C%20%27erreur_nom_connect_incorrect%27%20=%3E%20%27Server%20name%20not%20allowed%27%2C%20%27erreur_plugin_desinstalation_echouee%27%20=%3E%20%27Uninstallation%20of%20the%20plugin%20failed.%20However%2C%20you%20may%20deactivate%20it.%27%2C%20%27erreur_plugin_fichier_absent%27%20=%3E%20%27File%20missing%27%2C%40%40%20-175%2C7%20%20147%2C7%20%40%40%20Do%20not%20submit%20this%20import%20request.%3Cp%3EFor%20more%20information%2C%20please%20see%20%3Ca%20href=?a=commitdiff_plain;h=4da52463e3f461fc92ab40b197c7d49b9119eddd;p=lhc%2Fweb%2Fwiklou.git Ensure database is setup in MediaWikiTestCase::insertPage Also in editPage Add missing @group Database Depends-On: Id81425fff0a41c651c1967698124246befcdb032 Depends-On: If97d9e6e525465ca3879003e71dd5e67fc0afdfd Change-Id: I3bfd478769e0907913834c9639af4375223638cc --- diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 86b1b080a0..af014b9812 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -196,9 +196,17 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { * * @param Title|string|null $title * @return WikiPage - * @throws MWException + * @throws MWException If this test cases's needsDB() method doesn't return true. + * Test cases can use "@group Database" to enable database test support, + * or list the tables under testing in $this->tablesUsed, or override the + * needsDB() method. */ protected function getExistingTestPage( $title = null ) { + if ( !$this->needsDB() ) { + throw new MWException( 'When testing which pages, the test cases\'s needsDB()' . + ' method should return true. Use @group Database or $this->tablesUsed.' ); + } + $title = ( $title === null ) ? 'UTPage' : $title; $title = is_string( $title ) ? Title::newFromText( $title ) : $title; $page = WikiPage::factory( $title ); @@ -224,9 +232,17 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { * * @param Title|string|null $title * @return WikiPage - * @throws MWException + * @throws MWException If this test cases's needsDB() method doesn't return true. + * Test cases can use "@group Database" to enable database test support, + * or list the tables under testing in $this->tablesUsed, or override the + * needsDB() method. */ protected function getNonexistingTestPage( $title = null ) { + if ( !$this->needsDB() ) { + throw new MWException( 'When testing which pages, the test cases\'s needsDB()' . + ' method should return true. Use @group Database or $this->tablesUsed.' ); + } + $title = ( $title === null ) ? 'UTPage-' . rand( 0, 100000 ) : $title; $title = is_string( $title ) ? Title::newFromText( $title ) : $title; $page = WikiPage::factory( $title ); @@ -1140,6 +1156,10 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { * @param int|null $namespace Namespace id (name cannot already contain namespace) * @param User|null $user If null, static::getTestSysop()->getUser() is used. * @return array Title object and page id + * @throws MWException If this test cases's needsDB() method doesn't return true. + * Test cases can use "@group Database" to enable database test support, + * or list the tables under testing in $this->tablesUsed, or override the + * needsDB() method. */ protected function insertPage( $pageName, @@ -1147,6 +1167,11 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { $namespace = null, User $user = null ) { + if ( !$this->needsDB() ) { + throw new MWException( 'When testing which pages, the test cases\'s needsDB()' . + ' method should return true. Use @group Database or $this->tablesUsed.' ); + } + if ( is_string( $pageName ) ) { $title = Title::newFromText( $pageName, $namespace ); } else { @@ -2245,8 +2270,17 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { * @param string $summary Optional summary string for the revision * @param int $defaultNs Optional namespace id * @return array Array as returned by WikiPage::doEditContent() + * @throws MWException If this test cases's needsDB() method doesn't return true. + * Test cases can use "@group Database" to enable database test support, + * or list the tables under testing in $this->tablesUsed, or override the + * needsDB() method. */ protected function editPage( $pageName, $text, $summary = '', $defaultNs = NS_MAIN ) { + if ( !$this->needsDB() ) { + throw new MWException( 'When testing which pages, the test cases\'s needsDB()' . + ' method should return true. Use @group Database or $this->tablesUsed.' ); + } + $title = Title::newFromText( $pageName, $defaultNs ); $page = WikiPage::factory( $title ); diff --git a/tests/phpunit/includes/api/ApiQueryPrefixSearchTest.php b/tests/phpunit/includes/api/ApiQueryPrefixSearchTest.php index 749f154604..cb5e76dd8d 100644 --- a/tests/phpunit/includes/api/ApiQueryPrefixSearchTest.php +++ b/tests/phpunit/includes/api/ApiQueryPrefixSearchTest.php @@ -3,6 +3,7 @@ /** * @group API * @group medium + * @group Database * * @covers ApiQueryPrefixSearch */ diff --git a/tests/phpunit/includes/api/ApiQuerySiteinfoTest.php b/tests/phpunit/includes/api/ApiQuerySiteinfoTest.php index 129b7f9d6a..2d7f8a4b50 100644 --- a/tests/phpunit/includes/api/ApiQuerySiteinfoTest.php +++ b/tests/phpunit/includes/api/ApiQuerySiteinfoTest.php @@ -5,6 +5,7 @@ use MediaWiki\MediaWikiServices; /** * @group API * @group medium + * @group Database * * @covers ApiQuerySiteinfo */ diff --git a/tests/phpunit/includes/poolcounter/PoolWorkArticleViewTest.php b/tests/phpunit/includes/poolcounter/PoolWorkArticleViewTest.php index 61eb316c55..c6b9deeff4 100644 --- a/tests/phpunit/includes/poolcounter/PoolWorkArticleViewTest.php +++ b/tests/phpunit/includes/poolcounter/PoolWorkArticleViewTest.php @@ -5,6 +5,7 @@ use MediaWiki\Storage\RevisionRecord; /** * @covers PoolWorkArticleView + * @group Database */ class PoolWorkArticleViewTest extends MediaWikiTestCase {