mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
tests: Avoid Title::newFromText/title parsing
Using Title::newFromText is parsing the string, which is expensive. Just use Title::makeTitle when the result is known. editPage() can take a Title or WikiPage instead of a string, avoid creation of Title there. The default ns on editPage() is only needed when giving a string Change-Id: Ie303b9e6d6b8d6ac80286059f8e86bfc76b779af
This commit is contained in:
parent
b381636974
commit
637a88316b
|
@ -473,8 +473,7 @@ class AbuseFilterConsequencesTest extends MediaWikiIntegrationTestCase {
|
|||
$status = $this->editPage(
|
||||
$page,
|
||||
$oldText,
|
||||
__METHOD__ . ' page creation',
|
||||
$title->getNamespace()
|
||||
__METHOD__ . ' page creation'
|
||||
);
|
||||
if ( !$status->isGood() ) {
|
||||
throw new Exception( "Could not create test page. $status" );
|
||||
|
@ -517,7 +516,7 @@ class AbuseFilterConsequencesTest extends MediaWikiIntegrationTestCase {
|
|||
$page,
|
||||
$newText,
|
||||
$summary,
|
||||
$title->getNamespace(),
|
||||
NS_MAIN,
|
||||
$this->user
|
||||
);
|
||||
}
|
||||
|
@ -1566,7 +1565,7 @@ class AbuseFilterConsequencesTest extends MediaWikiIntegrationTestCase {
|
|||
// Filter 24 has no actions and always matches
|
||||
$this->createFilters( [ 24 ] );
|
||||
|
||||
$targetTitle = Title::newFromText( 'TestRevIdSet' );
|
||||
$targetTitle = Title::makeTitle( NS_MAIN, 'TestRevIdSet' );
|
||||
$startingRevId = $targetTitle->getLatestRevID( Title::READ_LATEST );
|
||||
|
||||
$this->doEdit( $targetTitle, 'Old text', 'New text', 'Summary' );
|
||||
|
|
|
@ -32,12 +32,11 @@ class LazyVariableComputerDBTest extends MediaWikiIntegrationTestCase {
|
|||
* @dataProvider provideEditRelatedVars
|
||||
*/
|
||||
public function testEditRelatedVars( $oldText, $newText, $summary, array $expected ) {
|
||||
$pageName = __METHOD__;
|
||||
$title = Title::makeTitle( 0, $pageName );
|
||||
$title = Title::makeTitle( NS_MAIN, 'TestEditRelatedVars' );
|
||||
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
|
||||
|
||||
$this->editPage( $pageName, $oldText, 'Creating the test page' );
|
||||
$this->editPage( $pageName, $newText, $summary );
|
||||
$this->editPage( $page, $oldText, 'Creating the test page' );
|
||||
$this->editPage( $page, $newText, $summary );
|
||||
|
||||
$baseVars = VariableHolder::newFromArray( [
|
||||
'old_wikitext' => $oldText,
|
||||
|
@ -155,19 +154,19 @@ class LazyVariableComputerDBTest extends MediaWikiIntegrationTestCase {
|
|||
$user = $this->getMutableTestUser()->getUser();
|
||||
// Create the page and make a couple of edits from different users
|
||||
$this->editPage(
|
||||
$title->getText(),
|
||||
$title,
|
||||
'AbuseFilter test for title variables',
|
||||
'',
|
||||
$title->getNamespace(),
|
||||
NS_MAIN,
|
||||
$user
|
||||
);
|
||||
$mockContributors = [ 'X>Alice', 'X>Bob', 'X>Charlie' ];
|
||||
foreach ( $mockContributors as $contributor ) {
|
||||
$this->editPage(
|
||||
$title->getText(),
|
||||
$title,
|
||||
"page revision by $contributor",
|
||||
'',
|
||||
$title->getNamespace(),
|
||||
NS_MAIN,
|
||||
User::newFromName( $contributor, false )
|
||||
);
|
||||
}
|
||||
|
@ -182,8 +181,7 @@ class LazyVariableComputerDBTest extends MediaWikiIntegrationTestCase {
|
|||
*/
|
||||
public function testRecentContributors() {
|
||||
$varName = "page_recent_contributors";
|
||||
$pageName = "Page to test $varName";
|
||||
$title = Title::newFromText( $pageName );
|
||||
$title = Title::makeTitle( NS_MAIN, "Page to test $varName" );
|
||||
|
||||
$expected = $this->computeRecentContributors( $title );
|
||||
$computer = AbuseFilterServices::getLazyVariableComputer();
|
||||
|
|
Loading…
Reference in a new issue