Port new data and infobox attributes (#16)

This commit is contained in:
lkucharczyk 2019-02-03 17:53:34 +01:00
commit 15f3b9e777
28 changed files with 862 additions and 240 deletions

View file

@ -13,6 +13,7 @@ class PortableInfoboxParserTagController {
const DEFAULT_LAYOUT_NAME = 'default';
const INFOBOX_THEME_PREFIX = 'pi-theme-';
const INFOBOX_LAYOUT_PREFIX = 'pi-layout-';
const INFOBOX_TYPE_PREFIX = 'pi-type-';
const ACCENT_COLOR = 'accent-color';
const ACCENT_COLOR_TEXT = 'accent-color-text';
const ERR_UNIMPLEMENTEDNODE = 'portable-infobox-unimplemented-infobox-tag';
@ -64,10 +65,12 @@ class PortableInfoboxParserTagController {
$layout = $this->getLayout( $params );
$accentColor = $this->getColor( self::ACCENT_COLOR, $params, $frame );
$accentColorText = $this->getColor( self::ACCENT_COLOR_TEXT, $params, $frame );
$type = $this->getType( $params );
$itemName = $this->getItemName( $params );
$renderService = new PortableInfoboxRenderService();
return $renderService->renderInfobox(
$data, implode( ' ', $themeList ), $layout, $accentColor, $accentColorText
$data, implode( ' ', $themeList ), $layout, $accentColor, $accentColorText, $type, $itemName
);
}
@ -235,6 +238,16 @@ class PortableInfoboxParserTagController {
return $color;
}
private function getType( $params ) {
return !empty( $params['type'] ) ? Sanitizer::escapeClass(
self::INFOBOX_TYPE_PREFIX . preg_replace( '|\s+|s', '-', $params['type'] )
) : '';
}
private function getItemName( $params ) {
return !empty( $params['name'] ) ? Sanitizer::encodeAttribute( $params['name'] ) : '';
}
private function sanitizeColor( $color ) {
return $this->getParamsValidator()->validateColorValue( $color );
}

View file

@ -10,6 +10,8 @@ class InfoboxParamsValidator {
'layout',
'theme',
'theme-source',
'type',
'name'
];
private static $supportedLayouts = [

View file

@ -7,6 +7,7 @@ use PortableInfobox\Parser\SimpleParser;
class Node {
const DATA_SRC_ATTR_NAME = 'source';
const NAME_ATTR_NAME = 'name';
const DEFAULT_TAG_NAME = 'default';
const FORMAT_TAG_NAME = 'format';
const LABEL_TAG_NAME = 'label';
@ -110,7 +111,11 @@ class Node {
public function getData() {
if ( !isset( $this->data ) ) {
$this->data = [ 'value' => (string)$this->xmlNode ];
$this->data = [
'value' => (string)$this->xmlNode,
'source' => $this->getPrimarySource(),
'item-name' => $this->getItemName()
];
}
return $this->data;
@ -277,4 +282,12 @@ class Node {
return array_unique( array_merge( $source, $sources[1] ) );
}
protected function getPrimarySource() {
return $this->getXmlAttribute( $this->xmlNode, self::DATA_SRC_ATTR_NAME );
}
protected function getItemName() {
return $this->getXmlAttribute( $this->xmlNode, self::NAME_ATTR_NAME );
}
}

View file

@ -14,7 +14,9 @@ class NodeData extends Node {
'label' => $this->getInnerValue( $this->xmlNode->{self::LABEL_TAG_NAME} ),
'value' => $this->getValueWithDefault( $this->xmlNode ),
'span' => $this->getSpan(),
'layout' => $this->getLayout()
'layout' => $this->getLayout(),
'source' => $this->getPrimarySource(),
'item-name' => $this->getItemName()
];
}

View file

@ -34,7 +34,8 @@ class NodeGroup extends Node {
'value' => $this->getDataForChildren(),
'layout' => $this->getLayout(),
'collapse' => $this->getCollapse(),
'row-items' => $this->getRowItems()
'row-items' => $this->getRowItems(),
'item-name' => $this->getItemName()
];
}
@ -57,7 +58,8 @@ class NodeGroup extends Node {
'value' => $value,
'layout' => $this->getLayout(),
'collapse' => $this->getCollapse(),
'row-items' => $this->getRowItems()
'row-items' => $this->getRowItems(),
'item-name' => $this->getItemName()
],
];
}

View file

@ -5,7 +5,10 @@ class NodeHeader extends Node {
public function getData() {
if ( !isset( $this->data ) ) {
$this->data = [ 'value' => $this->getInnerValue( $this->xmlNode ) ];
$this->data = [
'value' => $this->getInnerValue( $this->xmlNode ),
'item-name' => $this->getItemName()
];
}
return $this->data;

View file

@ -154,7 +154,9 @@ class NodeMedia extends Node {
'caption' => $caption ?: null,
'isImage' => in_array( $mediatype, [ MEDIATYPE_BITMAP, MEDIATYPE_DRAWING ] ),
'isVideo' => $mediatype === MEDIATYPE_VIDEO,
'isAudio' => $mediatype === MEDIATYPE_AUDIO
'isAudio' => $mediatype === MEDIATYPE_AUDIO,
'source' => $this->getPrimarySource(),
'item-name' => $this->getItemName()
];
if ( $image['isImage'] ) {

View file

@ -5,7 +5,10 @@ class NodeNavigation extends Node {
public function getData() {
if ( !isset( $this->data ) ) {
$this->data = [ 'value' => $this->getInnerValue( $this->xmlNode ) ];
$this->data = [
'value' => $this->getInnerValue( $this->xmlNode ),
'item-name' => $this->getItemName()
];
}
return $this->data;

View file

@ -5,7 +5,11 @@ class NodeTitle extends Node {
public function getData() {
if ( !isset( $this->data ) ) {
$title = $this->getValueWithDefault( $this->xmlNode );
$this->data = [ 'value' => $title ];
$this->data = [
'value' => $title,
'source' => $this->getXmlAttribute( $this->xmlNode, self::DATA_SRC_ATTR_NAME ),
'item-name' => $this->getItemName()
];
}
return $this->data;

View file

@ -23,10 +23,12 @@ class PortableInfoboxRenderService {
* @param string $layout
* @param string $accentColor
* @param string $accentColorText
* @param string $type
* @param string $itemName
* @return string - infobox HTML
*/
public function renderInfobox(
array $infoboxdata, $theme, $layout, $accentColor, $accentColorText
array $infoboxdata, $theme, $layout, $accentColor, $accentColorText, $type, $itemName
) {
$this->inlineStyles = $this->getInlineStyles( $accentColor, $accentColorText );
@ -36,7 +38,9 @@ class PortableInfoboxRenderService {
$output = $this->renderItem( 'wrapper', [
'content' => $infoboxHtmlContent,
'theme' => $theme,
'layout' => $layout
'layout' => $layout,
'type' => $type,
'item-name' => $itemName
] );
} else {
$output = '';
@ -120,7 +124,8 @@ class PortableInfoboxRenderService {
return $this->render( 'group', [
'content' => $groupHTMLContent,
'cssClasses' => implode( ' ', $cssClasses )
'cssClasses' => implode( ' ', $cssClasses ),
'item-name' => $groupData['item-name']
] );
}
@ -140,7 +145,11 @@ class PortableInfoboxRenderService {
$templateName = 'media';
} else {
// More than one image means image collection
$data = [ 'images' => $data ];
$data = [
'images' => $data,
'source' => $data[0]['source'],
'item-name' => $data[0]['item-name']
];
$templateName = 'media-collection';
}
@ -180,8 +189,7 @@ class PortableInfoboxRenderService {
private function createHorizontalGroupData( array $groupData ) {
$horizontalGroupData = [
'labels' => [],
'values' => [],
'data' => [],
'renderLabels' => false
];
@ -189,8 +197,12 @@ class PortableInfoboxRenderService {
$data = $item['data'];
if ( $item['type'] === 'data' ) {
array_push( $horizontalGroupData['labels'], $data['label'] );
array_push( $horizontalGroupData['values'], $data['value'] );
$horizontalGroupData['data'][] = [
'label' => $data['label'],
'value' => $data['value'],
'source' => $item['data']['source'] ?? "",
'item-name' => $item['data']['item-name']
];
if ( !empty( $data['label'] ) ) {
$horizontalGroupData['renderLabels'] = true;
@ -254,10 +266,15 @@ class PortableInfoboxRenderService {
if ( !empty( $label ) ) {
$result['renderLabels'] = true;
}
$result['labels'][] = [ 'value' => $label, 'inlineStyles' => $styles ];
$result['values'][] = [ 'value' => $item['data']['value'], 'inlineStyles' => $styles ];
$result['data'][] = [
'label' => $label,
'value' => $item['data']['value'],
'inlineStyles' => $styles,
'source' => $item['data']['source'] ?? "",
'item-name' => $item['data']['item-name']
];
return $result;
}, [ 'labels' => [], 'values' => [], 'renderLabels' => false ] );
}, [ 'data' => [], 'renderLabels' => false ] );
}
}

View file

@ -1,19 +1,19 @@
<table class="pi-horizontal-group{{#unless renderLabels}} pi-horizontal-group-no-labels{{/unless}}">
<table class="pi-horizontal-group{{#unless renderLabels}} pi-horizontal-group-no-labels{{/unless}}"{{#if item-name}} data-item-name="{{item-name}}"{{/if}}>
{{#if header}}<caption class="pi-header pi-secondary-font pi-secondary-background pi-item-spacing"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}>{{{header}}}</caption>{{/if}}
{{#if renderLabels}}
<thead>
<tr>
{{#each labels}}
<th class="pi-horizontal-group-item pi-data-label pi-secondary-font pi-border-color pi-item-spacing">{{{.}}}</th>
{{#each data}}
<th class="pi-horizontal-group-item pi-data-label pi-secondary-font pi-border-color pi-item-spacing"{{#if source}} data-source="{{source}}"{{/if}}{{#if item-name}} data-item-name="{{item-name}}"{{/if}}>{{{label}}}</th>
{{/each}}
</tr>
</thead>
{{/if}}
<tbody>
<tr>
{{#each values}}
<td class="pi-horizontal-group-item pi-data-value pi-font pi-border-color pi-item-spacing">{{{.}}}</td>
{{/each}}
</tr>
<tr>
{{#each data}}
<td class="pi-horizontal-group-item pi-data-value pi-font pi-border-color pi-item-spacing"{{#if source}} data-source="{{source}}"{{/if}}{{#if item-name}} data-item-name="{{item-name}}"{{/if}}>{{{value}}}</td>
{{/each}}
</tr>
</tbody>
</table>

View file

@ -1,4 +1,4 @@
<div class="pi-item pi-data pi-item-spacing pi-border-color{{#if cssClasses}} {{{cssClasses}}}{{/if}}"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}>
<div class="pi-item pi-data pi-item-spacing pi-border-color{{#if cssClasses}} {{{cssClasses}}}{{/if}}"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}{{#if source}} data-source="{{source}}"{{/if}}{{#if item-name}} data-item-name="{{item-name}}"{{/if}}>
{{#if label}}
<{{#if useHeadings}}h3{{else}}div{{/if}} class="pi-data-label pi-secondary-font">{{{label}}}</{{#if useHeadings}}h3{{else}}div{{/if}}>
{{/if}}

View file

@ -1 +1 @@
<section class="pi-item pi-group pi-border-color{{#if cssClasses}} {{{cssClasses}}}{{/if}}">{{{content}}}</section>
<section class="pi-item pi-group pi-border-color{{#if cssClasses}} {{{cssClasses}}}{{/if}}"{{#if item-name}} data-item-name="{{item-name}}"{{/if}}>{{{content}}}</section>

View file

@ -1 +1 @@
<{{#if useHeadings}}h2{{else}}div{{/if}} class="pi-item pi-header pi-secondary-font pi-item-spacing pi-secondary-background"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}>{{{value}}}</{{#if useHeadings}}h2{{else}}div{{/if}}>
<{{#if useHeadings}}h2{{else}}div{{/if}} class="pi-item pi-header pi-secondary-font pi-item-spacing pi-secondary-background"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}{{#if item-name}} data-item-name="{{item-name}}"{{/if}}>{{{value}}}</{{#if useHeadings}}h2{{else}}div{{/if}}>

View file

@ -1,4 +1,4 @@
<figure class="pi-item pi-media{{#if isImage}} pi-image{{/if}}{{#if isVideo}} pi-video{{/if}}{{#if isAudio}} pi-audio{{/if}}">
<figure class="pi-item pi-media{{#if isImage}} pi-image{{/if}}{{#if isVideo}} pi-video{{/if}}{{#if isAudio}} pi-audio{{/if}}"{{#if source}} data-source="{{source}}"{{/if}}{{#if item-name}} data-item-name="{{item-name}}"{{/if}}>
<a href="{{url}}" class="{{#if isImage}}image image-thumbnail{{/if}}{{#if isVideo}}video{{/if}}{{#if isAudio}}audio{{/if}}" title="{{alt}}">
{{#if isImage}}<img src="{{thumbnail}}" srcset="{{thumbnail}} 1x, {{thumbnail2x}} 2x" class="pi-image-thumbnail" alt="{{alt}}" width="{{{width}}}" height="{{{height}}}"/>
{{else}}{{#if isVideo}}<video src="{{url}}" class="pi-video-player" controls="true" controlsList="nodownload" preload="metadata">{{alt}}</video>

View file

@ -1,10 +1,10 @@
<div class="pi-media-collection">
<div class="pi-media-collection" {{#if source}} data-source="{{source}}"{{/if}}{{#if item-name}} data-item-name="{{item-name}}"{{/if}}>
<ul class="pi-media-collection-tabs">
{{#each images}}<li class="pi-tab-link pi-item-spacing{{#if isFirst}} current{{/if}}" data-pi-tab="pi-tab-{{ref}}">{{{caption}}}</li>{{/each}}
</ul>
{{#each images}}
<div class="pi-media-collection-tab-content{{#if isFirst}} current{{/if}}" id="pi-tab-{{ref}}">
<figure class="pi-item pi-media{{#if isImage}} pi-image{{/if}}{{#if isVideo}} pi-video{{/if}}{{#if isAudio}} pi-audio{{/if}}">
<figure class="pi-item pi-media{{#if isImage}} pi-image{{/if}}{{#if isVideo}} pi-video{{/if}}{{#if isAudio}} pi-audio{{/if}}"{{#if source}} data-source="{{source}}"{{/if}}{{#if item-name}} data-item-name="{{item-name}}"{{/if}}>
<a href="{{url}}" class="{{#if isImage}}image image-thumbnail{{/if}}{{#if isVideo}}video{{/if}}{{#if isAudio}}audio{{/if}}" title="{{alt}}">
{{#if isImage}}<img src="{{thumbnail}}" srcset="{{thumbnail}} 1x, {{thumbnail2x}} 2x" class="pi-image-thumbnail" alt="{{alt}}" width="{{{width}}}" height="{{{height}}}"/>
{{else}}{{#if isVideo}}<video src="{{url}}" class="pi-video-player" controls="true" controlsList="nodownload" preload="metadata">{{alt}}</video>

View file

@ -1 +1 @@
<nav class="pi-navigation pi-item-spacing pi-secondary-background pi-secondary-font">{{{value}}}</nav>
<nav class="pi-navigation pi-item-spacing pi-secondary-background pi-secondary-font"{{#if item-name}} data-item-name="{{item-name}}"{{/if}}>{{{value}}}</nav>

View file

@ -1,14 +1,14 @@
<section class="pi-item pi-smart-group pi-border-color">
{{#if renderLabels}}
<section class="pi-smart-group-head">
{{#each labels}}
<{{#if ../useHeadings}}h3{{else}}div{{/if}} class="pi-smart-data-label pi-data-label pi-secondary-font pi-item-spacing" style="{{{inlineStyles}}}">{{{value}}}</{{#if ../useHeadings}}h3{{else}}div{{/if}}>
{{#each data}}
<{{#if ../useHeadings}}h3{{else}}div{{/if}} class="pi-smart-data-label pi-data-label pi-secondary-font pi-item-spacing" style="{{{inlineStyles}}}"{{#if source}} data-source="{{source}}"{{/if}}{{#if item-name}} data-item-name="{{item-name}}"{{/if}}>{{{label}}}</{{#if ../useHeadings}}h3{{else}}div{{/if}}>
{{/each}}
</section>
{{/if}}
<section class="pi-smart-group-body">
{{#each values}}
<div class="pi-smart-data-value pi-data-value pi-font pi-item-spacing" style="{{{inlineStyles}}}">{{{value}}}</div>
{{#each data}}
<div class="pi-smart-data-value pi-data-value pi-font pi-item-spacing" style="{{{inlineStyles}}}"{{#if source}} data-source="{{source}}"{{/if}}{{#if item-name}} data-item-name="{{item-name}}"{{/if}}>{{{value}}}</div>
{{/each}}
</section>
</section>

View file

@ -1 +1 @@
<{{#if useHeadings}}h2{{else}}div{{/if}} class="pi-item pi-item-spacing pi-title"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}>{{{value}}}</{{#if useHeadings}}h2{{else}}div{{/if}}>
<{{#if useHeadings}}h2{{else}}div{{/if}} class="pi-item pi-item-spacing pi-title"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}{{#if source}} data-source="{{source}}"{{/if}}{{#if item-name}} data-item-name="{{item-name}}"{{/if}}>{{{value}}}</{{#if useHeadings}}h2{{else}}div{{/if}}>

View file

@ -1 +1 @@
<aside class="portable-infobox noexcerpt pi-background{{#if theme}} {{theme}}{{/if}}{{#if layout}} {{layout}}{{/if}}">{{{content}}}</aside>
<aside class="portable-infobox noexcerpt pi-background{{#if theme}} {{theme}}{{/if}}{{#if layout}} {{layout}}{{/if}}{{#if type}} {{type}}{{/if}}"{{#if item-name}} data-item-name="{{item-name}}"{{/if}}>{{{content}}}</aside>

View file

@ -65,7 +65,9 @@ class PortableInfoboxDataServiceTest extends MediaWikiTestCase {
'label' => null,
'value' => 1,
'layout' => null,
'span' => 1
'span' => 1,
'source' => 'test',
'item-name' => null
]
]
],

File diff suppressed because it is too large Load diff

View file

@ -532,83 +532,196 @@ class NodeDataTest extends MediaWikiTestCase {
[
'<data source="test"></data>',
[ 'test' => 'test' ],
[ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ]
[
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'<data source="test" span="2"></data>',
[ 'test' => 'test' ],
[ 'value' => 'test', 'label' => '', 'span' => '2', 'layout' => null ]
[
'value' => 'test',
'label' => '',
'span' => '2',
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'<data source="test" span="2.2"></data>',
[ 'test' => 'test' ],
[ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ]
[
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'<data source="test" span="non_numeric_span"></data>',
[ 'test' => 'test' ],
[ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ]
[
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'<data source="test" layout="wrong layout"></data>',
[ 'test' => 'test' ],
[ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ]
[
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'<data source="test" layout="default"></data>',
[ 'test' => 'test' ],
[ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => 'default' ]
[
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => 'default',
'source' => 'test',
'item-name' => null
]
],
[
'<data source="test"><default>def</default></data>',
[],
[ 'value' => 'def', 'label' => '', 'span' => 1, 'layout' => null ]
[
'value' => 'def',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'<data source="test"><label>l</label><default>def</default></data>',
[],
[ 'value' => 'def', 'label' => 'l', 'span' => 1, 'layout' => null ] ],
[
'value' => 'def',
'label' => 'l',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'<data source="test"><label source="l">jjj</label><default>def</default></data>',
[ 'l' => 1 ],
[ 'value' => 'def', 'label' => 'jjj', 'span' => 1, 'layout' => null ]
[
'value' => 'def',
'label' => 'jjj',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'<data source="test"><label source="l" /><default>def</default></data>',
[ 'l' => 1 ],
[ 'value' => 'def', 'label' => '', 'span' => 1, 'layout' => null ]
[
'value' => 'def',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'<data source="test"><label>l</label><default>def</default></data>',
[ 'test' => 1 ],
[ 'value' => 1, 'label' => 'l', 'span' => 1, 'layout' => null ]
[
'value' => 1,
'label' => 'l',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'<data></data>',
[],
[ 'label' => '', 'value' => null, 'span' => 1, 'layout' => null ]
[
'label' => '',
'value' => null,
'span' => 1,
'layout' => null,
'source' => null,
'item-name' => null
]
],
[
'<data source="test"><label>l</label><format>{{{test}}}%</format><default>def</default></data>',
[ 'test' => 1 ],
[ 'value' => '{{{test}}}%', 'label' => 'l', 'span' => 1, 'layout' => null ]
[ 'test' => 1 ],
[
'value' => '{{{test}}}%',
'label' => 'l',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'<data source="test">' .
'<label>l</label><format>{{{not_defined_var}}}%</format><default>def</default>' .
'</data>',
[ 'test' => 1 ],
[ 'value' => '{{{not_defined_var}}}%', 'label' => 'l', 'span' => 1, 'layout' => null ]
[
'value' => '{{{not_defined_var}}}%',
'label' => 'l',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'<data source="test"><label>l</label><format>{{{test}}}%</format><default>def</default></data>',
[],
[ 'value' => 'def', 'label' => 'l', 'span' => 1, 'layout' => null ]
[
'value' => 'def',
'label' => 'l',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'<data source="test"><format>{{{test}}}%</format></data>',
[ 'test' => 0 ],
[ 'value' => '{{{test}}}%', 'label' => '', 'span' => 1, 'layout' => null ]
[
'value' => '{{{test}}}%',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
];
}
@ -636,7 +749,14 @@ class NodeDataTest extends MediaWikiTestCase {
[ 'test' => 'test' ],
[
'type' => 'data',
'data' => [ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ]
'data' => [
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
]
],
[
@ -644,7 +764,14 @@ class NodeDataTest extends MediaWikiTestCase {
[ 'test' => 'test' ],
[
'type' => 'data',
'data' => [ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => 'default' ]
'data' => [
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => 'default',
'source' => 'test',
'item-name' => null
]
]
],
[
@ -652,7 +779,14 @@ class NodeDataTest extends MediaWikiTestCase {
[ 'test' => 'test' ],
[
'type' => 'data',
'data' => [ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ]
'data' => [
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
]
],
[
@ -660,7 +794,14 @@ class NodeDataTest extends MediaWikiTestCase {
[ 'test' => 'test' ],
[
'type' => 'data',
'data' => [ 'value' => 'test', 'label' => '', 'span' => '2', 'layout' => null ]
'data' => [
'value' => 'test',
'label' => '',
'span' => '2',
'layout' => null,
'source' => 'test',
'item-name' => null
]
]
],
[
@ -668,7 +809,14 @@ class NodeDataTest extends MediaWikiTestCase {
[ 'test' => 'test' ],
[
'type' => 'data',
'data' => [ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ]
'data' => [
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
]
],
[
@ -676,9 +824,31 @@ class NodeDataTest extends MediaWikiTestCase {
[ 'test' => 'test' ],
[
'type' => 'data',
'data' => [ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ]
'data' => [
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
]
],
[
'<data source="test" name="data name"></data>',
[ 'test' => 'test' ],
[
'type' => 'data',
'data' => [
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => 'data name'
]
]
]
];
}

View file

@ -78,25 +78,47 @@ class NodeGroupTest extends MediaWikiTestCase {
[
'type' => 'data',
'isEmpty' => false,
'data' => [ 'label' => 'l1', 'value' => 1, 'span' => 1, 'layout' => null ],
'data' => [
'label' => 'l1',
'value' => 1,
'span' => 1,
'layout' => null,
'source' => 'elem1',
'item-name' => null
],
'source' => [ 'elem1' ]
],
[
'type' => 'data',
'isEmpty' => false,
'data' => [ 'label' => 'l2', 'value' => 2, 'span' => 1, 'layout' => null ],
'data' => [
'label' => 'l2',
'value' => 2,
'span' => 1,
'layout' => null,
'source' => 'elem2',
'item-name' => null
],
'source' => [ 'elem2' ]
],
[
'type' => 'data',
'isEmpty' => true,
'data' => [ 'label' => 'l2', 'value' => null, 'span' => 1, 'layout' => null ],
'data' => [
'label' => 'l2',
'value' => null,
'span' => 1,
'layout' => null,
'source' => 'elem3',
'item-name' => null
],
'source' => [ 'elem3' ]
]
],
'layout' => 'default',
'collapse' => null,
'row-items' => null
'row-items' => null,
'item-name' => null
]
],
[
@ -111,25 +133,47 @@ class NodeGroupTest extends MediaWikiTestCase {
[
'type' => 'data',
'isEmpty' => false,
'data' => [ 'label' => 'l1', 'value' => 1, 'span' => 1, 'layout' => null ],
'data' => [
'label' => 'l1',
'value' => 1,
'span' => 1,
'layout' => null,
'source' => 'elem1',
'item-name' => null
],
'source' => [ 'elem1' ]
],
[
'type' => 'data',
'isEmpty' => false,
'data' => [ 'label' => 'l2', 'value' => 2, 'span' => 1, 'layout' => null ],
'data' => [
'label' => 'l2',
'value' => 2,
'span' => 1,
'layout' => null,
'source' => 'elem2',
'item-name' => null
],
'source' => [ 'elem2' ]
],
[
'type' => 'data',
'isEmpty' => true,
'data' => [ 'label' => 'l2', 'value' => null, 'span' => 1, 'layout' => null ],
'data' => [
'label' => 'l2',
'value' => null,
'span' => 1,
'layout' => null,
'source' => 'elem3',
'item-name' => null
],
'source' => [ 'elem3' ]
],
],
'layout' => 'horizontal',
'collapse' => null,
'row-items' => null
'row-items' => null,
'item-name' => null
]
],
[
@ -144,25 +188,47 @@ class NodeGroupTest extends MediaWikiTestCase {
[
'type' => 'data',
'isEmpty' => false,
'data' => [ 'label' => 'l1', 'value' => 1, 'span' => 1, 'layout' => null ],
'source' => [ 'elem1' ]
'data' => [
'label' => 'l1',
'value' => 1,
'span' => 1,
'layout' => null,
'source' => 'elem1',
'item-name' => null
],
'source' => [ 'elem1' ]
],
[
'type' => 'data',
'isEmpty' => false,
'data' => [ 'label' => 'l2', 'value' => 2, 'span' => 1, 'layout' => null ],
'source' => [ 'elem2' ]
'data' => [
'label' => 'l2',
'value' => 2,
'span' => 1,
'layout' => null,
'source' => 'elem2',
'item-name' => null
],
'source' => [ 'elem2' ]
],
[
'type' => 'data',
'isEmpty' => true,
'data' => [ 'label' => 'l2', 'value' => null, 'span' => 1, 'layout' => null ],
'data' => [
'label' => 'l2',
'value' => null,
'span' => 1,
'layout' => null,
'source' => 'elem3',
'item-name' => null
],
'source' => [ 'elem3' ]
]
],
'layout' => 'default',
'collapse' => null,
'row-items' => null
'row-items' => null,
'item-name' => null
]
],
[
@ -172,26 +238,44 @@ class NodeGroupTest extends MediaWikiTestCase {
'value' => [
[
'type' => 'header',
'data' => [ 'value' => 'h' ],
'data' => [
'value' => 'h',
'item-name' => null
],
'isEmpty' => false,
'source' => []
],
[
'type' => 'data',
'data' => [ 'value' => 'one', 'label' => '', 'span' => 1, 'layout' => null ],
'data' => [
'value' => 'one',
'label' => '',
'span' => 1,
'layout' => null,
'source' => '1',
'item-name' => null
],
'isEmpty' => false,
'source' => [ '1' ]
],
[
'type' => 'data',
'data' => [ 'value' => 'two', 'label' => '', 'span' => 1, 'layout' => null ],
'data' => [
'value' => 'two',
'label' => '',
'span' => 1,
'layout' => null,
'source' => '2',
'item-name' => null
],
'isEmpty' => false,
'source' => [ '2' ]
]
],
'layout' => 'default',
'collapse' => null,
'row-items' => null
'row-items' => null,
'item-name' => null
]
],
[
@ -201,26 +285,41 @@ class NodeGroupTest extends MediaWikiTestCase {
'value' => [
[
'type' => 'header',
'data' => [ 'value' => 'h' ],
'data' => [ 'value' => 'h', 'item-name' => null ],
'isEmpty' => false,
'source' => []
],
[
'type' => 'data',
'data' => [ 'value' => 'one', 'label' => '', 'span' => 1, 'layout' => null ],
'data' => [
'value' => 'one',
'label' => '',
'span' => 1,
'layout' => null,
'source' => '1',
'item-name' => null
],
'isEmpty' => false,
'source' => [ '1' ]
],
[
'type' => 'data',
'data' => [ 'value' => null, 'label' => '', 'span' => 1, 'layout' => null ],
'data' => [
'value' => null,
'label' => '',
'span' => 1,
'layout' => null,
'source' => '2',
'item-name' => null
],
'isEmpty' => true,
'source' => [ '2' ]
]
],
'layout' => 'default',
'collapse' => null,
'row-items' => null
'row-items' => null,
'item-name' => null
]
],
[
@ -230,26 +329,78 @@ class NodeGroupTest extends MediaWikiTestCase {
'value' => [
[
'type' => 'header',
'data' => [ 'value' => 'h' ],
'data' => [
'value' => 'h',
'item-name' => null
],
'isEmpty' => false,
'source' => []
],
[
'type' => 'data',
'data' => [ 'value' => null, 'label' => '', 'span' => 1, 'layout' => null ],
'data' => [
'value' => null,
'label' => '',
'span' => 1,
'layout' => null,
'source' => '1',
'item-name' => null
],
'isEmpty' => true,
'source' => [ '1' ]
],
[
'type' => 'data',
'data' => [ 'value' => null, 'label' => '', 'span' => 1, 'layout' => null ],
'data' => [
'value' => null,
'label' => '',
'span' => 1,
'layout' => null,
'source' => '2',
'item-name' => null
],
'isEmpty' => true,
'source' => [ '2' ]
]
],
'layout' => 'default',
'collapse' => null,
'row-items' => null
'row-items' => null,
'item-name' => null
]
],
[
'<group name="g"><header name="h">h</header><data source="d" name="d"/></group>',
[ 'd' => 'data' ],
[
'value' => [
[
'type' => 'header',
'data' => [
'value' => 'h',
'item-name' => 'h'
],
'isEmpty' => false,
'source' => []
],
[
'type' => 'data',
'data' => [
'value' => 'data',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'd',
'item-name' => 'd'
],
'isEmpty' => false,
'source' => [ 'd' ]
]
],
'layout' => 'default',
'collapse' => null,
'row-items' => null,
'item-name' => 'g'
]
]
];

View file

@ -23,15 +23,19 @@ class NodeHeaderTest extends MediaWikiTestCase {
return [
[
'<header></header>',
[ 'value' => '' ]
[ 'value' => '', 'item-name' => null ]
],
[
'<header>kjdflkja dafkjlsdkfj</header>',
[ 'value' => 'kjdflkja dafkjlsdkfj' ]
[ 'value' => 'kjdflkja dafkjlsdkfj', 'item-name' => null ]
],
[
'<header>kjdflkja<ref>dafkjlsdkfj</ref></header>',
[ 'value' => 'kjdflkja<ref>dafkjlsdkfj</ref>' ]
[ 'value' => 'kjdflkja<ref>dafkjlsdkfj</ref>', 'item-name' => null ]
],
[
'<header name="headertest">kjdflkja dafkjlsdkfj</header>',
[ 'value' => 'kjdflkja dafkjlsdkfj', 'item-name' => 'headertest' ]
]
];
}

View file

@ -179,7 +179,9 @@ class NodeMediaTest extends MediaWikiTestCase {
'caption' => null,
'isImage' => true,
'isVideo' => false,
'isAudio' => false
'isAudio' => false,
'source' => 'img',
'item-name' => null
] ]
],
[
@ -193,7 +195,9 @@ class NodeMediaTest extends MediaWikiTestCase {
'caption' => null,
'isImage' => true,
'isVideo' => false,
'isAudio' => false
'isAudio' => false,
'source' => 'img',
'item-name' => null
] ]
],
[
@ -207,7 +211,9 @@ class NodeMediaTest extends MediaWikiTestCase {
'caption' => null,
'isImage' => true,
'isVideo' => false,
'isAudio' => false
'isAudio' => false,
'source' => 'img',
'item-name' => null
] ]
],
[
@ -221,7 +227,25 @@ class NodeMediaTest extends MediaWikiTestCase {
'caption' => 'test.jpg',
'isImage' => true,
'isVideo' => false,
'isAudio' => false
'isAudio' => false,
'source' => 'img',
'item-name' => null
] ]
],
[
'<media source="img" name="img" />',
[ 'img' => 'test.jpg' ],
MEDIATYPE_BITMAP,
[ [
'url' => 'http://test.url',
'name' => 'Test.jpg',
'alt' => 'Test.jpg',
'caption' => null,
'isImage' => true,
'isVideo' => false,
'isAudio' => false,
'source' => 'img',
'item-name' => 'img'
] ]
],
[
@ -235,7 +259,9 @@ class NodeMediaTest extends MediaWikiTestCase {
'caption' => null,
'isImage' => false,
'isVideo' => true,
'isAudio' => false
'isAudio' => false,
'source' => 'media',
'item-name' => null
] ]
],
[
@ -255,7 +281,9 @@ class NodeMediaTest extends MediaWikiTestCase {
'caption' => null,
'isImage' => false,
'isVideo' => false,
'isAudio' => true
'isAudio' => true,
'source' => 'media',
'item-name' => null
] ]
],
[

View file

@ -23,15 +23,19 @@ class NodeNavigationTest extends MediaWikiTestCase {
return [
[
'<navigation></navigation>',
[ 'value' => '' ]
[ 'value' => '', 'item-name' => null ]
],
[
'<navigation>kjdflkja dafkjlsdkfj</navigation>',
[ 'value' => 'kjdflkja dafkjlsdkfj' ]
[ 'value' => 'kjdflkja dafkjlsdkfj', 'item-name' => null ]
],
[
'<navigation>kjdflkja<ref>dafkjlsdkfj</ref></navigation>',
[ 'value' => 'kjdflkja<ref>dafkjlsdkfj</ref>' ]
[ 'value' => 'kjdflkja<ref>dafkjlsdkfj</ref>', 'item-name' => null ]
],
[
'<navigation name="ihatetests">kjdflkja dafkjlsdkfj</navigation>',
[ 'value' => 'kjdflkja dafkjlsdkfj', 'item-name' => 'ihatetests' ]
]
];
}

View file

@ -24,57 +24,67 @@ class NodeTitleTest extends MediaWikiTestCase {
[
'<title source="test"/>',
[ 'test' => 'test' ],
[ 'value' => 'test' ]
[ 'value' => 'test', 'source' => 'test', 'item-name' => null ]
],
[
'<title source="test"><default>def</default></title>',
[],
[ 'value' => 'def' ]
[ 'value' => 'def', 'source' => 'test', 'item-name' => null ]
],
[
'<title source="test"><default>def</default></title>',
[],
[ 'value' => 'def' ]
[ 'value' => 'def', 'source' => 'test', 'item-name' => null ]
],
[
'<title source="test"><default>def</default></title>',
[ 'l' => 1 ],
[ 'value' => 'def' ]
[ 'value' => 'def', 'source' => 'test', 'item-name' => null ]
],
[
'<title source="test"><default>def</default></title>',
[ 'l' => 1 ],
[ 'value' => 'def' ]
[ 'value' => 'def', 'source' => 'test', 'item-name' => null ]
],
[
'<title source="test"><default>def</default></title>',
[ 'test' => 1 ],
[ 'value' => 1 ]
[ 'value' => 1, 'source' => 'test', 'item-name' => null ]
],
[
'<title></title>',
[],
[ 'value' => null ]
[ 'value' => null, 'source' => null, 'item-name' => null ]
],
[
'<title source="test"><format>{{{test}}}%</format><default>def</default></title>',
[ 'test' => 1 ],
[ 'value' => '{{{test}}}%' ]
[ 'value' => '{{{test}}}%', 'source' => 'test', 'item-name' => null ]
],
[
'<title source="test"><format>{{{not_defined_var}}}%</format><default>def</default></title>',
[ 'test' => 1 ],
[ 'value' => '{{{not_defined_var}}}%' ]
[ 'value' => '{{{not_defined_var}}}%', 'source' => 'test', 'item-name' => null ]
],
[
'<title source="test"><format>{{{test}}}%</format><default>def</default></title>',
[],
[ 'value' => 'def' ]
[ 'value' => 'def', 'source' => 'test', 'item-name' => null ]
],
[
'<title source="test"><format>{{{test}}}%</format></title>',
[ 'test' => 0 ],
[ 'value' => '{{{test}}}%' ]
[ 'value' => '{{{test}}}%', 'source' => 'test', 'item-name' => null ]
],
[
'<title source="test" name="nametest" />',
[ 'test' => 'abc' ],
[ 'value' => 'abc', 'source' => 'test', 'item-name' => 'nametest' ]
],
[
'<title name="nametest"><default>def</default></title>',
[],
[ 'value' => 'def', 'source' => null, 'item-name' => 'nametest' ]
]
];
}