diff options
author | Umherirrender <umherirrender_de.wp@web.de> | 2022-09-23 21:53:11 +0200 |
---|---|---|
committer | Umherirrender <umherirrender_de.wp@web.de> | 2022-09-23 21:53:11 +0200 |
commit | 89b2d11a0dfbf9233166ca6df33819877d7ced1d (patch) | |
tree | a0cd0ce12e8892f55794b0bb22530e51dff1d504 /tests/phpunit/includes/api | |
parent | 1e60c7337ae7022863754c485d7e218d92cf3cb8 (diff) | |
download | mediawikicore-89b2d11a0dfbf9233166ca6df33819877d7ced1d.tar.gz mediawikicore-89b2d11a0dfbf9233166ca6df33819877d7ced1d.zip |
tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance
Change-Id: Ie240eb42479d19714e64cc4606e26073fadc2e13
Diffstat (limited to 'tests/phpunit/includes/api')
6 files changed, 19 insertions, 19 deletions
diff --git a/tests/phpunit/includes/api/ApiChangeContentModelTest.php b/tests/phpunit/includes/api/ApiChangeContentModelTest.php index bf18e3074182..74bc305e4205 100644 --- a/tests/phpunit/includes/api/ApiChangeContentModelTest.php +++ b/tests/phpunit/includes/api/ApiChangeContentModelTest.php @@ -82,7 +82,7 @@ class ApiChangeContentModelTest extends ApiTestCase { public function testChangeNeeded() { $this->assertSame( 'wikitext', - Title::newFromText( 'ExistingPage' )->getContentModel(), + Title::makeTitle( NS_MAIN, 'ExistingPage' )->getContentModel(), '`ExistingPage` should be wikitext' ); @@ -134,7 +134,7 @@ class ApiChangeContentModelTest extends ApiTestCase { * @param string $expectedMessage expected fatal */ public function testEditFilterMergedContent( $customMessage, $expectedMessage ) { - $title = Title::newFromText( 'ExistingPage' ); + $title = Title::makeTitle( NS_MAIN, 'ExistingPage' ); $this->assertSame( 'wikitext', @@ -180,7 +180,7 @@ class ApiChangeContentModelTest extends ApiTestCase { * Test the ContentModelCanBeUsedOn hook can be intercepted */ public function testContentModelCanBeUsedOn() { - $title = Title::newFromText( 'ExistingPage' ); + $title = Title::makeTitle( NS_MAIN, 'ExistingPage' ); $this->assertSame( 'wikitext', @@ -267,7 +267,7 @@ class ApiChangeContentModelTest extends ApiTestCase { * Test that it works */ public function testEverythingWorks() { - $title = Title::newFromText( 'ExistingPage' ); + $title = Title::makeTitle( NS_MAIN, 'ExistingPage' ); $performer = $this->mockAnonAuthorityWithPermissions( [ 'edit', 'editcontentmodel', 'writeapi', 'applychangetags' ] ); diff --git a/tests/phpunit/includes/api/ApiComparePagesTest.php b/tests/phpunit/includes/api/ApiComparePagesTest.php index 7c07d4121307..d52c22aae471 100644 --- a/tests/phpunit/includes/api/ApiComparePagesTest.php +++ b/tests/phpunit/includes/api/ApiComparePagesTest.php @@ -41,13 +41,13 @@ class ApiComparePagesTest extends ApiTestCase { self::$repl['revA2'] = $this->addPage( 'A', 'A 2' ); self::$repl['revA3'] = $this->addPage( 'A', 'A 3' ); self::$repl['revA4'] = $this->addPage( 'A', 'A 4' ); - self::$repl['pageA'] = Title::newFromText( 'ApiComparePagesTest A' )->getArticleID(); + self::$repl['pageA'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest A' )->getArticleID(); self::$repl['revB1'] = $this->addPage( 'B', 'B 1' ); self::$repl['revB2'] = $this->addPage( 'B', 'B 2' ); self::$repl['revB3'] = $this->addPage( 'B', 'B 3' ); self::$repl['revB4'] = $this->addPage( 'B', 'B 4' ); - self::$repl['pageB'] = Title::newFromText( 'ApiComparePagesTest B' )->getArticleID(); + self::$repl['pageB'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest B' )->getArticleID(); $updateTimestamps = [ self::$repl['revB1'] => '20010101011101', self::$repl['revB2'] => '20020202022202', @@ -66,35 +66,35 @@ class ApiComparePagesTest extends ApiTestCase { self::$repl['revC1'] = $this->addPage( 'C', 'C 1' ); self::$repl['revC2'] = $this->addPage( 'C', 'C 2' ); self::$repl['revC3'] = $this->addPage( 'C', 'C 3' ); - self::$repl['pageC'] = Title::newFromText( 'ApiComparePagesTest C' )->getArticleID(); + self::$repl['pageC'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest C' )->getArticleID(); $id = $this->addPage( 'D', 'D 1' ); - self::$repl['pageD'] = Title::newFromText( 'ApiComparePagesTest D' )->getArticleID(); + self::$repl['pageD'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest D' )->getArticleID(); wfGetDB( DB_PRIMARY )->delete( 'revision', [ 'rev_id' => $id ] ); self::$repl['revE1'] = $this->addPage( 'E', 'E 1' ); self::$repl['revE2'] = $this->addPage( 'E', 'E 2' ); self::$repl['revE3'] = $this->addPage( 'E', 'E 3' ); self::$repl['revE4'] = $this->addPage( 'E', 'E 4' ); - self::$repl['pageE'] = Title::newFromText( 'ApiComparePagesTest E' )->getArticleID(); + self::$repl['pageE'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest E' )->getArticleID(); wfGetDB( DB_PRIMARY )->update( 'page', [ 'page_latest' => 0 ], [ 'page_id' => self::$repl['pageE'] ] ); self::$repl['revF1'] = $this->addPage( 'F', "== Section 1 ==\nF 1.1\n\n== Section 2 ==\nF 1.2" ); - self::$repl['pageF'] = Title::newFromText( 'ApiComparePagesTest F' )->getArticleID(); + self::$repl['pageF'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest F' )->getArticleID(); self::$repl['revG1'] = $this->addPage( 'G', "== Section 1 ==\nG 1.1", CONTENT_MODEL_TEXT ); - self::$repl['pageG'] = Title::newFromText( 'ApiComparePagesTest G' )->getArticleID(); + self::$repl['pageG'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest G' )->getArticleID(); $page = $this->getServiceContainer()->getWikiPageFactory() - ->newFromTitle( Title::newFromText( 'ApiComparePagesTest C' ) ); + ->newFromTitle( Title::makeTitle( NS_MAIN, 'ApiComparePagesTest C' ) ); $this->deletePage( $page, 'Test for ApiComparePagesTest', $user ); RevisionDeleter::createList( 'revision', RequestContext::getMain(), - Title::newFromText( 'ApiComparePagesTest B' ), + Title::makeTitle( NS_MAIN, 'ApiComparePagesTest B' ), [ self::$repl['revB2'] ] )->setVisibility( [ 'value' => [ @@ -108,7 +108,7 @@ class ApiComparePagesTest extends ApiTestCase { RevisionDeleter::createList( 'revision', RequestContext::getMain(), - Title::newFromText( 'ApiComparePagesTest B' ), + Title::makeTitle( NS_MAIN, 'ApiComparePagesTest B' ), [ self::$repl['revB3'] ] )->setVisibility( [ 'value' => [ diff --git a/tests/phpunit/includes/api/ApiOptionsTest.php b/tests/phpunit/includes/api/ApiOptionsTest.php index bdeb00ff8f00..ba0fa076dbcc 100644 --- a/tests/phpunit/includes/api/ApiOptionsTest.php +++ b/tests/phpunit/includes/api/ApiOptionsTest.php @@ -39,7 +39,7 @@ class ApiOptionsTest extends MediaWikiLangTestCase { // Create a new context $this->mContext = new DerivativeContext( new RequestContext() ); - $this->mContext->getContext()->setTitle( Title::newFromText( 'Test' ) ); + $this->mContext->getContext()->setTitle( Title::makeTitle( NS_MAIN, 'Test' ) ); $this->mContext->setAuthority( $this->mockUserAuthorityWithPermissions( $this->mUserMock, [ 'editmyoptions' ] ) ); diff --git a/tests/phpunit/includes/api/ApiResultTest.php b/tests/phpunit/includes/api/ApiResultTest.php index 03b2121a46b8..a771b83f0c9e 100644 --- a/tests/phpunit/includes/api/ApiResultTest.php +++ b/tests/phpunit/includes/api/ApiResultTest.php @@ -87,7 +87,7 @@ class ApiResultTest extends MediaWikiIntegrationTestCase { } $arr = []; - $title = Title::newFromText( "MediaWiki:Foobar" ); + $title = Title::makeTitle( NS_MEDIAWIKI, "Foobar" ); $obj = (object)[ 'foo' => 1, 'bar' => 2 ]; ApiResult::setValue( $arr, 'title', $title ); ApiResult::setValue( $arr, 'obj', $obj ); @@ -334,7 +334,7 @@ class ApiResultTest extends MediaWikiIntegrationTestCase { } $result->reset(); - $title = Title::newFromText( "MediaWiki:Foobar" ); + $title = Title::makeTitle( NS_MEDIAWIKI, "Foobar" ); $obj = (object)[ 'foo' => 1, 'bar' => 2 ]; $result->addValue( null, 'title', $title ); $result->addValue( null, 'obj', $obj ); diff --git a/tests/phpunit/includes/api/format/ApiFormatXmlTest.php b/tests/phpunit/includes/api/format/ApiFormatXmlTest.php index 28a9e9e971e7..0a8b94520c1f 100644 --- a/tests/phpunit/includes/api/format/ApiFormatXmlTest.php +++ b/tests/phpunit/includes/api/format/ApiFormatXmlTest.php @@ -124,7 +124,7 @@ class ApiFormatXmlTest extends ApiFormatTestBase { [ 'xslt' => 'MediaWiki:ApiFormatXmlTest' ] ], [ [], '<?xml version="1.0"?><?xml-stylesheet href="' . - htmlspecialchars( Title::newFromText( 'MediaWiki:ApiFormatXmlTest.xsl' )->getLocalURL( 'action=raw' ) ) . + htmlspecialchars( Title::makeTitle( NS_MEDIAWIKI, 'ApiFormatXmlTest.xsl' )->getLocalURL( 'action=raw' ) ) . '" type="text/xsl" ?><api />', [ 'xslt' => 'MediaWiki:ApiFormatXmlTest.xsl' ] ], ]; diff --git a/tests/phpunit/includes/api/query/ApiQueryBasicTest.php b/tests/phpunit/includes/api/query/ApiQueryBasicTest.php index 20fe86ec1691..f9cd579546f5 100644 --- a/tests/phpunit/includes/api/query/ApiQueryBasicTest.php +++ b/tests/phpunit/includes/api/query/ApiQueryBasicTest.php @@ -38,7 +38,7 @@ class ApiQueryBasicTest extends ApiQueryTestBase { */ public function addDBDataOnce() { try { - if ( Title::newFromText( 'AQBT-All' )->exists() ) { + if ( Title::makeTitle( NS_MAIN, 'AQBT-All' )->exists() ) { return; } |