Add use statements (#64)

This commit is contained in:
Universal Omega 2022-03-11 13:35:51 -07:00 committed by GitHub
parent 08339c7acf
commit 44c3389d5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 277 additions and 171 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/composer.lock /composer.lock
/vendor /vendor
.github/*

View file

@ -2,6 +2,7 @@
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RenderedRevision; use MediaWiki\Revision\RenderedRevision;
use PortableInfobox\Helpers\PortableInfoboxDataBag;
class PortableInfoboxHooks { class PortableInfoboxHooks {
@ -14,7 +15,7 @@ class PortableInfoboxHooks {
public static function onBeforeParserrenderImageGallery( public static function onBeforeParserrenderImageGallery(
Parser &$parser, ImageGalleryBase &$gallery Parser &$parser, ImageGalleryBase &$gallery
) { ) {
PortableInfobox\Helpers\PortableInfoboxDataBag::getInstance()->setGallery( PortableInfoboxDataBag::getInstance()->setGallery(
// @phan-suppress-next-line PhanDeprecatedProperty // @phan-suppress-next-line PhanDeprecatedProperty
Parser::MARKER_PREFIX . '-gallery-' . sprintf( '%08X', $parser->mMarkerIndex - 1 ) . Parser::MARKER_PREFIX . '-gallery-' . sprintf( '%08X', $parser->mMarkerIndex - 1 ) .
Parser::MARKER_SUFFIX, Parser::MARKER_SUFFIX,

View file

@ -1,6 +1,9 @@
<?php <?php
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use PortableInfobox\Helpers\InvalidInfoboxParamsException;
use PortableInfobox\Parser\Nodes\UnimplementedNodeException;
use PortableInfobox\Parser\XmlMarkupParseErrorException;
use Wikimedia\ParamValidator\ParamValidator; use Wikimedia\ParamValidator\ParamValidator;
class ApiPortableInfobox extends ApiBase { class ApiPortableInfobox extends ApiBase {
@ -36,14 +39,14 @@ class ApiPortableInfobox extends ApiBase {
try { try {
$output = PortableInfoboxParserTagController::getInstance()->render( $text, $parser, $frame ); $output = PortableInfoboxParserTagController::getInstance()->render( $text, $parser, $frame );
$this->getResult()->addValue( null, $this->getModuleName(), [ 'text' => [ '*' => $output ] ] ); $this->getResult()->addValue( null, $this->getModuleName(), [ 'text' => [ '*' => $output ] ] );
} catch ( \PortableInfobox\Parser\Nodes\UnimplementedNodeException $e ) { } catch ( UnimplementedNodeException $e ) {
$this->dieWithError( $this->dieWithError(
$this->msg( 'portable-infobox-unimplemented-infobox-tag', [ $e->getMessage() ] )->escaped(), $this->msg( 'portable-infobox-unimplemented-infobox-tag', [ $e->getMessage() ] )->escaped(),
'notimplemented' 'notimplemented'
); );
} catch ( \PortableInfobox\Parser\XmlMarkupParseErrorException $e ) { } catch ( XmlMarkupParseErrorException $e ) {
$this->dieWithError( $this->msg( 'portable-infobox-xml-parse-error' )->text(), 'badxml' ); $this->dieWithError( $this->msg( 'portable-infobox-xml-parse-error' )->text(), 'badxml' );
} catch ( \PortableInfobox\Helpers\InvalidInfoboxParamsException $e ) { } catch ( InvalidInfoboxParamsException $e ) {
$this->dieWithError( $this->dieWithError(
$this->msg( $this->msg(
'portable-infobox-xml-parse-error-infobox-tag-attribute-unsupported', 'portable-infobox-xml-parse-error-infobox-tag-attribute-unsupported',

View file

@ -3,7 +3,9 @@
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use PortableInfobox\Helpers\InfoboxParamsValidator; use PortableInfobox\Helpers\InfoboxParamsValidator;
use PortableInfobox\Helpers\InvalidInfoboxParamsException; use PortableInfobox\Helpers\InvalidInfoboxParamsException;
use PortableInfobox\Parser\Nodes; use PortableInfobox\Parser\MediaWikiParserService;
use PortableInfobox\Parser\Nodes\NodeFactory;
use PortableInfobox\Parser\Nodes\NodeInfobox;
use PortableInfobox\Parser\Nodes\UnimplementedNodeException; use PortableInfobox\Parser\Nodes\UnimplementedNodeException;
use PortableInfobox\Parser\XmlMarkupParseErrorException; use PortableInfobox\Parser\XmlMarkupParseErrorException;
@ -89,14 +91,14 @@ class PortableInfoboxParserTagController {
*/ */
public function prepareInfobox( $markup, Parser $parser, PPFrame $frame, $params = null ) { public function prepareInfobox( $markup, Parser $parser, PPFrame $frame, $params = null ) {
$frameArguments = $frame->getArguments(); $frameArguments = $frame->getArguments();
$infoboxNode = Nodes\NodeFactory::newFromXML( $markup, $frameArguments ?: [] ); $infoboxNode = NodeFactory::newFromXML( $markup, $frameArguments ?: [] );
$infoboxNode->setExternalParser( $infoboxNode->setExternalParser(
new PortableInfobox\Parser\MediaWikiParserService( $parser, $frame ) new MediaWikiParserService( $parser, $frame )
); );
// get params if not overridden // get params if not overridden
if ( !isset( $params ) ) { if ( !isset( $params ) ) {
$params = ( $infoboxNode instanceof Nodes\NodeInfobox ) ? $infoboxNode->getParams() : []; $params = ( $infoboxNode instanceof NodeInfobox ) ? $infoboxNode->getParams() : [];
} }
$this->getParamsValidator()->validateParams( $params ); $this->getParamsValidator()->validateParams( $params );
@ -148,7 +150,7 @@ class PortableInfoboxParserTagController {
return [ $renderedValue, 'markerType' => 'nowiki' ]; return [ $renderedValue, 'markerType' => 'nowiki' ];
} }
protected function saveToParserOutput( \ParserOutput $parserOutput, Nodes\NodeInfobox $raw ) { protected function saveToParserOutput( ParserOutput $parserOutput, NodeInfobox $raw ) {
// parser output stores this in page_props table, // parser output stores this in page_props table,
// therefore we can reuse the data in data provider service // therefore we can reuse the data in data provider service
// (see: PortableInfoboxDataService.class.php) // (see: PortableInfoboxDataService.class.php)

View file

@ -2,6 +2,7 @@
namespace PortableInfobox\Helpers; namespace PortableInfobox\Helpers;
use Language;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
// original class & authors: // original class & authors:
@ -25,7 +26,7 @@ class FileNamespaceSanitizeHelper {
} }
/** /**
* @param \Language $contLang * @param Language $contLang
* Used as local cache for getting string to remove * Used as local cache for getting string to remove
*/ */
private function getFilePrefixRegex( $contLang ) { private function getFilePrefixRegex( $contLang ) {
@ -65,7 +66,7 @@ class FileNamespaceSanitizeHelper {
/** /**
* @param string $filename * @param string $filename
* @param \Language $contLang * @param Language $contLang
* *
* @return mixed * @return mixed
*/ */

View file

@ -1,6 +1,9 @@
<?php <?php
namespace PortableInfobox\Helpers; namespace PortableInfobox\Helpers;
use Exception;
class InfoboxParamsValidator { class InfoboxParamsValidator {
private static $supportedParams = [ private static $supportedParams = [
'accent-color-default', 'accent-color-default',
@ -240,5 +243,5 @@ class InfoboxParamsValidator {
} }
// phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound // phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound
class InvalidInfoboxParamsException extends \Exception { class InvalidInfoboxParamsException extends Exception {
} }

View file

@ -2,10 +2,6 @@
namespace PortableInfobox\Helpers; namespace PortableInfobox\Helpers;
/**
* Class PortableInfoboxDataBag
* @package PortableInfobox\Helpers
*/
class PortableInfoboxDataBag { class PortableInfoboxDataBag {
private static $instance = null; private static $instance = null;
private $galleries = []; private $galleries = [];

View file

@ -2,7 +2,9 @@
namespace PortableInfobox\Helpers; namespace PortableInfobox\Helpers;
use File;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use Title;
class PortableInfoboxImagesHelper { class PortableInfoboxImagesHelper {
private const MAX_DESKTOP_THUMBNAIL_HEIGHT = 500; private const MAX_DESKTOP_THUMBNAIL_HEIGHT = 500;
@ -10,7 +12,7 @@ class PortableInfoboxImagesHelper {
/** /**
* extends image data * extends image data
* *
* @param \File|\Title|string $file image * @param File|Title|string $file image
* @param int $thumbnailFileWidth preferred thumbnail file width * @param int $thumbnailFileWidth preferred thumbnail file width
* @param int|null $thumbnailImgTagWidth preferred thumbnail img tag width * @param int|null $thumbnailImgTagWidth preferred thumbnail img tag width
* @return array|bool false on failure * @return array|bool false on failure
@ -116,21 +118,21 @@ class PortableInfoboxImagesHelper {
* Note: this method turns a string $file into an object, affecting the calling code version * Note: this method turns a string $file into an object, affecting the calling code version
* of this variable * of this variable
* *
* @param \File|\Title|string $file * @param File|Title|string $file
* @return \File|null file * @return File|null file
*/ */
public function getFile( $file ) { public function getFile( $file ) {
if ( is_string( $file ) ) { if ( is_string( $file ) ) {
$file = \Title::newFromText( $file, NS_FILE ); $file = Title::newFromText( $file, NS_FILE );
} }
if ( $file instanceof \Title ) { if ( $file instanceof Title ) {
$repoGroup = MediaWikiServices::getInstance()->getRepoGroup(); $repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
$file = $repoGroup->findFile( $file ); $file = $repoGroup->findFile( $file );
} }
if ( $file instanceof \File && $file->exists() ) { if ( $file instanceof File && $file->exists() ) {
return $file; return $file;
} }

View file

@ -2,8 +2,14 @@
namespace PortableInfobox\Helpers; namespace PortableInfobox\Helpers;
use Exception;
use MediaWiki\Logger\LoggerFactory; use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use ParserOptions;
use PortableInfoboxDataService;
use PortableInfoboxParserTagController;
use RequestContext;
use Title;
class PortableInfoboxParsingHelper { class PortableInfoboxParsingHelper {
@ -11,25 +17,25 @@ class PortableInfoboxParsingHelper {
protected $logger; protected $logger;
public function __construct() { public function __construct() {
$this->parserTagController = \PortableInfoboxParserTagController::getInstance(); $this->parserTagController = PortableInfoboxParserTagController::getInstance();
$this->logger = LoggerFactory::getInstance( 'PortableInfobox' ); $this->logger = LoggerFactory::getInstance( 'PortableInfobox' );
} }
/** /**
* Try to find out if infobox got "hidden" inside includeonly tag. Parse it if that's the case. * Try to find out if infobox got "hidden" inside includeonly tag. Parse it if that's the case.
* *
* @param \Title $title * @param Title $title
* *
* @return mixed false when no infoboxes found, Array with infoboxes on success * @return mixed false when no infoboxes found, Array with infoboxes on success
*/ */
public function parseIncludeonlyInfoboxes( \Title $title ) { public function parseIncludeonlyInfoboxes( Title $title ) {
// for templates we need to check for include tags // for templates we need to check for include tags
$templateText = $this->fetchArticleContent( $title ); $templateText = $this->fetchArticleContent( $title );
if ( $templateText ) { if ( $templateText ) {
$parser = MediaWikiServices::getInstance()->getParser(); $parser = MediaWikiServices::getInstance()->getParser();
$parser->setPage( $title ); $parser->setPage( $title );
$parserOptions = \ParserOptions::newFromAnon(); $parserOptions = ParserOptions::newFromAnon();
$parser->setOptions( $parserOptions ); $parser->setOptions( $parserOptions );
$frame = $parser->getPreprocessor()->newFrame(); $frame = $parser->getPreprocessor()->newFrame();
@ -40,13 +46,13 @@ class PortableInfoboxParsingHelper {
foreach ( $infoboxes as $infobox ) { foreach ( $infoboxes as $infobox ) {
try { try {
$this->parserTagController->prepareInfobox( $infobox, $parser, $frame ); $this->parserTagController->prepareInfobox( $infobox, $parser, $frame );
} catch ( \Exception $e ) { } catch ( Exception $e ) {
$this->logger->info( 'Invalid infobox syntax' ); $this->logger->info( 'Invalid infobox syntax' );
} }
} }
return json_decode( return json_decode(
$parser->getOutput()->getProperty( \PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), $parser->getOutput()->getProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ),
true true
); );
} }
@ -54,25 +60,25 @@ class PortableInfoboxParsingHelper {
return false; return false;
} }
public function reparseArticle( \Title $title ) { public function reparseArticle( Title $title ) {
$parser = MediaWikiServices::getInstance()->getParser(); $parser = MediaWikiServices::getInstance()->getParser();
$user = \RequestContext::getMain()->getUser(); $user = RequestContext::getMain()->getUser();
$parserOptions = new \ParserOptions( $user ); $parserOptions = new ParserOptions( $user );
$parser->parse( $this->fetchArticleContent( $title ), $title, $parserOptions ); $parser->parse( $this->fetchArticleContent( $title ), $title, $parserOptions );
return json_decode( return json_decode(
$parser->getOutput()->getProperty( \PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), $parser->getOutput()->getProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ),
true true
); );
} }
/** /**
* @param \Title $title * @param Title $title
* *
* @return string * @return string
*/ */
protected function fetchArticleContent( \Title $title ) { protected function fetchArticleContent( Title $title ) {
if ( $title->exists() ) { if ( $title->exists() ) {
// @phan-suppress-next-line PhanDeprecatedFunction // @phan-suppress-next-line PhanDeprecatedFunction
$content = MediaWikiServices::getInstance() $content = MediaWikiServices::getInstance()
@ -86,10 +92,10 @@ class PortableInfoboxParsingHelper {
} }
/** /**
* @param \Title $title * @param Title $title
* @return string[] array of strings (infobox markups) * @return string[] array of strings (infobox markups)
*/ */
public function getMarkup( \Title $title ) { public function getMarkup( Title $title ) {
$content = $this->fetchArticleContent( $title ); $content = $this->fetchArticleContent( $title );
return $this->getInfoboxes( $content ); return $this->getInfoboxes( $content );
} }

View file

@ -2,8 +2,11 @@
namespace PortableInfobox\Helpers; namespace PortableInfobox\Helpers;
use Closure;
use LightnCandy\LightnCandy;
use MediaWiki\Logger\LoggerFactory; use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use PortableInfoboxParserTagController;
class PortableInfoboxTemplateEngine { class PortableInfoboxTemplateEngine {
private const CACHE_TTL = 86400; private const CACHE_TTL = 86400;
@ -31,7 +34,7 @@ class PortableInfoboxTemplateEngine {
public function __construct() { public function __construct() {
if ( !isset( self::$lightncandy ) ) { if ( !isset( self::$lightncandy ) ) {
self::$lightncandy = \LightnCandy\LightnCandy::class; self::$lightncandy = LightnCandy::class;
self::$compileFlags = self::$lightncandy::FLAG_BESTPERFORMANCE | self::$lightncandy::FLAG_PARENT | self::$lightncandy::FLAG_HANDLEBARS; self::$compileFlags = self::$lightncandy::FLAG_BESTPERFORMANCE | self::$lightncandy::FLAG_PARENT | self::$lightncandy::FLAG_HANDLEBARS;
} }
@ -60,7 +63,7 @@ class PortableInfoboxTemplateEngine {
* Returns a template renderer * Returns a template renderer
* *
* @param string $type Template type * @param string $type Template type
* @return \Closure * @return Closure
*/ */
public function getRenderer( $type ) { public function getRenderer( $type ) {
global $wgPortableInfoboxCacheRenderers; global $wgPortableInfoboxCacheRenderers;
@ -70,7 +73,7 @@ class PortableInfoboxTemplateEngine {
if ( $wgPortableInfoboxCacheRenderers ) { if ( $wgPortableInfoboxCacheRenderers ) {
$cachekey = self::$memcache->makeKey( $cachekey = self::$memcache->makeKey(
__CLASS__, \PortableInfoboxParserTagController::PARSER_TAG_VERSION, $type __CLASS__, PortableInfoboxParserTagController::PARSER_TAG_VERSION, $type
); );
$template = self::$memcache->getWithSetCallback( $template = self::$memcache->getWithSetCallback(
$cachekey, self::CACHE_TTL, static function () use ( $path ) { $cachekey, self::CACHE_TTL, static function () use ( $path ) {

View file

@ -1,4 +1,5 @@
<?php <?php
namespace PortableInfobox\Parser; namespace PortableInfobox\Parser;
interface ExternalParser { interface ExternalParser {

View file

@ -2,7 +2,13 @@
namespace PortableInfobox\Parser; namespace PortableInfobox\Parser;
use BlockLevelPass;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use MediaWiki\Tidy\RemexDriver;
use PageImages\Hooks\ParserFileProcessingHookHandlers;
use Parser;
use PPFrame;
use Title;
class MediaWikiParserService implements ExternalParser { class MediaWikiParserService implements ExternalParser {
@ -12,13 +18,13 @@ class MediaWikiParserService implements ExternalParser {
protected $tidyDriver; protected $tidyDriver;
protected $cache = []; protected $cache = [];
public function __construct( \Parser $parser, \PPFrame $frame ) { public function __construct( Parser $parser, PPFrame $frame ) {
global $wgPortableInfoboxUseTidy; global $wgPortableInfoboxUseTidy;
$this->parser = $parser; $this->parser = $parser;
$this->frame = $frame; $this->frame = $frame;
if ( $wgPortableInfoboxUseTidy && class_exists( '\MediaWiki\Tidy\RemexDriver' ) ) { if ( $wgPortableInfoboxUseTidy && class_exists( RemexDriver::class ) ) {
global $wgTidyConfig; global $wgTidyConfig;
$wgTidyConfig = [ $wgTidyConfig = [
@ -49,7 +55,7 @@ class MediaWikiParserService implements ExternalParser {
} }
// @phan-suppress-next-line PhanAccessMethodInternal // @phan-suppress-next-line PhanAccessMethodInternal
$output = \BlockLevelPass::doBlockLevels( $parsed, false ); $output = BlockLevelPass::doBlockLevels( $parsed, false );
$ready = $this->parser->getStripState()->unstripBoth( $output ); $ready = $this->parser->getStripState()->unstripBoth( $output );
// @phan-suppress-next-line PhanDeprecatedFunction // @phan-suppress-next-line PhanDeprecatedFunction
@ -76,7 +82,7 @@ class MediaWikiParserService implements ExternalParser {
/** /**
* Add image to parser output for later usage * Add image to parser output for later usage
* *
* @param \Title $title * @param Title $title
*/ */
public function addImage( $title ) { public function addImage( $title ) {
$repoGroup = MediaWikiServices::getInstance()->getRepoGroup(); $repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
@ -87,11 +93,11 @@ class MediaWikiParserService implements ExternalParser {
$this->parser->getOutput()->addImage( $title->getDBkey(), $tmstmp, $sha1 ); $this->parser->getOutput()->addImage( $title->getDBkey(), $tmstmp, $sha1 );
// Pass PI images to PageImages extension if available (Popups and og:image) // Pass PI images to PageImages extension if available (Popups and og:image)
if ( \method_exists( if ( method_exists(
'\PageImages\Hooks\ParserFileProcessingHookHandlers', 'onParserMakeImageParams' ParserFileProcessingHookHandlers::class, 'onParserMakeImageParams'
) ) { ) ) {
$params = []; $params = [];
\PageImages\Hooks\ParserFileProcessingHookHandlers::onParserMakeImageParams( ParserFileProcessingHookHandlers::onParserMakeImageParams(
$title, $file, $params, $this->parser $title, $file, $params, $this->parser
); );
} }

View file

@ -1,8 +1,11 @@
<?php <?php
namespace PortableInfobox\Parser\Nodes; namespace PortableInfobox\Parser\Nodes;
use PortableInfobox\Parser\ExternalParser; use PortableInfobox\Parser\ExternalParser;
use PortableInfobox\Parser\SimpleParser; use PortableInfobox\Parser\SimpleParser;
use Sanitizer;
use SimpleXMLElement;
class Node { class Node {
@ -26,7 +29,7 @@ class Node {
*/ */
protected $externalParser; protected $externalParser;
public function __construct( \SimpleXMLElement $xmlNode, $infoboxData ) { public function __construct( SimpleXMLElement $xmlNode, $infoboxData ) {
$this->xmlNode = $xmlNode; $this->xmlNode = $xmlNode;
$this->infoboxData = $infoboxData; $this->infoboxData = $infoboxData;
} }
@ -43,7 +46,7 @@ class Node {
$metadata = []; $metadata = [];
$sources = $this->getSources(); $sources = $this->getSources();
$sourcesLength = count( $sources ); $sourcesLength = count( $sources );
$baseLabel = \Sanitizer::stripAllTags( $baseLabel = Sanitizer::stripAllTags(
$this->getInnerValue( $this->xmlNode->{self::LABEL_TAG_NAME} ) $this->getInnerValue( $this->xmlNode->{self::LABEL_TAG_NAME} )
); );
@ -196,7 +199,7 @@ class Node {
}, $this->getChildNodes() ); }, $this->getChildNodes() );
} }
protected function getValueWithDefault( \SimpleXMLElement $xmlNode ) { protected function getValueWithDefault( SimpleXMLElement $xmlNode ) {
$value = $this->extractDataFromSource( $xmlNode ); $value = $this->extractDataFromSource( $xmlNode );
$isEmpty = $value === null || $value === ''; $isEmpty = $value === null || $value === '';
if ( $isEmpty && $xmlNode->{self::DEFAULT_TAG_NAME} ) { if ( $isEmpty && $xmlNode->{self::DEFAULT_TAG_NAME} ) {
@ -209,7 +212,7 @@ class Node {
return $value; return $value;
} }
protected function getRawValueWithDefault( \SimpleXMLElement $xmlNode ) { protected function getRawValueWithDefault( SimpleXMLElement $xmlNode ) {
$value = $this->getRawInfoboxData( $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ) ); $value = $this->getRawInfoboxData( $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ) );
if ( !$value && $xmlNode->{self::DEFAULT_TAG_NAME} ) { if ( !$value && $xmlNode->{self::DEFAULT_TAG_NAME} ) {
$value = $this->getExternalParser()->replaceVariables( $value = $this->getExternalParser()->replaceVariables(
@ -220,17 +223,17 @@ class Node {
return $value; return $value;
} }
protected function getValueWithData( \SimpleXMLElement $xmlNode ) { protected function getValueWithData( SimpleXMLElement $xmlNode ) {
$value = $this->extractDataFromSource( $xmlNode ); $value = $this->extractDataFromSource( $xmlNode );
return $value ?: $this->getInnerValue( $xmlNode ); return $value ?: $this->getInnerValue( $xmlNode );
} }
protected function getInnerValue( \SimpleXMLElement $xmlNode ) { protected function getInnerValue( SimpleXMLElement $xmlNode ) {
return $this->getExternalParser()->parseRecursive( (string)$xmlNode ); return $this->getExternalParser()->parseRecursive( (string)$xmlNode );
} }
protected function getXmlAttribute( \SimpleXMLElement $xmlNode, $attribute ) { protected function getXmlAttribute( SimpleXMLElement $xmlNode, $attribute ) {
return ( isset( $xmlNode[$attribute] ) ) ? (string)$xmlNode[$attribute] return ( isset( $xmlNode[$attribute] ) ) ? (string)$xmlNode[$attribute]
: null; : null;
} }
@ -244,11 +247,11 @@ class Node {
} }
/** /**
* @param \SimpleXMLElement $xmlNode * @param SimpleXMLElement $xmlNode
* *
* @return mixed * @return mixed
*/ */
protected function extractDataFromSource( \SimpleXMLElement $xmlNode ) { protected function extractDataFromSource( SimpleXMLElement $xmlNode ) {
$source = $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ); $source = $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME );
return ( !empty( $source ) || $source == '0' ) ? $this->getInfoboxData( $source ) return ( !empty( $source ) || $source == '0' ) ? $this->getInfoboxData( $source )
@ -256,11 +259,11 @@ class Node {
} }
/** /**
* @param \SimpleXMLElement $xmlNode * @param SimpleXMLElement $xmlNode
* *
* @return array * @return array
*/ */
protected function extractSourcesFromNode( \SimpleXMLElement $xmlNode ) { protected function extractSourcesFromNode( SimpleXMLElement $xmlNode ) {
$sources = $this->hasPrimarySource( $xmlNode ) ? $sources = $this->hasPrimarySource( $xmlNode ) ?
[ $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ) ] : []; [ $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ) ] : [];
@ -274,11 +277,11 @@ class Node {
return $sources; return $sources;
} }
protected function hasPrimarySource( \SimpleXMLElement $xmlNode ) { protected function hasPrimarySource( SimpleXMLElement $xmlNode ) {
return (bool)$this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ); return (bool)$this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME );
} }
protected function matchVariables( \SimpleXMLElement $node, array $source ) { protected function matchVariables( SimpleXMLElement $node, array $source ) {
preg_match_all( self::EXTRACT_SOURCE_REGEX, (string)$node, $sources ); preg_match_all( self::EXTRACT_SOURCE_REGEX, (string)$node, $sources );
return array_unique( array_merge( $source, $sources[1] ) ); return array_unique( array_merge( $source, $sources[1] ) );

View file

@ -1,4 +1,5 @@
<?php <?php
namespace PortableInfobox\Parser\Nodes; namespace PortableInfobox\Parser\Nodes;
class NodeAudio extends NodeMedia { class NodeAudio extends NodeMedia {

View file

@ -1,4 +1,5 @@
<?php <?php
namespace PortableInfobox\Parser\Nodes; namespace PortableInfobox\Parser\Nodes;
class NodeData extends Node { class NodeData extends Node {

View file

@ -1,7 +1,9 @@
<?php <?php
namespace PortableInfobox\Parser\Nodes; namespace PortableInfobox\Parser\Nodes;
use PortableInfobox\Parser\XmlParser; use PortableInfobox\Parser\XmlParser;
use SimpleXMLElement;
class NodeFactory { class NodeFactory {
@ -9,22 +11,21 @@ class NodeFactory {
return self::getInstance( XmlParser::parseXmlString( $text ), $data ); return self::getInstance( XmlParser::parseXmlString( $text ), $data );
} }
public static function newFromSimpleXml( \SimpleXMLElement $xmlNode, array $data = [] ) { public static function newFromSimpleXml( SimpleXMLElement $xmlNode, array $data = [] ) {
return self::getInstance( $xmlNode, $data ); return self::getInstance( $xmlNode, $data );
} }
/** /**
* @param \SimpleXMLElement $xmlNode * @param SimpleXMLElement $xmlNode
* @param array $data * @param array $data
* *
* @return Node|NodeUnimplemented * @return Node|NodeUnimplemented
*/ */
protected static function getInstance( \SimpleXMLElement $xmlNode, array $data ) { protected static function getInstance( SimpleXMLElement $xmlNode, array $data ) {
$tagType = $xmlNode->getName(); $tagType = $xmlNode->getName();
$className = 'PortableInfobox\\Parser\\Nodes\\' . 'Node' . $className = Node::class . mb_convert_case( mb_strtolower( $tagType ), MB_CASE_TITLE );
mb_convert_case( mb_strtolower( $tagType ), MB_CASE_TITLE );
if ( class_exists( $className ) ) { if ( class_exists( $className ) ) {
/* @var $instance \PortableInfobox\Parser\Nodes\Node */ /* @var $instance Node */
$instance = new $className( $xmlNode, $data ); $instance = new $className( $xmlNode, $data );
if ( $instance instanceof Node ) { if ( $instance instanceof Node ) {

View file

@ -1,4 +1,5 @@
<?php <?php
namespace PortableInfobox\Parser\Nodes; namespace PortableInfobox\Parser\Nodes;
class NodeGroup extends Node { class NodeGroup extends Node {

View file

@ -1,4 +1,5 @@
<?php <?php
namespace PortableInfobox\Parser\Nodes; namespace PortableInfobox\Parser\Nodes;
class NodeHeader extends Node { class NodeHeader extends Node {

View file

@ -1,4 +1,5 @@
<?php <?php
namespace PortableInfobox\Parser\Nodes; namespace PortableInfobox\Parser\Nodes;
class NodeImage extends NodeMedia { class NodeImage extends NodeMedia {

View file

@ -1,4 +1,5 @@
<?php <?php
namespace PortableInfobox\Parser\Nodes; namespace PortableInfobox\Parser\Nodes;
class NodeInfobox extends Node { class NodeInfobox extends Node {

View file

@ -2,10 +2,16 @@
namespace PortableInfobox\Parser\Nodes; namespace PortableInfobox\Parser\Nodes;
use DOMDocument;
use DOMXpath;
use File;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use Parser;
use PortableInfobox\Helpers\FileNamespaceSanitizeHelper; use PortableInfobox\Helpers\FileNamespaceSanitizeHelper;
use PortableInfobox\Helpers\PortableInfoboxDataBag; use PortableInfobox\Helpers\PortableInfoboxDataBag;
use PortableInfobox\Helpers\PortableInfoboxImagesHelper; use PortableInfobox\Helpers\PortableInfoboxImagesHelper;
use PortableInfoboxRenderService;
use Title;
class NodeMedia extends Node { class NodeMedia extends Node {
private const GALLERY = 'GALLERY'; private const GALLERY = 'GALLERY';
@ -21,7 +27,7 @@ class NodeMedia extends Node {
private $helper; private $helper;
public static function getMarkers( $value, $ext ) { public static function getMarkers( $value, $ext ) {
$regex = '/' . \Parser::MARKER_PREFIX . "-$ext-[A-F0-9]{8}" . \Parser::MARKER_SUFFIX . '/i'; $regex = '/' . Parser::MARKER_PREFIX . "-$ext-[A-F0-9]{8}" . Parser::MARKER_SUFFIX . '/i';
if ( preg_match_all( $regex, $value, $out ) ) { if ( preg_match_all( $regex, $value, $out ) ) {
return $out[0]; return $out[0];
} else { } else {
@ -42,7 +48,7 @@ class NodeMedia extends Node {
public static function getTabberData( $html ) { public static function getTabberData( $html ) {
$data = []; $data = [];
$doc = new \DOMDocument(); $doc = new DOMDocument();
$libXmlErrorSetting = libxml_use_internal_errors( true ); $libXmlErrorSetting = libxml_use_internal_errors( true );
// encode for correct load // encode for correct load
@ -51,7 +57,7 @@ class NodeMedia extends Node {
libxml_clear_errors(); libxml_clear_errors();
libxml_use_internal_errors( $libXmlErrorSetting ); libxml_use_internal_errors( $libXmlErrorSetting );
$xpath = new \DOMXpath( $doc ); $xpath = new DOMXpath( $doc );
$divs = $xpath->query( '//div[@class=\'tabbertab\']' ); $divs = $xpath->query( '//div[@class=\'tabbertab\']' );
foreach ( $divs as $div ) { foreach ( $divs as $div ) {
if ( preg_match( '# src="(?:[^"]*/)?(?:\d+px-)?([^"]*?)"#', $doc->saveXml( $div ), $out ) ) { if ( preg_match( '# src="(?:[^"]*/)?(?:\d+px-)?([^"]*?)"#', $doc->saveXml( $div ), $out ) ) {
@ -137,14 +143,14 @@ class NodeMedia extends Node {
*/ */
private function getImageData( $title, $alt, $caption ) { private function getImageData( $title, $alt, $caption ) {
$helper = $this->getImageHelper(); $helper = $this->getImageHelper();
$titleObj = $title instanceof \Title ? $title : $this->getImageAsTitleObject( $title ); $titleObj = $title instanceof Title ? $title : $this->getImageAsTitleObject( $title );
$fileObj = $helper->getFile( $titleObj ); $fileObj = $helper->getFile( $titleObj );
if ( !isset( $fileObj ) || !$this->isTypeAllowed( $fileObj->getMediaType() ) ) { if ( !isset( $fileObj ) || !$this->isTypeAllowed( $fileObj->getMediaType() ) ) {
return []; return [];
} }
if ( $titleObj instanceof \Title ) { if ( $titleObj instanceof Title ) {
$this->getExternalParser()->addImage( $titleObj ); $this->getExternalParser()->addImage( $titleObj );
} }
@ -164,8 +170,8 @@ class NodeMedia extends Node {
if ( $image['isImage'] ) { if ( $image['isImage'] ) {
$image = array_merge( $image, $helper->extendImageData( $image = array_merge( $image, $helper->extendImageData(
$fileObj, $fileObj,
\PortableInfoboxRenderService::DEFAULT_DESKTOP_THUMBNAIL_WIDTH, PortableInfoboxRenderService::DEFAULT_DESKTOP_THUMBNAIL_WIDTH,
\PortableInfoboxRenderService::DEFAULT_DESKTOP_INFOBOX_WIDTH PortableInfoboxRenderService::DEFAULT_DESKTOP_INFOBOX_WIDTH
) ); ) );
} }
@ -199,7 +205,7 @@ class NodeMedia extends Node {
private function getImageAsTitleObject( $imageName ) { private function getImageAsTitleObject( $imageName ) {
$contLang = MediaWikiServices::getInstance()->getContentLanguage(); $contLang = MediaWikiServices::getInstance()->getContentLanguage();
$title = \Title::makeTitleSafe( $title = Title::makeTitleSafe(
NS_FILE, NS_FILE,
FileNamespaceSanitizeHelper::getInstance()->sanitizeImageFileName( $imageName, $contLang ) FileNamespaceSanitizeHelper::getInstance()->sanitizeImageFileName( $imageName, $contLang )
); );
@ -216,7 +222,7 @@ class NodeMedia extends Node {
/** /**
* Returns image url for given image title * Returns image url for given image title
* @param \File|null $file * @param File|null $file
* @return string url or '' if image doesn't exist * @return string url or '' if image doesn't exist
*/ */
public function resolveImageUrl( $file ) { public function resolveImageUrl( $file ) {

View file

@ -1,4 +1,5 @@
<?php <?php
namespace PortableInfobox\Parser\Nodes; namespace PortableInfobox\Parser\Nodes;
class NodeNavigation extends Node { class NodeNavigation extends Node {

View file

@ -1,4 +1,5 @@
<?php <?php
namespace PortableInfobox\Parser\Nodes; namespace PortableInfobox\Parser\Nodes;
class NodePanel extends Node { class NodePanel extends Node {

View file

@ -1,4 +1,5 @@
<?php <?php
namespace PortableInfobox\Parser\Nodes; namespace PortableInfobox\Parser\Nodes;
class NodeSection extends Node { class NodeSection extends Node {

View file

@ -1,4 +1,5 @@
<?php <?php
namespace PortableInfobox\Parser\Nodes; namespace PortableInfobox\Parser\Nodes;
class NodeTitle extends Node { class NodeTitle extends Node {

View file

@ -1,6 +1,9 @@
<?php <?php
namespace PortableInfobox\Parser\Nodes; namespace PortableInfobox\Parser\Nodes;
use Exception;
class NodeUnimplemented extends Node { class NodeUnimplemented extends Node {
public function getData() { public function getData() {
@ -11,5 +14,5 @@ class NodeUnimplemented extends Node {
} }
// phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound // phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound
class UnimplementedNodeException extends \Exception { class UnimplementedNodeException extends Exception {
} }

View file

@ -1,4 +1,5 @@
<?php <?php
namespace PortableInfobox\Parser\Nodes; namespace PortableInfobox\Parser\Nodes;
class NodeVideo extends NodeMedia { class NodeVideo extends NodeMedia {

View file

@ -1,4 +1,5 @@
<?php <?php
namespace PortableInfobox\Parser; namespace PortableInfobox\Parser;
class SimpleParser implements ExternalParser { class SimpleParser implements ExternalParser {

View file

@ -1,7 +1,10 @@
<?php <?php
namespace PortableInfobox\Parser; namespace PortableInfobox\Parser;
use Exception;
use MediaWiki\Logger\LoggerFactory; use MediaWiki\Logger\LoggerFactory;
use SimpleXMLElement;
class XmlParser { class XmlParser {
protected static $contentTags = [ 'default', 'label', 'format', 'navigation', 'header' ]; protected static $contentTags = [ 'default', 'label', 'format', 'navigation', 'header' ];
@ -11,7 +14,7 @@ class XmlParser {
* *
* @param array &$errors this array will be filled with errors if any found * @param array &$errors this array will be filled with errors if any found
* *
* @return \SimpleXMLElement * @return SimpleXMLElement
* @throws XmlMarkupParseErrorException * @throws XmlMarkupParseErrorException
*/ */
public static function parseXmlString( $xmlString, &$errors = [] ) { public static function parseXmlString( $xmlString, &$errors = [] ) {
@ -62,7 +65,7 @@ class XmlParser {
} }
// phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound // phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound
class XmlMarkupParseErrorException extends \Exception { class XmlMarkupParseErrorException extends Exception {
private $errors; private $errors;
public function __construct( $errors ) { public function __construct( $errors ) {

View file

@ -22,7 +22,7 @@ class PortableInfoboxErrorRenderService {
77 => 'XML_ERR_TAG_NOT_FINISHED' 77 => 'XML_ERR_TAG_NOT_FINISHED'
]; ];
/* @var $templateEngine PortableInfobox\Helpers\PortableInfoboxTemplateEngine */ /* @var $templateEngine PortableInfoboxTemplateEngine */
private $templateEngine; private $templateEngine;
public function __construct( $errorList ) { public function __construct( $errorList ) {

View file

@ -1,5 +1,7 @@
<?php <?php
use OOUI\ProgressBarWidget;
class SpecialPortableInfoboxBuilder extends SpecialPage { class SpecialPortableInfoboxBuilder extends SpecialPage {
public function __construct() { public function __construct() {
$restriction = $this->getConfig()->get( 'NamespaceProtection' )[NS_TEMPLATE][0] ?? ''; $restriction = $this->getConfig()->get( 'NamespaceProtection' )[NS_TEMPLATE][0] ?? '';
@ -17,7 +19,7 @@ class SpecialPortableInfoboxBuilder extends SpecialPage {
$out->addModules( [ 'ext.PortableInfobox.styles', 'ext.PortableInfoboxBuilder' ] ); $out->addModules( [ 'ext.PortableInfobox.styles', 'ext.PortableInfoboxBuilder' ] );
$out->addHTML( $out->addHTML(
'<div id="mw-infoboxbuilder" data-title="' . str_replace( '"', '&quot;', $par ) . '">' . '<div id="mw-infoboxbuilder" data-title="' . str_replace( '"', '&quot;', $par ) . '">' .
new OOUI\ProgressBarWidget( [ 'progress' => false ] ) . new ProgressBarWidget( [ 'progress' => false ] ) .
'</div>' '</div>'
); );
} }

View file

@ -1,15 +1,19 @@
<?php <?php
use PortableInfobox\Helpers\InfoboxParamsValidator;
use PortableInfobox\Helpers\InvalidInfoboxParamsException;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Helpers\InfoboxParamsValidator * @covers \PortableInfobox\Helpers\InfoboxParamsValidator
*/ */
class InfoboxParamsValidatorTest extends MediaWikiIntegrationTestCase { class InfoboxParamsValidatorTest extends MediaWikiIntegrationTestCase {
/** @var PortableInfobox\Helpers\InfoboxParamsValidator $InfoboxParamsValidator */ /** @var InfoboxParamsValidator $InfoboxParamsValidator */
private $InfoboxParamsValidator; private $InfoboxParamsValidator;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$this->InfoboxParamsValidator = new PortableInfobox\Helpers\InfoboxParamsValidator(); $this->InfoboxParamsValidator = new InfoboxParamsValidator();
} }
protected function tearDown(): void { protected function tearDown(): void {
@ -22,7 +26,7 @@ class InfoboxParamsValidatorTest extends MediaWikiIntegrationTestCase {
* @dataProvider infoboxParamsFailValidationDataProvider * @dataProvider infoboxParamsFailValidationDataProvider
*/ */
public function testInfoboxParamsFailValidation( $params ) { public function testInfoboxParamsFailValidation( $params ) {
$this->expectException( PortableInfobox\Helpers\InvalidInfoboxParamsException::class ); $this->expectException( InvalidInfoboxParamsException::class );
$this->InfoboxParamsValidator->validateParams( $params ); $this->InfoboxParamsValidator->validateParams( $params );
} }

View file

@ -1,10 +1,11 @@
<?php <?php
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use PortableInfobox\Parser\MediaWikiParserService;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Parser\MediaWikiParserService * @covers \PortableInfobox\Parser\MediaWikiParserService
*/ */
class MediaWikiParserTest extends MediaWikiIntegrationTestCase { class MediaWikiParserTest extends MediaWikiIntegrationTestCase {
@ -41,7 +42,7 @@ class MediaWikiParserTest extends MediaWikiIntegrationTestCase {
public function testAsideTagPWrappedDuringParsing() { public function testAsideTagPWrappedDuringParsing() {
$aside = "<aside></aside>"; $aside = "<aside></aside>";
$result = \BlockLevelPass::doBlockLevels( $aside, true ); $result = BlockLevelPass::doBlockLevels( $aside, true );
$this->assertEquals( $aside, $result ); $this->assertEquals( $aside, $result );
} }
@ -54,7 +55,7 @@ class MediaWikiParserTest extends MediaWikiIntegrationTestCase {
*/ */
public function testWrapper( $wikitext, $params, $newline ) { public function testWrapper( $wikitext, $params, $newline ) {
$frame = $this->parser->getPreprocessor()->newCustomFrame( $params ); $frame = $this->parser->getPreprocessor()->newCustomFrame( $params );
$wrapper = new PortableInfobox\Parser\MediaWikiParserService( $this->parser, $frame ); $wrapper = new MediaWikiParserService( $this->parser, $frame );
$output = $wrapper->parseRecursive( $wikitext ); $output = $wrapper->parseRecursive( $wikitext );

View file

@ -2,6 +2,7 @@
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfoboxRenderService * @covers PortableInfoboxRenderService
* @coversDefaultClass PortableInfoboxRenderService
*/ */
class PortableInfoboxRenderServiceTest extends MediaWikiIntegrationTestCase { class PortableInfoboxRenderServiceTest extends MediaWikiIntegrationTestCase {
@ -23,8 +24,8 @@ class PortableInfoboxRenderServiceTest extends MediaWikiIntegrationTestCase {
} }
/** /**
* @covers PortableInfoboxRenderService::renderInfobox * @covers ::renderInfobox
* @covers PortableInfobox\Helpers\PortableInfoboxTemplateEngine * @covers \PortableInfobox\Helpers\PortableInfoboxTemplateEngine
* @param $input * @param $input
* @param $expectedOutput * @param $expectedOutput
* @param $description * @param $description

View file

@ -1,18 +1,22 @@
<?php <?php
use PortableInfobox\Helpers\PortableInfoboxTemplateEngine;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Helpers\PortableInfoboxTemplateEngine * @covers \PortableInfobox\Helpers\PortableInfoboxTemplateEngine
* @coversDefaultClass \PortableInfobox\Helpers\PortableInfoboxTemplateEngine
*/ */
class PortableInfoboxTemplateEngineTest extends MediaWikiIntegrationTestCase { class PortableInfoboxTemplateEngineTest extends MediaWikiIntegrationTestCase {
/** /**
* @covers PortableInfobox\Helpers\PortableInfoboxTemplateEngine::isSupportedType * @covers ::isSupportedType
* @dataProvider isTypeSupportedInTemplatesDataProvider * @dataProvider isTypeSupportedInTemplatesDataProvider
*/ */
public function testIsTypeSupportedInTemplates( $type, $result, $description ) { public function testIsTypeSupportedInTemplates( $type, $result, $description ) {
$this->assertEquals( $this->assertEquals(
$result, $result,
PortableInfobox\Helpers\PortableInfoboxTemplateEngine::isSupportedType( $type ), PortableInfoboxTemplateEngine::isSupportedType( $type ),
$description $description
); );
} }

View file

@ -1,14 +1,17 @@
<?php <?php
use PortableInfobox\Parser\XmlParser;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Parser\XmlParser * @covers \PortableInfobox\Parser\XmlParser
*/ */
class XmlParserTest extends MediaWikiIntegrationTestCase { class XmlParserTest extends MediaWikiIntegrationTestCase {
/** @dataProvider contentTagsDataProvider */ /** @dataProvider contentTagsDataProvider */
public function testXHTMLParsing( $tag, $content ) { public function testXHTMLParsing( $tag, $content ) {
$markup = "<data source=\"asdfd\"><{$tag}>{$content}</{$tag}></data>"; $markup = "<data source=\"asdfd\"><{$tag}>{$content}</{$tag}></data>";
$result = PortableInfobox\Parser\XmlParser::parseXmlString( $markup ); $result = XmlParser::parseXmlString( $markup );
$this->assertEquals( $content, (string)$result->{$tag} ); $this->assertEquals( $content, (string)$result->{$tag} );
} }
@ -25,7 +28,7 @@ class XmlParserTest extends MediaWikiIntegrationTestCase {
* @dataProvider entitiesTestDataProvider * @dataProvider entitiesTestDataProvider
*/ */
public function testHTMLEntities( $markup, $expectedResult ) { public function testHTMLEntities( $markup, $expectedResult ) {
$result = PortableInfobox\Parser\XmlParser::parseXmlString( $markup ); $result = XmlParser::parseXmlString( $markup );
$this->assertEquals( $expectedResult, $result[ 0 ] ); $this->assertEquals( $expectedResult, $result[ 0 ] );
} }

View file

@ -5,7 +5,7 @@ use PortableInfobox\Helpers\FileNamespaceSanitizeHelper;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Helpers\FileNamespaceSanitizeHelper * @covers \PortableInfobox\Helpers\FileNamespaceSanitizeHelper
*/ */
class FileNamespaceSanitizeHelperTest extends MediaWikiIntegrationTestCase { class FileNamespaceSanitizeHelperTest extends MediaWikiIntegrationTestCase {
/** @var FileNamespaceSanitizeHelper $fileNamespaceSanitizeHelper */ /** @var FileNamespaceSanitizeHelper $fileNamespaceSanitizeHelper */

View file

@ -4,7 +4,7 @@ use PortableInfobox\Helpers\PortableInfoboxImagesHelper;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Helpers\PortableInfoboxImagesHelper * @covers \PortableInfobox\Helpers\PortableInfoboxImagesHelper
*/ */
class PortableInfoboxImagesHelperTest extends MediaWikiIntegrationTestCase { class PortableInfoboxImagesHelperTest extends MediaWikiIntegrationTestCase {
private $helper; private $helper;

View file

@ -1,9 +1,11 @@
<?php <?php
use PortableInfobox\Helpers\PortableInfoboxParsingHelper;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @group Database * @group Database
* @covers PortableInfobox\Helpers\PortableInfoboxParsingHelper * @covers \PortableInfobox\Helpers\PortableInfoboxParsingHelper
*/ */
class PortableInfoboxParsingHelperTest extends MediaWikiIntegrationTestCase { class PortableInfoboxParsingHelperTest extends MediaWikiIntegrationTestCase {
@ -11,7 +13,7 @@ class PortableInfoboxParsingHelperTest extends MediaWikiIntegrationTestCase {
* @dataProvider parsingIncludeonlyInfoboxesDataProvider * @dataProvider parsingIncludeonlyInfoboxesDataProvider
*/ */
public function testParsingIncludeonlyInfoboxes( $markup, $expected ) { public function testParsingIncludeonlyInfoboxes( $markup, $expected ) {
$helper = $this->getMockBuilder( PortableInfobox\Helpers\PortableInfoboxParsingHelper::class ) $helper = $this->getMockBuilder( PortableInfoboxParsingHelper::class )
->setMethods( [ 'fetchArticleContent' ] ) ->setMethods( [ 'fetchArticleContent' ] )
->getMock(); ->getMock();
$helper->expects( $this->once() ) $helper->expects( $this->once() )

View file

@ -1,12 +1,18 @@
<?php <?php
use PortableInfobox\Parser\Nodes\NodeData;
use PortableInfobox\Parser\Nodes\NodeFactory;
use PortableInfobox\Parser\SimpleParser;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Parser\Nodes\Node * @covers \PortableInfobox\Parser\Nodes\Node
* @coversDefaultClass \PortableInfobox\Parser\Nodes\Node
*/ */
class NodeDataTest extends MediaWikiIntegrationTestCase { class NodeDataTest extends MediaWikiIntegrationTestCase {
/** /**
* @covers PortableInfobox\Parser\Nodes\Node::getSources * @covers ::getSources
* @dataProvider sourceDataProvider * @dataProvider sourceDataProvider
* *
* @param $markup * @param $markup
@ -14,7 +20,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase {
* @param $expected * @param $expected
*/ */
public function testSource( $markup, $params, $expected ) { public function testSource( $markup, $params, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params ); $node = NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getSources() ); $this->assertEquals( $expected, $node->getSources() );
} }
@ -77,7 +83,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase {
} }
/** /**
* @covers PortableInfobox\Parser\Nodes\Node::getSourcesMetadata * @covers ::getSourcesMetadata
* @dataProvider sourcesMetadataDataProvider * @dataProvider sourcesMetadataDataProvider
* *
* @param $markup * @param $markup
@ -85,7 +91,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase {
* @param $expected * @param $expected
*/ */
public function testSourcesMetadata( $markup, $params, $expected ) { public function testSourcesMetadata( $markup, $params, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params ); $node = NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getSourcesMetadata() ); $this->assertEquals( $expected, $node->getSourcesMetadata() );
} }
@ -332,8 +338,8 @@ class NodeDataTest extends MediaWikiIntegrationTestCase {
} }
/** /**
* @covers PortableInfobox\Parser\Nodes\Node::getMetadata * @covers ::getMetadata
* @covers PortableInfobox\Parser\Nodes\NodeInfobox::getMetadata * @covers \PortableInfobox\Parser\Nodes\NodeInfobox::getMetadata
* @dataProvider metadataDataProvider * @dataProvider metadataDataProvider
* *
* @param $markup * @param $markup
@ -341,7 +347,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase {
* @param $expected * @param $expected
*/ */
public function testMetadata( $markup, $params, $expected ) { public function testMetadata( $markup, $params, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params ); $node = NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getMetadata() ); $this->assertEquals( $expected, $node->getMetadata() );
} }
@ -493,28 +499,28 @@ class NodeDataTest extends MediaWikiIntegrationTestCase {
} }
/** /**
* @covers PortableInfobox\Parser\Nodes\Node::getExternalParser * @covers ::getExternalParser
* @covers PortableInfobox\Parser\Nodes\Node::setExternalParser * @covers ::setExternalParser
* @dataProvider parserTestDataProvider * @dataProvider parserTestDataProvider
* *
* @param $parser * @param $parser
* @param $expected * @param $expected
*/ */
public function testExternalParserSetUp( $parser, $expected ) { public function testExternalParserSetUp( $parser, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( '<data></data>', [] ); $node = NodeFactory::newFromXML( '<data></data>', [] );
$this->assertEquals( $expected, $node->setExternalParser( $parser )->getExternalParser() ); $this->assertEquals( $expected, $node->setExternalParser( $parser )->getExternalParser() );
} }
public function parserTestDataProvider() { public function parserTestDataProvider() {
return [ return [
[ null, new PortableInfobox\Parser\SimpleParser() ], [ null, new SimpleParser() ],
[ new PortableInfobox\Parser\SimpleParser(), new PortableInfobox\Parser\SimpleParser() ] [ new SimpleParser(), new SimpleParser() ]
]; ];
} }
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeData::getData * @covers \PortableInfobox\Parser\Nodes\NodeData::getData
* @dataProvider dataProvider * @dataProvider dataProvider
* *
* @param $markup * @param $markup
@ -522,7 +528,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase {
* @param $expected * @param $expected
*/ */
public function testData( $markup, $params, $expected ) { public function testData( $markup, $params, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params ); $node = NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getData() ); $this->assertEquals( $expected, $node->getData() );
} }
@ -727,9 +733,9 @@ class NodeDataTest extends MediaWikiIntegrationTestCase {
} }
/** /**
* @covers PortableInfobox\Parser\Nodes\Node::getRenderData * @covers ::getRenderData
* @covers PortableInfobox\Parser\Nodes\NodeData::getLayout * @covers \PortableInfobox\Parser\Nodes\NodeData::getLayout
* @covers PortableInfobox\Parser\Nodes\NodeData::getSpan * @covers \PortableInfobox\Parser\Nodes\NodeData::getSpan
* @dataProvider dataRenderProvider * @dataProvider dataRenderProvider
* *
* @param $markup * @param $markup
@ -737,7 +743,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase {
* @param $expected * @param $expected
*/ */
public function testRenderData( $markup, $params, $expected ) { public function testRenderData( $markup, $params, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params ); $node = NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getRenderData() ); $this->assertEquals( $expected, $node->getRenderData() );
} }
@ -853,7 +859,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase {
} }
/** /**
* @covers PortableInfobox\Parser\Nodes\Node::isType * @covers ::isType
* @dataProvider isTypeDataProvider * @dataProvider isTypeDataProvider
* *
* @param $markup * @param $markup
@ -861,7 +867,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase {
* @param $expected * @param $expected
*/ */
public function testIsType( $markup, $typeToCheck, $expected ) { public function testIsType( $markup, $typeToCheck, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [] ); $node = NodeFactory::newFromXML( $markup, [] );
$this->assertEquals( $expected, $node->isType( $typeToCheck ) ); $this->assertEquals( $expected, $node->isType( $typeToCheck ) );
} }
@ -875,14 +881,14 @@ class NodeDataTest extends MediaWikiIntegrationTestCase {
} }
/** /**
* @covers PortableInfobox\Parser\Nodes\Node::getType * @covers ::getType
* @dataProvider typeDataProvider * @dataProvider typeDataProvider
* *
* @param $markup * @param $markup
* @param $expected * @param $expected
*/ */
public function testType( $markup, $expected ) { public function testType( $markup, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [] ); $node = NodeFactory::newFromXML( $markup, [] );
$this->assertEquals( $expected, $node->getType() ); $this->assertEquals( $expected, $node->getType() );
} }
@ -901,7 +907,7 @@ class NodeDataTest extends MediaWikiIntegrationTestCase {
$string = '<data source="season"><label>Season</label></data>'; $string = '<data source="season"><label>Season</label></data>';
$xml = simplexml_load_string( $string ); $xml = simplexml_load_string( $string );
$node = new PortableInfobox\Parser\Nodes\NodeData( $xml, [ 'season' => $season ] ); $node = new NodeData( $xml, [ 'season' => $season ] );
$nodeData = $node->getData(); $nodeData = $node->getData();
$this->assertTrue( $node->isEmpty( $nodeData ) == $expectedOutput ); $this->assertTrue( $node->isEmpty( $nodeData ) == $expectedOutput );
} }

View file

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

View file

@ -1,19 +1,23 @@
<?php <?php
use PortableInfobox\Parser\Nodes\NodeFactory;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Parser\Nodes\NodeGroup * @covers \PortableInfobox\Parser\Nodes\NodeGroup
* @coversDefaultClass \PortableInfobox\Parser\Nodes\NodeGroup
*/ */
class NodeGroupTest extends MediaWikiIntegrationTestCase { class NodeGroupTest extends MediaWikiIntegrationTestCase {
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeGroup::getData * @covers ::getData
* @dataProvider groupNodeCollapseTestProvider * @dataProvider groupNodeCollapseTestProvider
* *
* @param $markup * @param $markup
* @param $expected * @param $expected
*/ */
public function testNodeGroupCollapse( $markup, $expected ) { public function testNodeGroupCollapse( $markup, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup ); $node = NodeFactory::newFromXML( $markup );
$this->assertEquals( $expected, $node->getData()['collapse'] ); $this->assertEquals( $expected, $node->getData()['collapse'] );
} }
@ -27,15 +31,15 @@ class NodeGroupTest extends MediaWikiIntegrationTestCase {
} }
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeGroup::getData * @covers ::getData
* @covers PortableInfobox\Parser\Nodes\NodeGroup::getRenderData * @covers ::getRenderData
* @dataProvider groupNodeRowItemsTestProvider * @dataProvider groupNodeRowItemsTestProvider
* *
* @param $markup * @param $markup
* @param $expected * @param $expected
*/ */
public function testNodeGroupRowItems( $markup, $expected ) { public function testNodeGroupRowItems( $markup, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup ); $node = NodeFactory::newFromXML( $markup );
$this->assertEquals( $expected, $node->getData()['row-items'] ); $this->assertEquals( $expected, $node->getData()['row-items'] );
$this->assertEquals( $expected, $node->getRenderData()['data']['row-items'] ); $this->assertEquals( $expected, $node->getRenderData()['data']['row-items'] );
} }
@ -51,7 +55,7 @@ class NodeGroupTest extends MediaWikiIntegrationTestCase {
} }
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeGroup::getData * @covers ::getData
* @dataProvider groupNodeTestProvider * @dataProvider groupNodeTestProvider
* *
* @param $markup * @param $markup
@ -59,7 +63,7 @@ class NodeGroupTest extends MediaWikiIntegrationTestCase {
* @param $expected * @param $expected
*/ */
public function testNodeGroup( $markup, $params, $expected ) { public function testNodeGroup( $markup, $params, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params ); $node = NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getData() ); $this->assertEquals( $expected, $node->getData() );
} }

View file

@ -1,20 +1,24 @@
<?php <?php
use PortableInfobox\Parser\Nodes\NodeFactory;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Parser\Nodes\NodeHeader * @covers \PortableInfobox\Parser\Nodes\NodeHeader
* @coversDefaultClass \PortableInfobox\Parser\Nodes\NodeHeader
*/ */
class NodeHeaderTest extends MediaWikiIntegrationTestCase { class NodeHeaderTest extends MediaWikiIntegrationTestCase {
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeHeader::getData * @covers ::getData
* @covers PortableInfobox\Parser\Nodes\Node::getInnerValue * @covers \PortableInfobox\Parser\Nodes\Node::getInnerValue
* @dataProvider dataProvider * @dataProvider dataProvider
* *
* @param $markup * @param $markup
* @param $expected * @param $expected
*/ */
public function testData( $markup, $expected ) { public function testData( $markup, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup ); $node = NodeFactory::newFromXML( $markup );
$this->assertEquals( $expected, $node->getData() ); $this->assertEquals( $expected, $node->getData() );
} }

View file

@ -1,20 +1,23 @@
<?php <?php
use PortableInfobox\Parser\Nodes\NodeFactory;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Parser\Nodes\NodeInfobox * @covers \PortableInfobox\Parser\Nodes\NodeInfobox
* @coversDefaultClass \PortableInfobox\Parser\Nodes\NodeInfobox
*/ */
class NodeInfoboxTest extends MediaWikiIntegrationTestCase { class NodeInfoboxTest extends MediaWikiIntegrationTestCase {
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeInfobox::getParams * @covers ::getParams
* @dataProvider paramsProvider * @dataProvider paramsProvider
* *
* @param $markup * @param $markup
* @param $expected * @param $expected
*/ */
public function testParams( $markup, $expected ) { public function testParams( $markup, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [] ); $node = NodeFactory::newFromXML( $markup, [] );
$this->assertEquals( $expected, $node->getParams() ); $this->assertEquals( $expected, $node->getParams() );
} }

View file

@ -4,16 +4,18 @@ use PortableInfobox\Helpers\PortableInfoboxDataBag;
use PortableInfobox\Helpers\PortableInfoboxImagesHelper; use PortableInfobox\Helpers\PortableInfoboxImagesHelper;
use PortableInfobox\Parser\Nodes\NodeFactory; use PortableInfobox\Parser\Nodes\NodeFactory;
use PortableInfobox\Parser\Nodes\NodeMedia; use PortableInfobox\Parser\Nodes\NodeMedia;
use PortableInfobox\Parser\XmlMarkupParseErrorException;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Parser\Nodes\NodeMedia * @covers \PortableInfobox\Parser\Nodes\NodeMedia
* @coversDefaultClass \PortableInfobox\Parser\Nodes\NodeMedia
*/ */
class NodeMediaTest extends MediaWikiIntegrationTestCase { class NodeMediaTest extends MediaWikiIntegrationTestCase {
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::getGalleryData * @covers ::getGalleryData
* @covers PortableInfobox\Helpers\PortableInfoboxDataBag * @covers \PortableInfobox\Helpers\PortableInfoboxDataBag
* @dataProvider galleryDataProvider * @dataProvider galleryDataProvider
* @param $marker * @param $marker
* @param $expected * @param $expected
@ -83,7 +85,7 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase {
} }
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::getTabberData * @covers ::getTabberData
*/ */
public function testTabberData() { public function testTabberData() {
$input = '<div class="tabber"><div class="tabbertab" title="_title_">' . $input = '<div class="tabber"><div class="tabbertab" title="_title_">' .
@ -98,7 +100,7 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase {
} }
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::getMarkers * @covers ::getMarkers
* @dataProvider markersProvider * @dataProvider markersProvider
* @param $ext * @param $ext
* @param $value * @param $value
@ -131,7 +133,7 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase {
} }
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::getData * @covers ::getData
* @dataProvider dataProvider * @dataProvider dataProvider
* *
* @param $markup * @param $markup
@ -298,7 +300,7 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase {
} }
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::isEmpty * @covers ::isEmpty
* @dataProvider isEmptyProvider * @dataProvider isEmptyProvider
* *
* @param $markup * @param $markup
@ -318,7 +320,7 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase {
} }
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::getSources * @covers ::getSources
* @dataProvider sourcesProvider * @dataProvider sourcesProvider
* *
* @param $markup * @param $markup
@ -388,19 +390,19 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase {
} }
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::isTypeAllowed * @covers ::isTypeAllowed
* @covers PortableInfobox\Parser\Nodes\NodeAudio * @covers \PortableInfobox\Parser\Nodes\NodeAudio
* @covers PortableInfobox\Parser\Nodes\NodeImage * @covers \PortableInfobox\Parser\Nodes\NodeImage
* @covers PortableInfobox\Parser\Nodes\NodeVideo * @covers \PortableInfobox\Parser\Nodes\NodeVideo
* @dataProvider isTypeAllowedProvider * @dataProvider isTypeAllowedProvider
* @param $markup * @param $markup
* @param $expected * @param $expected
* @throws PortableInfobox\Parser\XmlMarkupParseErrorException * @throws XmlMarkupParseErrorException
*/ */
public function testIsTypeAllowed( $markup, $expected ) { public function testIsTypeAllowed( $markup, $expected ) {
$types = [ MEDIATYPE_BITMAP, MEDIATYPE_DRAWING, MEDIATYPE_VIDEO, MEDIATYPE_AUDIO, 'unknown' ]; $types = [ MEDIATYPE_BITMAP, MEDIATYPE_DRAWING, MEDIATYPE_VIDEO, MEDIATYPE_AUDIO, 'unknown' ];
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [] ); $node = NodeFactory::newFromXML( $markup, [] );
$reflection = new ReflectionClass( $node ); $reflection = new ReflectionClass( $node );
$reflection_method = $reflection->getMethod( 'isTypeAllowed' ); $reflection_method = $reflection->getMethod( 'isTypeAllowed' );

View file

@ -1,20 +1,24 @@
<?php <?php
use PortableInfobox\Parser\Nodes\NodeFactory;
use PortableInfobox\Parser\Nodes\NodeNavigation;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Parser\Nodes\NodeNavigation * @covers \PortableInfobox\Parser\Nodes\NodeNavigation
*/ */
class NodeNavigationTest extends MediaWikiIntegrationTestCase { class NodeNavigationTest extends MediaWikiIntegrationTestCase {
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeNavigation::getData * @covers \PortableInfobox\Parser\Nodes\NodeNavigation::getData
* @covers PortableInfobox\Parser\Nodes\Node::getInnerValue * @covers \PortableInfobox\Parser\Nodes\Node::getInnerValue
* @dataProvider dataProvider * @dataProvider dataProvider
* *
* @param $markup * @param $markup
* @param $expected * @param $expected
*/ */
public function testData( $markup, $expected ) { public function testData( $markup, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup ); $node = NodeFactory::newFromXML( $markup );
$this->assertEquals( $expected, $node->getData() ); $this->assertEquals( $expected, $node->getData() );
} }
@ -45,7 +49,7 @@ class NodeNavigationTest extends MediaWikiIntegrationTestCase {
*/ */
public function testIsEmpty( $string, $expectedOutput ) { public function testIsEmpty( $string, $expectedOutput ) {
$xml = simplexml_load_string( $string ); $xml = simplexml_load_string( $string );
$node = new PortableInfobox\Parser\Nodes\NodeNavigation( $xml, [] ); $node = new NodeNavigation( $xml, [] );
$data = $node->getData(); $data = $node->getData();
$this->assertTrue( $node->isEmpty( $data ) == $expectedOutput ); $this->assertTrue( $node->isEmpty( $data ) == $expectedOutput );
} }

View file

@ -1,12 +1,16 @@
<?php <?php
use PortableInfobox\Parser\Nodes\NodeFactory;
/** /**
* @group PortableInfobox * @group PortableInfobox
* @covers PortableInfobox\Parser\Nodes\NodeTitle * @covers \PortableInfobox\Parser\Nodes\NodeTitle
* @coversDefaultClass \PortableInfobox\Parser\Nodes\NodeTitle
*/ */
class NodeTitleTest extends MediaWikiIntegrationTestCase { class NodeTitleTest extends MediaWikiIntegrationTestCase {
/** /**
* @covers PortableInfobox\Parser\Nodes\NodeTitle::getData * @covers ::getData
* @dataProvider dataProvider * @dataProvider dataProvider
* *
* @param $markup * @param $markup
@ -14,7 +18,7 @@ class NodeTitleTest extends MediaWikiIntegrationTestCase {
* @param $expected * @param $expected
*/ */
public function testData( $markup, $params, $expected ) { public function testData( $markup, $params, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params ); $node = NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getData() ); $this->assertEquals( $expected, $node->getData() );
} }

View file

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