rdbms: Rename "memCache" to "memStash" in LBFactory
[mediawiki.git] / tests / phpunit / includes / parser / ParserOutputTest.php
blobec8f0d076d92a85821d5c9e847cd84af4ff82a02
1 <?php
3 /**
4 * @group Database
5 * ^--- trigger DB shadowing because we are using Title magic
6 */
7 class ParserOutputTest extends MediaWikiTestCase {
9 public static function provideIsLinkInternal() {
10 return [
11 // Different domains
12 [ false, 'http://example.org', 'http://mediawiki.org' ],
13 // Same domains
14 [ true, 'http://example.org', 'http://example.org' ],
15 [ true, 'https://example.org', 'https://example.org' ],
16 [ true, '//example.org', '//example.org' ],
17 // Same domain different cases
18 [ true, 'http://example.org', 'http://EXAMPLE.ORG' ],
19 // Paths, queries, and fragments are not relevant
20 [ true, 'http://example.org', 'http://example.org/wiki/Main_Page' ],
21 [ true, 'http://example.org', 'http://example.org?my=query' ],
22 [ true, 'http://example.org', 'http://example.org#its-a-fragment' ],
23 // Different protocols
24 [ false, 'http://example.org', 'https://example.org' ],
25 [ false, 'https://example.org', 'http://example.org' ],
26 // Protocol relative servers always match http and https links
27 [ true, '//example.org', 'http://example.org' ],
28 [ true, '//example.org', 'https://example.org' ],
29 // But they don't match strange things like this
30 [ false, '//example.org', 'irc://example.org' ],
34 /**
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 ) );
43 /**
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" ) );
64 /**
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 );