PortableInfobox/tests/phpunit/helpers/PortableInfoboxParsingHelperTest.php

66 lines
1.8 KiB
PHP
Raw Normal View History

2016-12-14 12:54:53 +00:00
<?php
2021-09-11 23:07:07 +00:00
2018-08-08 09:42:22 +00:00
/**
* @group PortableInfobox
2021-09-11 23:07:07 +00:00
* @group Database
* @covers PortableInfobox\Helpers\PortableInfoboxParsingHelper
2018-08-08 09:42:22 +00:00
*/
2021-12-15 22:01:13 +00:00
class PortableInfoboxParsingHelperTest extends MediaWikiIntegrationTestCase {
2016-12-14 12:54:53 +00:00
/**
2017-03-15 18:07:51 +00:00
* @dataProvider parsingIncludeonlyInfoboxesDataProvider
2016-12-14 12:54:53 +00:00
*/
public function testParsingIncludeonlyInfoboxes( $markup, $expected ) {
$helper = $this->getMockBuilder( PortableInfobox\Helpers\PortableInfoboxParsingHelper::class )
2017-03-15 18:07:51 +00:00
->setMethods( [ 'fetchArticleContent' ] )
->getMock();
$helper->expects( $this->once() )
->method( 'fetchArticleContent' )
->will( $this->returnValue( $markup ) );
2016-12-14 12:54:53 +00:00
2021-09-11 23:07:07 +00:00
$result = $helper->parseIncludeonlyInfoboxes( $this->getExistingTestPage( 'Test' )->getTitle() );
2016-12-14 12:54:53 +00:00
$this->assertEquals( $expected, $result );
}
2017-03-15 18:07:51 +00:00
public function parsingIncludeonlyInfoboxesDataProvider() {
2016-12-14 12:54:53 +00:00
return [
[ 'test', false ],
[
'<includeonly><infobox><data source="test"><label>1</label></data></infobox></includeonly>',
[
[
'parser_tag_version' => PortableInfoboxParserTagController::PARSER_TAG_VERSION,
'data' => [],
'metadata' => [
[
'type' => 'data',
'sources' => [
'test' => [
'label' => '1',
'primary' => true
]
]
]
]
]
]
],
2018-08-08 09:42:22 +00:00
[ '<noinclude><infobox></infobox></noinclude>', false ],
[ '<onlyinclude></onlyinclude><infobox></infobox>', false ],
2016-12-14 12:54:53 +00:00
[
2018-08-08 09:42:22 +00:00
'<includeonly></includeonly><infobox></infobox>',
2016-12-14 12:54:53 +00:00
[
[
'parser_tag_version' => PortableInfoboxParserTagController::PARSER_TAG_VERSION,
'data' => [],
'metadata' => []
]
]
],
[ '<nowiki><includeonly><infobox></infobox></includeonly></nowiki>', false ],
[ '<includeonly><nowiki><infobox></infobox></nowiki></includeonly>', false ],
];
}
}