This moves the implementation of ParserOutput::addTrackingCategory() to the TrackingCategories class as a non-static method. This makes invocation from ParserOutput awkward, but when invoking as Parser::addTrackingCategory() all the necessary services are available. As a result, we've also soft-deprecated ParserOutput::addTrackingCategory(); new users should use the TrackingCategories::addTrackingCategory() method, or else Parser::addTrackingCategory() if the parser object is available. The Parser class is already kind of bloated as it is (alas), but there aren't too many callsites which invoke ParserOutput::addTrackingCategory() and don't have the corresponding Parser object handy; see: https://codesearch.wmcloud.org/search/?q=%5BOo%5Dutput%28%5C%28%5C%29%29%3F-%3EaddTrackingCategory%5C%28&i=nope&files=&excludeFiles=&repos= Change-Id: I697ce188a912e445a6a748121575548e79aabac6
47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Config\ServiceOptions;
|
|
use MediaWiki\Logger\LoggerFactory;
|
|
use MediaWiki\Page\PageReferenceValue;
|
|
|
|
/**
|
|
* @covers ParserOutput
|
|
* @covers CacheTime
|
|
* @group Database
|
|
* ^--- trigger DB shadowing because we are using Title magic
|
|
*/
|
|
class TrackingCategoriesTest extends MediaWikiLangTestCase {
|
|
/**
|
|
* @covers ParserOutput::addTrackingCategory
|
|
*/
|
|
public function testAddTrackingCategory() {
|
|
$services = $this->getServiceContainer();
|
|
$tc = new TrackingCategories(
|
|
new ServiceOptions(
|
|
TrackingCategories::CONSTRUCTOR_OPTIONS,
|
|
$services->getMainConfig()
|
|
),
|
|
$services->getNamespaceInfo(),
|
|
$services->getTitleParser(),
|
|
LoggerFactory::getInstance( 'TrackingCategories' )
|
|
);
|
|
|
|
$po = new ParserOutput;
|
|
$po->setPageProperty( 'defaultsort', 'foobar' );
|
|
|
|
$page = PageReferenceValue::localReference( NS_USER, 'Testing' );
|
|
|
|
$tc->addTrackingCategory( $po, 'index-category', $page ); // from CORE_TRACKING_CATEGORIES
|
|
$tc->addTrackingCategory( $po, 'sitenotice', $page ); // should be "-", which is ignored
|
|
$tc->addTrackingCategory( $po, 'brackets-start', $page ); // invalid text
|
|
// TODO: assert proper handling of non-existing messages
|
|
|
|
$expected = wfMessage( 'index-category' )
|
|
->page( $page )
|
|
->inContentLanguage()
|
|
->text();
|
|
|
|
$expected = strtr( $expected, ' ', '_' );
|
|
$this->assertSame( [ $expected => 'foobar' ], $po->getCategories() );
|
|
}
|
|
}
|