Increase code coverage

This commit is contained in:
Luqgreg 2018-08-13 16:31:50 +02:00
parent 626710caf9
commit c9d1bd4f10
17 changed files with 559 additions and 52 deletions

View file

@ -93,25 +93,6 @@ class PortableInfoboxParsingHelper {
return $text; return $text;
} }
/**
* @desc returns the text from inside of the first <includeonly> tag and
* without the nowiki and pre tags.
*
* @param $text string template text
*
* @return string
*/
protected function getIncludeonlyText( $text ) {
$clean = $this->removeNowikiPre( $text );
preg_match_all( "/<includeonly>(.+)<\/includeonly>/sU", $clean, $result );
if ( !isset( $result[ 1 ][ 0 ] ) ) {
return null;
}
return $result[ 1 ][ 0 ];
}
/** /**
* @desc From the template without <includeonly> tags, creates an array of * @desc From the template without <includeonly> tags, creates an array of
* strings containing only infoboxes. All template content which is not an infobox is removed. * strings containing only infoboxes. All template content which is not an infobox is removed.

View file

@ -25,7 +25,7 @@ class PortableInfoboxTemplateEngine {
'media-collection' => 'PortableInfoboxItemMediaCollection.hbs', 'media-collection' => 'PortableInfoboxItemMediaCollection.hbs',
'xml-parse-error' => 'PortableInfoboxMarkupDebug.hbs' 'xml-parse-error' => 'PortableInfoboxMarkupDebug.hbs'
]; ];
public function __construct() {} public function __construct() {}
public static function getTemplatesDir() { public static function getTemplatesDir() {
@ -52,7 +52,7 @@ class PortableInfoboxTemplateEngine {
return self::$cache[ $type ]; return self::$cache[ $type ];
} }
$path = self::getTemplatesDir() . DIRECTORY_SEPARATOR . self::$templates[ $type ]; $path = self::getTemplatesDir() . DIRECTORY_SEPARATOR . static::getTemplates()[ $type ];
// @see https://github.com/wikimedia/mediawiki-vendor/tree/master/zordius/lightncandy // @see https://github.com/wikimedia/mediawiki-vendor/tree/master/zordius/lightncandy
$renderer = \LightnCandy::prepare( $renderer = \LightnCandy::prepare(
@ -74,7 +74,7 @@ class PortableInfoboxTemplateEngine {
* @return bool * @return bool
*/ */
public static function isSupportedType( $type ) { public static function isSupportedType( $type ) {
$result = isset( static::$templates[ $type ] ); $result = isset( static::getTemplates()[ $type ] );
if ( !$result ) { if ( !$result ) {
LoggerFactory::getInstance( 'PortableInfobox' )->info( self::TYPE_NOT_SUPPORTED_MESSAGE, [ 'type' => $type ] ); LoggerFactory::getInstance( 'PortableInfobox' )->info( self::TYPE_NOT_SUPPORTED_MESSAGE, [ 'type' => $type ] );
} }

View file

@ -11,7 +11,7 @@ class InfoboxParamsValidatorTest extends MediaWikiTestCase {
parent::setUp(); parent::setUp();
$this->InfoboxParamsValidator = new PortableInfobox\Helpers\InfoboxParamsValidator(); $this->InfoboxParamsValidator = new PortableInfobox\Helpers\InfoboxParamsValidator();
} }
protected function tearDown() { protected function tearDown() {
unset($this->InfoboxParamsValidator); unset($this->InfoboxParamsValidator);
parent::tearDown(); parent::tearDown();
@ -73,7 +73,7 @@ class InfoboxParamsValidatorTest extends MediaWikiTestCase {
} }
/** /**
* @param $color * @param array $color
* @dataProvider passValidateColorValueDataProvider * @dataProvider passValidateColorValueDataProvider
*/ */
public function testPassValidateColorValue( $color ) { public function testPassValidateColorValue( $color ) {
@ -148,4 +148,34 @@ class InfoboxParamsValidatorTest extends MediaWikiTestCase {
[ 'color' => '#aaaaa' ], [ 'color' => '#aaaaa' ],
]; ];
} }
/**
* @param array $layout
* @dataProvider passValidateLayoutDataProvider
*/
public function testPassValidateLayout( $layout ) {
$this->assertTrue( $this->InfoboxParamsValidator->validateLayout( $layout ) );
}
public function passValidateLayoutDataProvider() {
return [
[ 'layout' => 'default' ],
[ 'layout' => 'stacked' ]
];
}
/**
* @param array $layout
* @dataProvider failValidateLayoutDataProvider
*/
public function testFailValidateLayout( $layout ) {
$this->assertFalse( $this->InfoboxParamsValidator->validateLayout( $layout ) );
}
public function failValidateLayoutDataProvider() {
return [
[ 'layout' => '' ],
[ 'layout' => 'custom' ]
];
}
} }

View file

@ -236,6 +236,14 @@ class PortableInfoboxDataServiceTest extends MediaWikiTestCase {
] ]
]; ];
} }
public function testGetInfoboxes() {
$result = PortableInfoboxDataService::newFromTitle( $this->prepareTitle( 1 ) )
->setParsingHelper( new ParsingHelperDummy() )
->getInfoboxes();
$this->assertEquals( $result, [ "markup" ] );
}
} }
class ParsingHelperDummy { class ParsingHelperDummy {
@ -252,6 +260,10 @@ class ParsingHelperDummy {
public function reparseArticle( $title ) { public function reparseArticle( $title ) {
return $this->infoboxesData; return $this->infoboxesData;
} }
public function getMarkup( Title $title ) {
return [ "markup" ];
}
} }
class PagePropsProxyDummy { class PagePropsProxyDummy {

View file

@ -1,7 +1,7 @@
<?php <?php
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfoboxParserTagController * @covers PortableInfoboxRenderService
*/ */
class PortableInfoboxRenderServiceTest extends MediaWikiTestCase { class PortableInfoboxRenderServiceTest extends MediaWikiTestCase {
@ -22,7 +22,22 @@ class PortableInfoboxRenderServiceTest extends MediaWikiTestCase {
return $DOM->saveXML(); return $DOM->saveXML();
} }
public function testGetImageHelper() {
$infoboxRenderService = new PortableInfoboxRenderService();
$reflection = new ReflectionClass( $infoboxRenderService );
$reflection_method = $reflection->getMethod( 'getImageHelper' );
$reflection_method->setAccessible( true );
$this->assertInstanceOf(
\PortableInfobox\Helpers\PortableInfoboxImagesHelper::class,
$reflection_method->invoke( $infoboxRenderService )
);
}
/** /**
* @covers PortableInfoboxRenderService::renderInfobox
* @covers PortableInfobox\Helpers\PortableInfoboxTemplateEngine
* @param $input * @param $input
* @param $expectedOutput * @param $expectedOutput
* @param $description * @param $description
@ -1588,13 +1603,204 @@ class PortableInfoboxRenderServiceTest extends MediaWikiTestCase {
'accentColor' => '', 'accentColor' => '',
'accentColorText' => '' 'accentColorText' => ''
], ],
[
'input' => [
[
'type' => 'title',
'data' => [
'value' => 'Test Title'
]
],
[
'type' => 'image',
'data' => [
[
'alt' => 'image alt',
'url' => 'http://image.jpg',
'caption' => 'caption'
],
[
'alt' => 'image alt',
'url' => 'http://image.jpg',
'caption' => 'caption'
]
]
]
],
'output' => '<aside class="portable-infobox pi-background">
<h2 class="pi-item pi-item-spacing pi-title">Test Title</h2>
<div class="pi-media-collection">
<ul class="pi-media-collection-tabs">
<li class="pi-tab-link pi-item-spacing current" data-pi-tab="pi-tab-1">caption</li>
<li class="pi-tab-link pi-item-spacing" data-pi-tab="pi-tab-2">caption</li>
</ul>
<div class="pi-media-collection-tab-content current" id="pi-tab-1">
<figure class="pi-item pi-media pi-image">
<a href="http://image.jpg" class="image image-thumbnail" title="image alt">
<img src="http://thumbnail.jpg" srcset="http://thumbnail.jpg 1x, http://thumbnail2x.jpg 2x" class="pi-image-thumbnail" alt="image alt"
width="400" height="200"/>
</a>
</figure>
</div>
<div class="pi-media-collection-tab-content" id="pi-tab-2">
<figure class="pi-item pi-media pi-image">
<a href="http://image.jpg" class="image image-thumbnail" title="image alt">
<img src="http://thumbnail.jpg" srcset="http://thumbnail.jpg 1x, http://thumbnail2x.jpg 2x" class="pi-image-thumbnail" alt="image alt"
width="400" height="200"/>
</a>
</figure>
</div>
</div>
</aside>',
'description' => 'Simple infobox with title and image collection',
'mockParams' => [
'extendImageData' => [
'alt' => 'image alt',
'url' => 'http://image.jpg',
'caption' => 'caption',
'ref' => 1,
'width' => '400',
'height' => '200',
'thumbnail' => 'http://thumbnail.jpg',
'thumbnail2x' => 'http://thumbnail2x.jpg',
'isImage' => true
]
],
'accentColor' => '',
'accentColorText' => ''
],
[
'input' => [
[
'type' => 'title',
'data' => [
'value' => 'Test Title'
]
],
[
'type' => 'group',
'data' => [
'value' => [
[
'type' => 'header',
'data' => [
'value' => 'Test Header'
]
],
[
'type' => 'data',
'data' => [
'label' => 'test label',
'value' => 'test value'
]
],
[
'type' => 'data',
'data' => [
'label' => 'test label',
'value' => 'test value'
]
]
],
'layout' => 'default',
'collapse' => 'open',
'row-items' => null
]
]
],
'output' => '<aside class="portable-infobox pi-background">
<h2 class="pi-item pi-item-spacing pi-title">Test Title</h2>
<section class="pi-item pi-group pi-border-color pi-collapse pi-collapse-open">
<h2 class="pi-item pi-header pi-secondary-font pi-item-spacing pi-secondary-background">Test Header</h2>
<div class="pi-item pi-data pi-item-spacing pi-border-color">
<h3 class="pi-data-label pi-secondary-font">test label</h3>
<div class="pi-data-value pi-font">test value</div>
</div>
<div class="pi-item pi-data pi-item-spacing pi-border-color">
<h3 class="pi-data-label pi-secondary-font">test label</h3>
<div class="pi-data-value pi-font">test value</div>
</div>
</section>
</aside>',
'description' => 'Infobox with title, collapsible group with header and two key-value pairs',
'mockParams' => [ ],
'accentColor' => '',
'accentColorText' => ''
],
[
'input' => [
[
'type' => 'title',
'data' => [
'value' => 'Test Title'
]
],
[
'type' => 'group',
'data' => [
'value' => [
[
'type' => 'header',
'data' => [
'value' => 'Test Header'
]
],
[
'type' => 'data',
'data' => [
'label' => 'test label',
'value' => 'test value'
]
],
[
'type' => 'data',
'data' => [
'label' => 'test label',
'value' => 'test value'
]
]
],
'layout' => 'default',
'collapse' => 'closed',
'row-items' => null
]
]
],
'output' => '<aside class="portable-infobox pi-background">
<h2 class="pi-item pi-item-spacing pi-title">Test Title</h2>
<section class="pi-item pi-group pi-border-color pi-collapse pi-collapse-closed">
<h2 class="pi-item pi-header pi-secondary-font pi-item-spacing pi-secondary-background">Test Header</h2>
<div class="pi-item pi-data pi-item-spacing pi-border-color">
<h3 class="pi-data-label pi-secondary-font">test label</h3>
<div class="pi-data-value pi-font">test value</div>
</div>
<div class="pi-item pi-data pi-item-spacing pi-border-color">
<h3 class="pi-data-label pi-secondary-font">test label</h3>
<div class="pi-data-value pi-font">test value</div>
</div>
</section>
</aside>',
'description' => 'Infobox with title, collapsed group with header and two key-value pairs',
'mockParams' => [ ],
'accentColor' => '',
'accentColorText' => ''
]
]; ];
} }
} }
class DummyPIImageHelper { class DummyPIImageHelper {
static $imageData = []; static $imageData = [];
private $ref = 1;
public function extendImageData( $imageData ) { public function extendImageData( $imageData ) {
return self::$imageData; $data = self::$imageData;
$data['ref'] = $this->ref++;
return $data;
}
public function extendImageCollectionData( $images ) {
$images[0]['isFirst'] = true;
return [
'images' => $images
];
} }
} }

View file

@ -288,6 +288,7 @@ class NodeDataTest extends MediaWikiTestCase {
/** /**
* @covers PortableInfobox\Parser\Nodes\Node::getMetadata * @covers PortableInfobox\Parser\Nodes\Node::getMetadata
* @covers PortableInfobox\Parser\Nodes\NodeInfobox::getMetadata
* @dataProvider metadataDataProvider * @dataProvider metadataDataProvider
* *
* @param $markup * @param $markup
@ -512,6 +513,8 @@ class NodeDataTest extends MediaWikiTestCase {
/** /**
* @covers PortableInfobox\Parser\Nodes\Node::getRenderData * @covers PortableInfobox\Parser\Nodes\Node::getRenderData
* @covers PortableInfobox\Parser\Nodes\NodeData::getLayout
* @covers PortableInfobox\Parser\Nodes\NodeData::getSpan
* @dataProvider dataRenderProvider * @dataProvider dataRenderProvider
* *
* @param $markup * @param $markup

View file

@ -0,0 +1,58 @@
<?php
use PortableInfobox\Parser\Nodes\NodeFactory;
/**
* @group PortableInfobox
* @covers PortableInfobox\Parser\Nodes\NodeFactory
*/
class NodeFactoryTest extends MediaWikiTestCase {
/**
* @dataProvider newFromXMLProvider
* @param $markup
* @param $expected
* @throws PortableInfobox\Parser\XmlMarkupParseErrorException
*/
public function testNewFromXML( $markup, $expected ) {
$node = NodeFactory::newFromXML( $markup, [] );
$this->assertEquals( $expected, get_class( $node ) );
}
/**
* @dataProvider newFromXMLProvider
* @param $markup
* @param $expected
* @throws PortableInfobox\Parser\XmlMarkupParseErrorException
*/
public function testNewFromSimpleXml( $markup, $expected ) {
$xmlObj = PortableInfobox\Parser\XmlParser::parseXmlString( $markup );
$node = NodeFactory::newFromSimpleXml( $xmlObj, [] );
$this->assertEquals( $expected, get_class( $node ) );
}
public function newFromXMLProvider() {
return [
[
'<infobox />',
PortableInfobox\Parser\Nodes\NodeInfobox::class
],
[
'<data />',
PortableInfobox\Parser\Nodes\NodeData::class
],
[
'<MEDIA />',
PortableInfobox\Parser\Nodes\NodeMedia::class
],
[
'<image><default></default><othertag></othertag></image>',
PortableInfobox\Parser\Nodes\NodeImage::class
],
[
'<idonotexist />',
PortableInfobox\Parser\Nodes\NodeUnimplemented::class
]
];
}
}

View file

@ -0,0 +1,31 @@
<?php
/**
* @group PortableInfobox
* @covers PortableInfobox\Parser\Nodes\NodeHeader
*/
class NodeHeaderTest extends MediaWikiTestCase {
/**
* @covers PortableInfobox\Parser\Nodes\NodeHeader::getData
* @covers PortableInfobox\Parser\Nodes\Node::getInnerValue
* @dataProvider dataProvider
*
* @param $markup
* @param $params
* @param $expected
*/
public function testData( $markup, $params, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getData() );
}
public function dataProvider() {
return [
[ '<header></header>', [ ], [ 'value' => '' ] ],
[ '<header>kjdflkja dafkjlsdkfj</header>', [ ], [ 'value' => 'kjdflkja dafkjlsdkfj' ] ],
[ '<header>kjdflkja<ref>dafkjlsdkfj</ref></header>', [ ], [ 'value' => 'kjdflkja<ref>dafkjlsdkfj</ref>' ] ],
];
}
}

View file

@ -18,11 +18,13 @@ class NodeMediaTest extends MediaWikiTestCase {
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::getGalleryData * @covers PortableInfobox\Parser\Nodes\NodeMedia::getGalleryData
* @covers PortableInfobox\Helpers\PortableInfoboxDataBag
* @dataProvider galleryDataProvider * @dataProvider galleryDataProvider
* @param $marker * @param $marker
* @param $expected * @param $expected
*/ */
public function testGalleryData( $marker, $expected ) { public function testGalleryData( $marker, $gallery, $expected ) {
PortableInfoboxDataBag::getInstance()->setGallery( $marker, $gallery );
$this->assertEquals( $expected, NodeMedia::getGalleryData( $marker ) ); $this->assertEquals( $expected, NodeMedia::getGalleryData( $marker ) );
} }
@ -32,29 +34,30 @@ class NodeMediaTest extends MediaWikiTestCase {
"'\"`UNIQabcd-gAlLeRy-2-QINU`\"'", "'\"`UNIQabcd-gAlLeRy-2-QINU`\"'",
"'\"`UNIQabcd-gAlLeRy-3-QINU`\"'" "'\"`UNIQabcd-gAlLeRy-3-QINU`\"'"
]; ];
PortableInfoboxDataBag::getInstance()->setGallery( $markers[0], $galleries = [
new GalleryMock([ new GalleryMock([
[ [
'image0_name.jpg', 'image0_name.jpg',
'image0_caption' 'image0_caption'
], ],
[ [
'image01_name.jpg', 'image01_name.jpg',
'image01_caption' 'image01_caption'
], ],
])); ]),
PortableInfoboxDataBag::getInstance()->setGallery( $markers[1], new GalleryMock([
new GalleryMock([ [
[ 'image1_name.jpg',
'image1_name.jpg', 'image1_caption'
'image1_caption' ]
] ]),
])); new GalleryMock()
PortableInfoboxDataBag::getInstance()->setGallery( $markers[2], new GalleryMock() ); ];
return [ return [
[ [
'marker' => $markers[0], 'marker' => $markers[0],
'gallery' => $galleries[0],
'expected' => [ 'expected' => [
[ [
'label' => 'image0_caption', 'label' => 'image0_caption',
@ -68,6 +71,7 @@ class NodeMediaTest extends MediaWikiTestCase {
], ],
[ [
'marker' => $markers[1], 'marker' => $markers[1],
'gallery' => $galleries[1],
'expected' => [ 'expected' => [
[ [
'label' => 'image1_caption', 'label' => 'image1_caption',
@ -77,6 +81,7 @@ class NodeMediaTest extends MediaWikiTestCase {
], ],
[ [
'marker' => $markers[2], 'marker' => $markers[2],
'gallery' => $galleries[2],
'expected' => [] 'expected' => []
], ],
]; ];
@ -84,6 +89,7 @@ class NodeMediaTest extends MediaWikiTestCase {
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::getTabberData * @covers PortableInfobox\Parser\Nodes\NodeMedia::getTabberData
* @covers PortableInfobox\Helpers\HtmlHelper
*/ */
public function testTabberData() { public function testTabberData() {
$input = '<div class="tabber"><div class="tabbertab" title="_title_"><p><a><img src="_src_"></a></p></div></div>'; $input = '<div class="tabber"><div class="tabbertab" title="_title_"><p><a><img src="_src_"></a></p></div></div>';
@ -207,7 +213,7 @@ class NodeMediaTest extends MediaWikiTestCase {
* @param $expected * @param $expected
*/ */
public function testSources( $markup, $expected ) { public function testSources( $markup, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [ ] ); $node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [] );
$this->assertEquals( $expected, $node->getSources() ); $this->assertEquals( $expected, $node->getSources() );
} }
@ -242,7 +248,7 @@ class NodeMediaTest extends MediaWikiTestCase {
/** @dataProvider metadataProvider */ /** @dataProvider metadataProvider */
public function testMetadata( $markup, $expected ) { public function testMetadata( $markup, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [ ] ); $node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [] );
$this->assertEquals( $expected, $node->getMetadata() ); $this->assertEquals( $expected, $node->getMetadata() );
} }
@ -271,8 +277,8 @@ class NodeMediaTest extends MediaWikiTestCase {
$videoMock = new VideoMock(); $videoMock = new VideoMock();
$xmlObj = PortableInfobox\Parser\XmlParser::parseXmlString( $markup ); $xmlObj = PortableInfobox\Parser\XmlParser::parseXmlString( $markup );
$mock = $this->getMock(NodeMedia::class, [ 'getFilefromTitle' ], [ $xmlObj, $params ]); $mock = $this->getMock( NodeMedia::class, [ 'getFilefromTitle' ], [ $xmlObj, $params ] );
$mock->expects( $this->any( )) $mock->expects( $this->any() )
->method( 'getFilefromTitle' ) ->method( 'getFilefromTitle' )
->willReturn( $videoMock ); ->willReturn( $videoMock );
@ -312,8 +318,8 @@ class NodeMediaTest extends MediaWikiTestCase {
$audioMock = new AudioMock(); $audioMock = new AudioMock();
$xmlObj = PortableInfobox\Parser\XmlParser::parseXmlString( $markup ); $xmlObj = PortableInfobox\Parser\XmlParser::parseXmlString( $markup );
$mock = $this->getMock(NodeMedia::class, [ 'getFilefromTitle' ], [ $xmlObj, $params ]); $mock = $this->getMock( NodeMedia::class, [ 'getFilefromTitle' ], [ $xmlObj, $params ] );
$mock->expects( $this->any( )) $mock->expects( $this->any() )
->method( 'getFilefromTitle' ) ->method( 'getFilefromTitle' )
->willReturn( $audioMock ); ->willReturn( $audioMock );
@ -341,6 +347,71 @@ class NodeMediaTest extends MediaWikiTestCase {
] ]
]; ];
} }
/**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::isTypeAllowed
* @covers PortableInfobox\Parser\Nodes\NodeAudio
* @covers PortableInfobox\Parser\Nodes\NodeImage
* @covers PortableInfobox\Parser\Nodes\NodeVideo
* @dataProvider isTypeAllowedProvider
* @param $markup
* @param $expected
* @throws PortableInfobox\Parser\XmlMarkupParseErrorException
*/
public function testIsTypeAllowed( $markup, $expected ) {
$types = [ MEDIATYPE_BITMAP, MEDIATYPE_DRAWING, MEDIATYPE_VIDEO, MEDIATYPE_AUDIO, 'unknown' ];
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [] );
$reflection = new ReflectionClass( $node );
$reflection_method = $reflection->getMethod( 'isTypeAllowed' );
$reflection_method->setAccessible( true );
foreach ( $types as $i => $type ) {
$this->assertEquals( $expected[$i], $reflection_method->invoke( $node, $type ) );
}
}
public function isTypeAllowedProvider() {
return [
[
'<media />',
[ true, true, true, true, false ]
],
[
'<media image="false" />',
[ false, false, true, true, false ]
],
[
'<media video="false" />',
[ true, true, false, true, false ]
],
[
'<media audio="false" />',
[ true, true, true, false, false ]
],
[
'<media image="false" video="false" audio="false" />',
[ false, false, false, false, false ]
],
[
'<image />',
[ true, true, true, false, false ]
],
[
'<image video="false" />',
[ true, true, false, false, false ]
],
[
'<video />',
[ false, false, true, false, false ]
],
[
'<audio />',
[ false, false, false, true, false ]
]
];
}
} }
class ImageMock { class ImageMock {

View file

@ -0,0 +1,46 @@
<?php
/**
* @group PortableInfobox
* @covers PortableInfobox\Parser\Nodes\NodeTitle
*/
class NodeTitleTest extends MediaWikiTestCase {
/**
* @covers PortableInfobox\Parser\Nodes\NodeTitle::getData
* @dataProvider dataProvider
*
* @param $markup
* @param $params
* @param $expected
*/
public function testData( $markup, $params, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getData() );
}
public function dataProvider() {
return [
[ '<title source="test"/>', [ 'test' => 'test' ], [ 'value' => 'test' ] ],
[ '<title source="test"><default>def</default></title>', [ ], [ 'value' => 'def' ] ],
[ '<title source="test"><default>def</default></title>', [ ],
[ 'value' => 'def' ] ],
[ '<title source="test"><default>def</default></title>', [ 'l' => 1 ],
[ 'value' => 'def' ] ],
[ '<title source="test"><default>def</default></title>', [ 'l' => 1 ],
[ 'value' => 'def' ] ],
[ '<title source="test"><default>def</default></title>', [ 'test' => 1 ],
[ 'value' => 1 ] ],
[ '<title></title>', [ ], [ 'value' => null ] ],
[ '<title source="test"><format>{{{test}}}%</format><default>def</default></title>', [ 'test' => 1 ],
[ 'value' => '{{{test}}}%' ] ],
[ '<title source="test"><format>{{{not_defined_var}}}%</format><default>def</default></title>', [ 'test' => 1 ],
[ 'value' => '{{{not_defined_var}}}%' ] ],
[ '<title source="test"><format>{{{test}}}%</format><default>def</default></title>', [ ],
[ 'value' => 'def' ] ],
[ '<title source="test"><format>{{{test}}}%</format></title>', [ 'test' => 0 ],
[ 'value' => '{{{test}}}%' ] ],
];
}
}

View file

@ -0,0 +1,20 @@
<?php
use PortableInfobox\Parser\Nodes\NodeUnimplemented;
/**
* @group PortableInfobox
* @covers PortableInfobox\Parser\Nodes\NodeUnimplemented
*/
class NodeUnimplementedTest extends MediaWikiTestCase {
/**
* @expectedException PortableInfobox\Parser\Nodes\UnimplementedNodeException
*/
public function testNewFromXML() {
( new NodeUnimplemented(
PortableInfobox\Parser\XmlParser::parseXmlString( "<foo/>" ),
[]
) )->getData();
}
}

View file

@ -5,6 +5,7 @@ use PortableInfobox\Sanitizers\NodeDataSanitizer;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Sanitizers\NodeSanitizer
* @covers PortableInfobox\Sanitizers\NodeDataSanitizer * @covers PortableInfobox\Sanitizers\NodeDataSanitizer
*/ */
class NodeDataSanitizerTest extends MediaWikiTestCase { class NodeDataSanitizerTest extends MediaWikiTestCase {

View file

@ -5,6 +5,7 @@ use PortableInfobox\Sanitizers\NodeHorizontalGroupSanitizer;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Sanitizers\NodeSanitizer
* @covers PortableInfobox\Sanitizers\NodeHorizontalGroupSanitizer * @covers PortableInfobox\Sanitizers\NodeHorizontalGroupSanitizer
*/ */
class NodeHorizontalGroupSanitizerTest extends MediaWikiTestCase { class NodeHorizontalGroupSanitizerTest extends MediaWikiTestCase {

View file

@ -5,6 +5,7 @@ use PortableInfobox\Sanitizers\NodeImageSanitizer;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Sanitizers\NodeSanitizer
* @covers PortableInfobox\Sanitizers\NodeImageSanitizer * @covers PortableInfobox\Sanitizers\NodeImageSanitizer
*/ */
class NodeImageSanitizerTest extends MediaWikiTestCase { class NodeImageSanitizerTest extends MediaWikiTestCase {

View file

@ -5,6 +5,7 @@ use PortableInfobox\Sanitizers\NodeTitleSanitizer;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Sanitizers\NodeSanitizer
* @covers PortableInfobox\Sanitizers\NodeTitleSanitizer * @covers PortableInfobox\Sanitizers\NodeTitleSanitizer
*/ */
class NodeTitleSanitizerTest extends MediaWikiTestCase { class NodeTitleSanitizerTest extends MediaWikiTestCase {

View file

@ -5,6 +5,7 @@ use PortableInfobox\Sanitizers\PassThroughSanitizer;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Sanitizers\NodeSanitizer
* @covers PortableInfobox\Sanitizers\PassThroughSanitizer * @covers PortableInfobox\Sanitizers\PassThroughSanitizer
*/ */
class PassThroughSanitizerTest extends MediaWikiTestCase { class PassThroughSanitizerTest extends MediaWikiTestCase {

View file

@ -0,0 +1,44 @@
<?php
use PortableInfobox\Sanitizers\SanitizerBuilder;
/**
* @group PortableInfobox
* @covers PortableInfobox\Sanitizers\SanitizerBuilder
*/
class SanitizerBuilderTest extends MediaWikiTestCase {
/**
* @param $type
* @param $expected
* @dataProvider createFromTypeProvide
*/
public function testCreateFromType( $type, $expected ) {
$this->assertType( $expected, SanitizerBuilder::createFromType( $type ) );
}
public function createFromTypeProvide() {
return [
[
'data',
PortableInfobox\Sanitizers\NodeDataSanitizer::class
],
[
'horizontal-group-content',
PortableInfobox\Sanitizers\NodeHorizontalGroupSanitizer::class
],
[
'title',
PortableInfobox\Sanitizers\NodeTitleSanitizer::class
],
[
'image',
PortableInfobox\Sanitizers\NodeImageSanitizer::class
],
[
'unknown',
PortableInfobox\Sanitizers\PassThroughSanitizer::class
],
];
}
}