aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/content/WikitextContentHandlerTest.php
diff options
context:
space:
mode:
authorDaimona Eaytoy <daimona.wiki@gmail.com>2023-07-16 02:16:45 +0200
committerDaimona Eaytoy <daimona.wiki@gmail.com>2023-07-31 00:46:13 +0000
commit485e47ff102fbf172f6f906e17b6bfa578978fd9 (patch)
treec82b406f3bc5f2b143be8a27071597e104a54148 /tests/phpunit/includes/content/WikitextContentHandlerTest.php
parentb03fc0147e005d492f5ffda54f6ed7acef3868b1 (diff)
downloadmediawikicore-485e47ff102fbf172f6f906e17b6bfa578978fd9.tar.gz
mediawikicore-485e47ff102fbf172f6f906e17b6bfa578978fd9.zip
tests: Avoid database usage when possible
We would like to remove DB access in non-database PHPUnit tests. As a first step, avoid database usage in tested code when possible. In particular: - In NameTableStoreFactory, avoid domain ID normalization if the provided ID is already false. - In SpecialDoubleRedirects, do not acquire a DB connection until it's needed (which is just one place). - Use editPage() in TitleDefTest instead of a DIY implementation, and add `@group Database` accordingly. - Avoid parsing titles in ContentHandler tests that don't need to parse titles. Among the many dependencies of parsing titles is the interwiki lookup, which requires DB access. - Also remove test cases that used the "Gadget" namespace; it doesn't exist in core, so these pages were actually in the mainspace. - Mock the database in CategoriesRdfTest. The only two methods that use the database were already being mocked. - Add `@group Database` to test classes that are intentionally using the Database, mainly via getTestUser(). Bug: T155147 Change-Id: I9385fe14cfeb6b7b7378cc322d510034c4ee0711
Diffstat (limited to 'tests/phpunit/includes/content/WikitextContentHandlerTest.php')
-rw-r--r--tests/phpunit/includes/content/WikitextContentHandlerTest.php31
1 files changed, 15 insertions, 16 deletions
diff --git a/tests/phpunit/includes/content/WikitextContentHandlerTest.php b/tests/phpunit/includes/content/WikitextContentHandlerTest.php
index 1c037c2a5353..c90b8895d3bd 100644
--- a/tests/phpunit/includes/content/WikitextContentHandlerTest.php
+++ b/tests/phpunit/includes/content/WikitextContentHandlerTest.php
@@ -1,8 +1,10 @@
<?php
+use MediaWiki\Linker\LinkTarget;
use MediaWiki\MainConfigNames;
use MediaWiki\Page\PageReferenceValue;
use MediaWiki\Title\Title;
+use MediaWiki\User\UserIdentity;
/**
* See also unit tests at \MediaWiki\Tests\Unit\WikitextContentHandlerTest
@@ -22,33 +24,30 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase {
/**
* @dataProvider provideMakeRedirectContent
- * @param Title|string $title Title object or string for Title::newFromText()
+ * @param LinkTarget $target
* @param string $expected Serialized form of the content object built
* @covers WikitextContentHandler::makeRedirectContent
*/
- public function testMakeRedirectContent( $title, $expected ) {
+ public function testMakeRedirectContent( LinkTarget $target, $expected ) {
$this->getServiceContainer()->resetServiceForTesting( 'ContentLanguage' );
$this->getServiceContainer()->resetServiceForTesting( 'MagicWordFactory' );
- if ( is_string( $title ) ) {
- $title = Title::newFromText( $title );
- }
- $content = $this->handler->makeRedirectContent( $title );
+ $content = $this->handler->makeRedirectContent( Title::newFromLinkTarget( $target ) );
$this->assertEquals( $expected, $content->serialize() );
}
public static function provideMakeRedirectContent() {
return [
- [ 'Hello', '#REDIRECT [[Hello]]' ],
- [ 'Template:Hello', '#REDIRECT [[Template:Hello]]' ],
- [ 'Hello#section', '#REDIRECT [[Hello#section]]' ],
- [ 'user:john_doe#section', '#REDIRECT [[User:John doe#section]]' ],
- [ 'MEDIAWIKI:FOOBAR', '#REDIRECT [[MediaWiki:FOOBAR]]' ],
- [ 'Category:Foo', '#REDIRECT [[:Category:Foo]]' ],
- [ Title::makeTitle( NS_MAIN, 'en:Foo' ), '#REDIRECT [[en:Foo]]' ],
- [ Title::makeTitle( NS_MAIN, 'Foo', '', 'en' ), '#REDIRECT [[:en:Foo]]' ],
+ [ new TitleValue( NS_MAIN, 'Hello' ), '#REDIRECT [[Hello]]' ],
+ [ new TitleValue( NS_TEMPLATE, 'Hello' ), '#REDIRECT [[Template:Hello]]' ],
+ [ new TitleValue( NS_MAIN, 'Hello', 'section' ), '#REDIRECT [[Hello#section]]' ],
+ [ new TitleValue( NS_USER, 'John doe', 'section' ), '#REDIRECT [[User:John doe#section]]' ],
+ [ new TitleValue( NS_MEDIAWIKI, 'FOOBAR' ), '#REDIRECT [[MediaWiki:FOOBAR]]' ],
+ [ new TitleValue( NS_CATEGORY, 'Foo' ), '#REDIRECT [[:Category:Foo]]' ],
+ [ new TitleValue( NS_MAIN, 'en:Foo' ), '#REDIRECT [[en:Foo]]' ],
+ [ new TitleValue( NS_MAIN, 'Foo', '', 'en' ), '#REDIRECT [[:en:Foo]]' ],
[
- Title::makeTitle( NS_MAIN, 'Bar', 'fragment', 'google' ),
+ new TitleValue( NS_MAIN, 'Bar', 'fragment', 'google' ),
'#REDIRECT [[google:Bar#fragment]]'
],
];
@@ -309,7 +308,7 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase {
$pstContent = $contentTransformer->preSaveTransform(
$content,
$pageObj,
- $this->getTestUser()->getUser(),
+ $this->createMock( UserIdentity::class ),
ParserOptions::newFromAnon()
);