This is moderately messy. Process was principally: * xargs rg --files-with-matches '^use Title;' | grep 'php$' | \ xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1' * rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \ xargs rg --files-with-matches 'Title\b' | \ xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1' * composer fix Then manual fix-ups for a few files that don't have any use statements. Bug: T166010 Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
71 lines
1.8 KiB
PHP
71 lines
1.8 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Search\ParserOutputSearchDataExtractor;
|
|
use MediaWiki\Title\Title;
|
|
|
|
/**
|
|
* @group Search
|
|
* @covers MediaWiki\Search\ParserOutputSearchDataExtractor
|
|
*/
|
|
class ParserOutputSearchDataExtractorTest extends MediaWikiLangTestCase {
|
|
|
|
public function testGetCategories() {
|
|
$categories = [
|
|
'Foo_bar' => 'Bar',
|
|
'New_page' => ''
|
|
];
|
|
|
|
$parserOutput = new ParserOutput( '', [], $categories );
|
|
|
|
$searchDataExtractor = new ParserOutputSearchDataExtractor();
|
|
|
|
$this->assertEquals(
|
|
[ 'Foo bar', 'New page' ],
|
|
$searchDataExtractor->getCategories( $parserOutput )
|
|
);
|
|
}
|
|
|
|
public function testGetExternalLinks() {
|
|
$parserOutput = new ParserOutput();
|
|
|
|
$parserOutput->addExternalLink( 'https://foo' );
|
|
$parserOutput->addExternalLink( 'https://bar' );
|
|
|
|
$searchDataExtractor = new ParserOutputSearchDataExtractor();
|
|
|
|
$this->assertEquals(
|
|
[ 'https://foo', 'https://bar' ],
|
|
$searchDataExtractor->getExternalLinks( $parserOutput )
|
|
);
|
|
}
|
|
|
|
public function testGetOutgoingLinks() {
|
|
$parserOutput = new ParserOutput();
|
|
|
|
$parserOutput->addLink( Title::makeTitle( NS_MAIN, 'Foo_bar' ), 1 );
|
|
$parserOutput->addLink( Title::makeTitle( NS_HELP, 'Contents' ), 2 );
|
|
|
|
$searchDataExtractor = new ParserOutputSearchDataExtractor();
|
|
|
|
// this indexes links with db key
|
|
$this->assertEquals(
|
|
[ 'Foo_bar', 'Help:Contents' ],
|
|
$searchDataExtractor->getOutgoingLinks( $parserOutput )
|
|
);
|
|
}
|
|
|
|
public function testGetTemplates() {
|
|
$title = Title::makeTitle( NS_TEMPLATE, 'Cite_news' );
|
|
|
|
$parserOutput = new ParserOutput();
|
|
$parserOutput->addTemplate( $title, 10, 100 );
|
|
|
|
$searchDataExtractor = new ParserOutputSearchDataExtractor();
|
|
|
|
$this->assertEquals(
|
|
[ 'Template:Cite news' ],
|
|
$searchDataExtractor->getTemplates( $parserOutput )
|
|
);
|
|
}
|
|
|
|
}
|