summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/parser/ParserOutputTest.php
blob: 68f77ab53791e3bbd1df9350fb81ed67a9be0a8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

class ParserOutputTest extends MediaWikiTestCase {

	function dataIsLinkInternal() {
		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 dataIsLinkInternal
	 */
	function testIsLinkInternal( $shouldMatch, $server, $url ) {

		$this->assertEquals( $shouldMatch, ParserOutput::isLinkInternal( $server, $url ) );
	}

	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" ) );
	}
}