Merge "DumpUploads: output local path instead of mwstore path"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / ParserOutputTest.php
1 <?php
2
3 /**
4 * @group Database
5 * ^--- trigger DB shadowing because we are using Title magic
6 */
7 class ParserOutputTest extends MediaWikiTestCase {
8
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' ],
31 ];
32 }
33
34 /**
35 * Test to make sure ParserOutput::isLinkInternal behaves properly
36 * @dataProvider provideIsLinkInternal
37 * @covers ParserOutput::isLinkInternal
38 */
39 public function testIsLinkInternal( $shouldMatch, $server, $url ) {
40 $this->assertEquals( $shouldMatch, ParserOutput::isLinkInternal( $server, $url ) );
41 }
42
43 /**
44 * @covers ParserOutput::setExtensionData
45 * @covers ParserOutput::getExtensionData
46 */
47 public function testExtensionData() {
48 $po = new ParserOutput();
49
50 $po->setExtensionData( "one", "Foo" );
51
52 $this->assertEquals( "Foo", $po->getExtensionData( "one" ) );
53 $this->assertNull( $po->getExtensionData( "spam" ) );
54
55 $po->setExtensionData( "two", "Bar" );
56 $this->assertEquals( "Foo", $po->getExtensionData( "one" ) );
57 $this->assertEquals( "Bar", $po->getExtensionData( "two" ) );
58
59 $po->setExtensionData( "one", null );
60 $this->assertNull( $po->getExtensionData( "one" ) );
61 $this->assertEquals( "Bar", $po->getExtensionData( "two" ) );
62 }
63
64 /**
65 * @covers ParserOutput::setProperty
66 * @covers ParserOutput::getProperty
67 * @covers ParserOutput::unsetProperty
68 * @covers ParserOutput::getProperties
69 */
70 public function testProperties() {
71 $po = new ParserOutput();
72
73 $po->setProperty( 'foo', 'val' );
74
75 $properties = $po->getProperties();
76 $this->assertEquals( $po->getProperty( 'foo' ), 'val' );
77 $this->assertEquals( $properties['foo'], 'val' );
78
79 $po->setProperty( 'foo', 'second val' );
80
81 $properties = $po->getProperties();
82 $this->assertEquals( $po->getProperty( 'foo' ), 'second val' );
83 $this->assertEquals( $properties['foo'], 'second val' );
84
85 $po->unsetProperty( 'foo' );
86
87 $properties = $po->getProperties();
88 $this->assertEquals( $po->getProperty( 'foo' ), false );
89 $this->assertArrayNotHasKey( 'foo', $properties );
90 }
91
92 }