5 * ^--- trigger DB shadowing because we are using Title magic
7 class ParserOutputTest
extends MediaWikiTestCase
{
9 public static function provideIsLinkInternal() {
12 array( false, 'http://example.org', 'http://mediawiki.org' ),
14 array( true, 'http://example.org', 'http://example.org' ),
15 array( true, 'https://example.org', 'https://example.org' ),
16 array( true, '//example.org', '//example.org' ),
17 // Same domain different cases
18 array( true, 'http://example.org', 'http://EXAMPLE.ORG' ),
19 // Paths, queries, and fragments are not relevant
20 array( true, 'http://example.org', 'http://example.org/wiki/Main_Page' ),
21 array( true, 'http://example.org', 'http://example.org?my=query' ),
22 array( true, 'http://example.org', 'http://example.org#its-a-fragment' ),
23 // Different protocols
24 array( false, 'http://example.org', 'https://example.org' ),
25 array( false, 'https://example.org', 'http://example.org' ),
26 // Protocol relative servers always match http and https links
27 array( true, '//example.org', 'http://example.org' ),
28 array( true, '//example.org', 'https://example.org' ),
29 // But they don't match strange things like this
30 array( false, '//example.org', 'irc://example.org' ),
35 * Test to make sure ParserOutput::isLinkInternal behaves properly
36 * @dataProvider provideIsLinkInternal
37 * @covers ParserOutput::isLinkInternal
39 public function testIsLinkInternal( $shouldMatch, $server, $url ) {
40 $this->assertEquals( $shouldMatch, ParserOutput
::isLinkInternal( $server, $url ) );
44 * @covers ParserOutput::setExtensionData
45 * @covers ParserOutput::getExtensionData
47 public function testExtensionData() {
48 $po = new ParserOutput();
50 $po->setExtensionData( "one", "Foo" );
52 $this->assertEquals( "Foo", $po->getExtensionData( "one" ) );
53 $this->assertNull( $po->getExtensionData( "spam" ) );
55 $po->setExtensionData( "two", "Bar" );
56 $this->assertEquals( "Foo", $po->getExtensionData( "one" ) );
57 $this->assertEquals( "Bar", $po->getExtensionData( "two" ) );
59 $po->setExtensionData( "one", null );
60 $this->assertNull( $po->getExtensionData( "one" ) );
61 $this->assertEquals( "Bar", $po->getExtensionData( "two" ) );
65 * @covers ParserOutput::setProperty
66 * @covers ParserOutput::getProperty
67 * @covers ParserOutput::unsetProperty
68 * @covers ParserOutput::getProperties
70 public function testProperties() {
71 $po = new ParserOutput();
73 $po->setProperty( 'foo', 'val' );
75 $properties = $po->getProperties();
76 $this->assertEquals( $po->getProperty( 'foo' ), 'val' );
77 $this->assertEquals( $properties['foo'], 'val' );
79 $po->setProperty( 'foo', 'second val' );
81 $properties = $po->getProperties();
82 $this->assertEquals( $po->getProperty( 'foo' ), 'second val' );
83 $this->assertEquals( $properties['foo'], 'second val' );
85 $po->unsetProperty( 'foo' );
87 $properties = $po->getProperties();
88 $this->assertEquals( $po->getProperty( 'foo' ), false );
89 $this->assertArrayNotHasKey( 'foo', $properties );
93 * @covers ParserOutput::hasCustomDataUpdates
94 * @covers ParserOutput::addSecondaryDataUpdate
96 public function testHasCustomDataUpdates() {
97 $po = new ParserOutput();
98 $this->assertFalse( $po->hasCustomDataUpdates() );
100 $dataUpdate = $this->getMock( 'DataUpdate' );
101 $po->addSecondaryDataUpdate( $dataUpdate );
102 $this->assertTrue( $po->hasCustomDataUpdates() );
106 * @covers ParserOutput::getSecondaryDataUpdates
107 * @covers ParserOutput::addSecondaryDataUpdate
109 public function testGetSecondaryDataUpdates() {
110 // NOTE: getSecondaryDataUpdates always returns a LinksUpdate object
111 // in addition to the DataUpdates registered via addSecondaryDataUpdate().
113 $title = Title
::makeTitle( NS_MAIN
, 'Dummy' );
114 $title->resetArticleID( 7777777 );
116 $po = new ParserOutput();
117 $this->assertCount( 1, $po->getSecondaryDataUpdates( $title ) );
119 $dataUpdate = $this->getMock( 'DataUpdate' );
120 $po->addSecondaryDataUpdate( $dataUpdate );
121 $this->assertCount( 2, $po->getSecondaryDataUpdates( $title ) );
123 // Test Fallback to getTitleText
124 $this->insertPage( 'Project:ParserOutputTestDummyPage' );
125 $po->setTitleText( 'Project:ParserOutputTestDummyPage' );
126 $this->assertCount( 2, $po->getSecondaryDataUpdates() );
130 * @covers ParserOutput::getSecondaryDataUpdates
131 * @covers ParserOutput::__sleep
133 public function testGetSecondaryDataUpdates_serialization() {
134 $title = Title
::makeTitle( NS_MAIN
, 'Dummy' );
135 $title->resetArticleID( 7777777 );
137 $po = new ParserOutput();
139 // Serializing is fine with no custom DataUpdates.
140 $po = unserialize( serialize( $po ) );
141 $this->assertCount( 1, $po->getSecondaryDataUpdates( $title ) );
143 // If there are custom DataUpdates, getSecondaryDataUpdates
144 // should fail after serialization.
145 $dataUpdate = $this->getMock( 'DataUpdate' );
146 $po->addSecondaryDataUpdate( $dataUpdate );
147 $po = unserialize( serialize( $po ) );
149 $this->setExpectedException( 'MWException' );
150 $po->getSecondaryDataUpdates( $title );