assertEquals( $shouldMatch, ParserOutput::isLinkInternal( $server, $url ) );
}
/**
* @covers ParserOutput::setExtensionData
* @covers ParserOutput::getExtensionData
*/
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" ) );
}
/**
* @covers ParserOutput::setProperty
* @covers ParserOutput::getProperty
* @covers ParserOutput::unsetProperty
* @covers ParserOutput::getProperties
*/
public function testProperties() {
$po = new ParserOutput();
$po->setProperty( 'foo', 'val' );
$properties = $po->getProperties();
$this->assertEquals( $po->getProperty( 'foo' ), 'val' );
$this->assertEquals( $properties['foo'], 'val' );
$po->setProperty( 'foo', 'second val' );
$properties = $po->getProperties();
$this->assertEquals( $po->getProperty( 'foo' ), 'second val' );
$this->assertEquals( $properties['foo'], 'second val' );
$po->unsetProperty( 'foo' );
$properties = $po->getProperties();
$this->assertEquals( $po->getProperty( 'foo' ), false );
$this->assertArrayNotHasKey( 'foo', $properties );
}
/**
* @covers ParserOutput::getWrapperDivClass
* @covers ParserOutput::addWrapperDivClass
* @covers ParserOutput::clearWrapperDivClass
* @covers ParserOutput::getText
*/
public function testWrapperDivClass() {
$po = new ParserOutput();
$po->setText( 'Kittens' );
$this->assertContains( 'Kittens', $po->getText() );
$this->assertNotContains( '
getText() );
$this->assertSame( 'Kittens', $po->getRawText() );
$po->addWrapperDivClass( 'foo' );
$text = $po->getText();
$this->assertContains( 'Kittens', $text );
$this->assertContains( '
assertContains( 'class="foo"', $text );
$po->addWrapperDivClass( 'bar' );
$text = $po->getText();
$this->assertContains( 'Kittens', $text );
$this->assertContains( '
assertContains( 'class="foo bar"', $text );
$po->addWrapperDivClass( 'bar' ); // second time does nothing, no "foo bar bar".
$text = $po->getText( [ 'unwrap' => true ] );
$this->assertContains( 'Kittens', $text );
$this->assertNotContains( '
assertNotContains( 'class="foo bar"', $text );
$text = $po->getText( [ 'wrapperDivClass' => '' ] );
$this->assertContains( 'Kittens', $text );
$this->assertNotContains( '
assertNotContains( 'class="foo bar"', $text );
$text = $po->getText( [ 'wrapperDivClass' => 'xyzzy' ] );
$this->assertContains( 'Kittens', $text );
$this->assertContains( '
assertContains( 'class="xyzzy"', $text );
$this->assertNotContains( 'class="foo bar"', $text );
$text = $po->getRawText();
$this->assertSame( 'Kittens', $text );
$po->clearWrapperDivClass();
$text = $po->getText();
$this->assertContains( 'Kittens', $text );
$this->assertNotContains( '
assertNotContains( 'class="foo bar"', $text );
}
/**
* @covers ParserOutput::getText
* @dataProvider provideGetText
* @param array $options Options to getText()
* @param string $text Parser text
* @param string $expect Expected output
*/
public function testGetText( $options, $text, $expect ) {
$this->setMwGlobals( [
'wgArticlePath' => '/wiki/$1',
'wgScriptPath' => '/w',
'wgScript' => '/w/index.php',
] );
$po = new ParserOutput( $text );
$actual = $po->getText( $options );
$this->assertSame( $expect, $actual );
}
public static function provideGetText() {
// phpcs:disable Generic.Files.LineLength
$text = <<
Test document.
Section 1Section 1
One
Section 2Section 2
Two
Section 2.1Section 2.1
Two point one
Section 3Section 3
Three
EOF;
$dedupText = <<This is a test document.
EOF;
return [
'No options' => [
[], $text, <<Test document.
Section 1[edit]
One
Section 2[edit]
Two
Section 2.1[edit]
Two point one
Section 3[edit]
Three
EOF
],
'Disable section edit links' => [
[ 'enableSectionEditLinks' => false ], $text, <<Test document.
Section 1
One
Section 2
Two
Section 2.1
Two point one
Section 3
Three
EOF
],
'Disable TOC, but wrap' => [
[ 'allowTOC' => false, 'wrapperDivClass' => 'mw-parser-output' ], $text, <<Test document.
Section 1[edit]
One
Section 2[edit]
Two
Section 2.1[edit]
Two point one
Section 3[edit]
Three
EOF
],
'Style deduplication' => [
[], $dedupText, <<
This is a test document.
EOF
],
'Style deduplication disabled' => [
[ 'deduplicateStyles' => false ], $dedupText, $dedupText
],
];
// phpcs:enable
}
}