Merge "Special:Version: Link to tree instead of commit for git hashes"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / ParserOutputTest.php
1 <?php
2
3 class ParserOutputTest extends MediaWikiTestCase {
4
5 public static function provideIsLinkInternal() {
6 return array(
7 // Different domains
8 array( false, 'http://example.org', 'http://mediawiki.org' ),
9 // Same domains
10 array( true, 'http://example.org', 'http://example.org' ),
11 array( true, 'https://example.org', 'https://example.org' ),
12 array( true, '//example.org', '//example.org' ),
13 // Same domain different cases
14 array( true, 'http://example.org', 'http://EXAMPLE.ORG' ),
15 // Paths, queries, and fragments are not relevant
16 array( true, 'http://example.org', 'http://example.org/wiki/Main_Page' ),
17 array( true, 'http://example.org', 'http://example.org?my=query' ),
18 array( true, 'http://example.org', 'http://example.org#its-a-fragment' ),
19 // Different protocols
20 array( false, 'http://example.org', 'https://example.org' ),
21 array( false, 'https://example.org', 'http://example.org' ),
22 // Protocol relative servers always match http and https links
23 array( true, '//example.org', 'http://example.org' ),
24 array( true, '//example.org', 'https://example.org' ),
25 // But they don't match strange things like this
26 array( false, '//example.org', 'irc://example.org' ),
27 );
28 }
29
30 /**
31 * Test to make sure ParserOutput::isLinkInternal behaves properly
32 * @dataProvider provideIsLinkInternal
33 * @covers ParserOutput::isLinkInternal
34 */
35 public function testIsLinkInternal( $shouldMatch, $server, $url ) {
36 $this->assertEquals( $shouldMatch, ParserOutput::isLinkInternal( $server, $url ) );
37 }
38
39 /**
40 * @covers ParserOutput::setExtensionData
41 * @covers ParserOutput::getExtensionData
42 */
43 public function testExtensionData() {
44 $po = new ParserOutput();
45
46 $po->setExtensionData( "one", "Foo" );
47
48 $this->assertEquals( "Foo", $po->getExtensionData( "one" ) );
49 $this->assertNull( $po->getExtensionData( "spam" ) );
50
51 $po->setExtensionData( "two", "Bar" );
52 $this->assertEquals( "Foo", $po->getExtensionData( "one" ) );
53 $this->assertEquals( "Bar", $po->getExtensionData( "two" ) );
54
55 $po->setExtensionData( "one", null );
56 $this->assertNull( $po->getExtensionData( "one" ) );
57 $this->assertEquals( "Bar", $po->getExtensionData( "two" ) );
58 }
59
60 /**
61 * @covers ParserOutput::setProperty
62 * @covers ParserOutput::getProperty
63 * @covers ParserOutput::unsetProperty
64 * @covers ParserOutput::getProperties
65 */
66 public function testProperties() {
67 $po = new ParserOutput();
68
69 $po->setProperty( 'foo', 'val' );
70
71 $properties = $po->getProperties();
72 $this->assertEquals( $po->getProperty( 'foo' ), 'val' );
73 $this->assertEquals( $properties['foo'], 'val' );
74
75 $po->setProperty( 'foo', 'second val' );
76
77 $properties = $po->getProperties();
78 $this->assertEquals( $po->getProperty( 'foo' ), 'second val' );
79 $this->assertEquals( $properties['foo'], 'second val' );
80
81 $po->unsetProperty( 'foo' );
82
83 $properties = $po->getProperties();
84 $this->assertEquals( $po->getProperty( 'foo' ), false );
85 $this->assertArrayNotHasKey( 'foo', $properties );
86 }
87 }