This is a hard deprecation, with getSecondaryDataUpdates returning an empty array and addSecondaryDataUpdate throwing an exception. This seems prudent since there are no known users of these methods, and they interfere with the parser cache: DataUpdates are basically jobs, they need access to services to function. That makes them inherently non-serializable. This interferes with the function of the parser cache, which serializes ParserOutput objects in order to persist them. This could be solved by splitting DataUpdates into DataUpdateDefinitions and DataUpdateHandlers, similar to how JobSpecification works with wgJobClasses. That however seems pointless and overkill, since ParserOutput already has a mechanism for storing arbitrary data, including any info needed by an UpdateJob: the setExtensionData method. After this change, the preferred method to introduce custom data updates is to store any relevant data using setExtensionData and implement Content::getSecondaryDataUpdates() if possible. If not, use the 'SecondaryDataUpdates' hook to construct the necessary update objects from the info stored using setExtensionData. Change-Id: I0f6f49e61fa3d8904e55f42c99f342a3dc357495
92 lines
3.1 KiB
PHP
92 lines
3.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group Database
|
|
* ^--- trigger DB shadowing because we are using Title magic
|
|
*/
|
|
class ParserOutputTest extends MediaWikiTestCase {
|
|
|
|
public static function provideIsLinkInternal() {
|
|
return array(
|
|
// Different domains
|
|
array( false, 'http://example.org', 'http://mediawiki.org' ),
|
|
// Same domains
|
|
array( true, 'http://example.org', 'http://example.org' ),
|
|
array( true, 'https://example.org', 'https://example.org' ),
|
|
array( true, '//example.org', '//example.org' ),
|
|
// Same domain different cases
|
|
array( true, 'http://example.org', 'http://EXAMPLE.ORG' ),
|
|
// Paths, queries, and fragments are not relevant
|
|
array( true, 'http://example.org', 'http://example.org/wiki/Main_Page' ),
|
|
array( true, 'http://example.org', 'http://example.org?my=query' ),
|
|
array( true, 'http://example.org', 'http://example.org#its-a-fragment' ),
|
|
// Different protocols
|
|
array( false, 'http://example.org', 'https://example.org' ),
|
|
array( false, 'https://example.org', 'http://example.org' ),
|
|
// Protocol relative servers always match http and https links
|
|
array( true, '//example.org', 'http://example.org' ),
|
|
array( true, '//example.org', 'https://example.org' ),
|
|
// But they don't match strange things like this
|
|
array( false, '//example.org', 'irc://example.org' ),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Test to make sure ParserOutput::isLinkInternal behaves properly
|
|
* @dataProvider provideIsLinkInternal
|
|
* @covers ParserOutput::isLinkInternal
|
|
*/
|
|
public function testIsLinkInternal( $shouldMatch, $server, $url ) {
|
|
$this->assertEquals( $shouldMatch, ParserOutput::isLinkInternal( $server, $url ) );
|
|
}
|
|
|
|
/**
|
|
* @covers ParserOutput::setExtensionData
|
|
* @covers ParserOutput::getExtensionData
|
|
*/
|
|
public function testExtensionData() {
|
|
$po = new ParserOutput();
|
|
|
|
$po->setExtensionData( "one", "Foo" );
|
|
|
|
$this->assertEquals( "Foo", $po->getExtensionData( "one" ) );
|
|
$this->assertNull( $po->getExtensionData( "spam" ) );
|
|
|
|
$po->setExtensionData( "two", "Bar" );
|
|
$this->assertEquals( "Foo", $po->getExtensionData( "one" ) );
|
|
$this->assertEquals( "Bar", $po->getExtensionData( "two" ) );
|
|
|
|
$po->setExtensionData( "one", null );
|
|
$this->assertNull( $po->getExtensionData( "one" ) );
|
|
$this->assertEquals( "Bar", $po->getExtensionData( "two" ) );
|
|
}
|
|
|
|
/**
|
|
* @covers ParserOutput::setProperty
|
|
* @covers ParserOutput::getProperty
|
|
* @covers ParserOutput::unsetProperty
|
|
* @covers ParserOutput::getProperties
|
|
*/
|
|
public function testProperties() {
|
|
$po = new ParserOutput();
|
|
|
|
$po->setProperty( 'foo', 'val' );
|
|
|
|
$properties = $po->getProperties();
|
|
$this->assertEquals( $po->getProperty( 'foo' ), 'val' );
|
|
$this->assertEquals( $properties['foo'], 'val' );
|
|
|
|
$po->setProperty( 'foo', 'second val' );
|
|
|
|
$properties = $po->getProperties();
|
|
$this->assertEquals( $po->getProperty( 'foo' ), 'second val' );
|
|
$this->assertEquals( $properties['foo'], 'second val' );
|
|
|
|
$po->unsetProperty( 'foo' );
|
|
|
|
$properties = $po->getProperties();
|
|
$this->assertEquals( $po->getProperty( 'foo' ), false );
|
|
$this->assertArrayNotHasKey( 'foo', $properties );
|
|
}
|
|
|
|
}
|