getMutableTestUser()->getUser(); // Create the page and make a couple of edits from different users $this->editPage( $title->getText(), 'AbuseFilter test for title variables', '', $title->getNamespace(), $user ); $mockContributors = [ 'X>Alice', 'X>Bob', 'X>Charlie' ]; foreach ( $mockContributors as $contributor ) { $this->editPage( $title->getText(), "page revision by $contributor", '', $title->getNamespace(), User::newFromName( $contributor, false ) ); } $contributors = array_reverse( $mockContributors ); array_push( $contributors, $user->getName() ); return $contributors; } /** * Test _recent_contributors variables. They perform a custom DB query and thus are tested * here instead of in AbuseFilterTest. * * @covers \MediaWiki\Extension\AbuseFilter\VariableGenerator\VariableGenerator::addTitleVars */ public function testRecentContributors() { $prefixes = [ 'page', 'moved_from', 'moved_to' ]; foreach ( $prefixes as $prefix ) { $varName = "{$prefix}_recent_contributors"; $pageName = "Page to test $varName"; $title = Title::newFromText( $pageName ); $expected = $this->computeRecentContributors( $title ); $vars = new AbuseFilterVariableHolder; $generator = new VariableGenerator( $vars ); $vars = $generator->addTitleVars( $title, $prefix )->getVariableHolder(); $actual = $vars->getVar( $varName )->toNative(); $this->assertSame( $expected, $actual, "Prefix: $prefix" ); } } /** * Check that the generated variables for edits are correct * * @param string $oldText The old wikitext of the page * @param string $newText The new wikitext of the page * @param string $summary * @param array $expected Expected edit vars * @covers \MediaWiki\Extension\AbuseFilter\VariableGenerator\VariableGenerator::addEditVars * @covers AFComputedVariable * @dataProvider provideEditVars */ public function testAddEditVars( $oldText, $newText, $summary, array $expected ) { $pageName = __METHOD__; $title = Title::makeTitle( 0, $pageName ); $page = WikiPage::factory( $title ); $this->editPage( $pageName, $oldText, 'Creating the test page' ); $this->editPage( $pageName, $newText, $summary ); $baseVars = AbuseFilterVariableHolder::newFromArray( [ 'old_wikitext' => $oldText, 'new_wikitext' => $newText, 'summary' => $summary ] ); $generator = new VariableGenerator( $baseVars ); $actual = $generator->addEditVars( $title, $page )->getVariableHolder()->exportAllVars(); // Special case for new_html: avoid flaky tests, and only check containment $this->assertStringContainsString( '