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
/vendor
.github/*

View file

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

View file

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

View file

@ -3,7 +3,9 @@
use MediaWiki\MediaWikiServices;
use PortableInfobox\Helpers\InfoboxParamsValidator;
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\XmlMarkupParseErrorException;
@ -89,14 +91,14 @@ class PortableInfoboxParserTagController {
*/
public function prepareInfobox( $markup, Parser $parser, PPFrame $frame, $params = null ) {
$frameArguments = $frame->getArguments();
$infoboxNode = Nodes\NodeFactory::newFromXML( $markup, $frameArguments ?: [] );
$infoboxNode = NodeFactory::newFromXML( $markup, $frameArguments ?: [] );
$infoboxNode->setExternalParser(
new PortableInfobox\Parser\MediaWikiParserService( $parser, $frame )
new MediaWikiParserService( $parser, $frame )
);
// get params if not overridden
if ( !isset( $params ) ) {
$params = ( $infoboxNode instanceof Nodes\NodeInfobox ) ? $infoboxNode->getParams() : [];
$params = ( $infoboxNode instanceof NodeInfobox ) ? $infoboxNode->getParams() : [];
}
$this->getParamsValidator()->validateParams( $params );
@ -148,7 +150,7 @@ class PortableInfoboxParserTagController {
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,
// therefore we can reuse the data in data provider service
// (see: PortableInfoboxDataService.class.php)

View file

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

View file

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

View file

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

View file

@ -2,7 +2,9 @@
namespace PortableInfobox\Helpers;
use File;
use MediaWiki\MediaWikiServices;
use Title;
class PortableInfoboxImagesHelper {
private const MAX_DESKTOP_THUMBNAIL_HEIGHT = 500;
@ -10,7 +12,7 @@ class PortableInfoboxImagesHelper {
/**
* extends image data
*
* @param \File|\Title|string $file image
* @param File|Title|string $file image
* @param int $thumbnailFileWidth preferred thumbnail file width
* @param int|null $thumbnailImgTagWidth preferred thumbnail img tag width
* @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
* of this variable
*
* @param \File|\Title|string $file
* @return \File|null file
* @param File|Title|string $file
* @return File|null file
*/
public function getFile( $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();
$file = $repoGroup->findFile( $file );
}
if ( $file instanceof \File && $file->exists() ) {
if ( $file instanceof File && $file->exists() ) {
return $file;
}

View file

@ -2,8 +2,14 @@
namespace PortableInfobox\Helpers;
use Exception;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use ParserOptions;
use PortableInfoboxDataService;
use PortableInfoboxParserTagController;
use RequestContext;
use Title;
class PortableInfoboxParsingHelper {
@ -11,25 +17,25 @@ class PortableInfoboxParsingHelper {
protected $logger;
public function __construct() {
$this->parserTagController = \PortableInfoboxParserTagController::getInstance();
$this->parserTagController = PortableInfoboxParserTagController::getInstance();
$this->logger = LoggerFactory::getInstance( 'PortableInfobox' );
}
/**
* 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
*/
public function parseIncludeonlyInfoboxes( \Title $title ) {
public function parseIncludeonlyInfoboxes( Title $title ) {
// for templates we need to check for include tags
$templateText = $this->fetchArticleContent( $title );
if ( $templateText ) {
$parser = MediaWikiServices::getInstance()->getParser();
$parser->setPage( $title );
$parserOptions = \ParserOptions::newFromAnon();
$parserOptions = ParserOptions::newFromAnon();
$parser->setOptions( $parserOptions );
$frame = $parser->getPreprocessor()->newFrame();
@ -40,13 +46,13 @@ class PortableInfoboxParsingHelper {
foreach ( $infoboxes as $infobox ) {
try {
$this->parserTagController->prepareInfobox( $infobox, $parser, $frame );
} catch ( \Exception $e ) {
} catch ( Exception $e ) {
$this->logger->info( 'Invalid infobox syntax' );
}
}
return json_decode(
$parser->getOutput()->getProperty( \PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ),
$parser->getOutput()->getProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ),
true
);
}
@ -54,25 +60,25 @@ class PortableInfoboxParsingHelper {
return false;
}
public function reparseArticle( \Title $title ) {
public function reparseArticle( Title $title ) {
$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 );
return json_decode(
$parser->getOutput()->getProperty( \PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ),
$parser->getOutput()->getProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ),
true
);
}
/**
* @param \Title $title
* @param Title $title
*
* @return string
*/
protected function fetchArticleContent( \Title $title ) {
protected function fetchArticleContent( Title $title ) {
if ( $title->exists() ) {
// @phan-suppress-next-line PhanDeprecatedFunction
$content = MediaWikiServices::getInstance()
@ -86,10 +92,10 @@ class PortableInfoboxParsingHelper {
}
/**
* @param \Title $title
* @param Title $title
* @return string[] array of strings (infobox markups)
*/
public function getMarkup( \Title $title ) {
public function getMarkup( Title $title ) {
$content = $this->fetchArticleContent( $title );
return $this->getInfoboxes( $content );
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +1,10 @@
<?php
namespace PortableInfobox\Parser;
use Exception;
use MediaWiki\Logger\LoggerFactory;
use SimpleXMLElement;
class XmlParser {
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
*
* @return \SimpleXMLElement
* @return SimpleXMLElement
* @throws XmlMarkupParseErrorException
*/
public static function parseXmlString( $xmlString, &$errors = [] ) {
@ -62,7 +65,7 @@ class XmlParser {
}
// phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound
class XmlMarkupParseErrorException extends \Exception {
class XmlMarkupParseErrorException extends Exception {
private $errors;
public function __construct( $errors ) {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -4,16 +4,18 @@ use PortableInfobox\Helpers\PortableInfoboxDataBag;
use PortableInfobox\Helpers\PortableInfoboxImagesHelper;
use PortableInfobox\Parser\Nodes\NodeFactory;
use PortableInfobox\Parser\Nodes\NodeMedia;
use PortableInfobox\Parser\XmlMarkupParseErrorException;
/**
* @group PortableInfobox
* @covers PortableInfobox\Parser\Nodes\NodeMedia
* @covers \PortableInfobox\Parser\Nodes\NodeMedia
* @coversDefaultClass \PortableInfobox\Parser\Nodes\NodeMedia
*/
class NodeMediaTest extends MediaWikiIntegrationTestCase {
/**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::getGalleryData
* @covers PortableInfobox\Helpers\PortableInfoboxDataBag
* @covers ::getGalleryData
* @covers \PortableInfobox\Helpers\PortableInfoboxDataBag
* @dataProvider galleryDataProvider
* @param $marker
* @param $expected
@ -83,7 +85,7 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase {
}
/**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::getTabberData
* @covers ::getTabberData
*/
public function testTabberData() {
$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
* @param $ext
* @param $value
@ -131,7 +133,7 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase {
}
/**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::getData
* @covers ::getData
* @dataProvider dataProvider
*
* @param $markup
@ -298,7 +300,7 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase {
}
/**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::isEmpty
* @covers ::isEmpty
* @dataProvider isEmptyProvider
*
* @param $markup
@ -318,7 +320,7 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase {
}
/**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::getSources
* @covers ::getSources
* @dataProvider sourcesProvider
*
* @param $markup
@ -388,19 +390,19 @@ class NodeMediaTest extends MediaWikiIntegrationTestCase {
}
/**
* @covers PortableInfobox\Parser\Nodes\NodeMedia::isTypeAllowed
* @covers PortableInfobox\Parser\Nodes\NodeAudio
* @covers PortableInfobox\Parser\Nodes\NodeImage
* @covers PortableInfobox\Parser\Nodes\NodeVideo
* @covers ::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
* @throws XmlMarkupParseErrorException
*/
public function testIsTypeAllowed( $markup, $expected ) {
$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_method = $reflection->getMethod( 'isTypeAllowed' );

View file

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

View file

@ -1,12 +1,16 @@
<?php
use PortableInfobox\Parser\Nodes\NodeFactory;
/**
* @group PortableInfobox
* @covers PortableInfobox\Parser\Nodes\NodeTitle
* @covers \PortableInfobox\Parser\Nodes\NodeTitle
* @coversDefaultClass \PortableInfobox\Parser\Nodes\NodeTitle
*/
class NodeTitleTest extends MediaWikiIntegrationTestCase {
/**
* @covers PortableInfobox\Parser\Nodes\NodeTitle::getData
* @covers ::getData
* @dataProvider dataProvider
*
* @param $markup
@ -14,7 +18,7 @@ class NodeTitleTest extends MediaWikiIntegrationTestCase {
* @param $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() );
}

View file

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