This module contains testcases for its parent module, XML.
See also
--- Test specification for XML parser.
-- @file xml.testcases
local xml = require('Module:XML')
local unindent = require('Module:Unindent')
return {
load = {
options = {
mode = 'method',
nowiki = true
},
tests = {
{
'Module:DEV/NULL',
'file "Module:DEV/NULL" does not contain XML',
{ err = true }
},
{
'Dev:DEV/NULL',
'file "Dev:DEV/NULL" does not contain XML',
{ err = true }
},
{
'Module:XML',
'file "Module:XML" does not contain XML',
{ err = true }
},
{
'Module:XML/testcases/books',
unindent [=[
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Source: https://msdn.microsoft.com/en-us/library/ms762271(v=vs.85).aspx -->
<catalog>
<book>
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book>
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book>
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
</catalog>
]=]
},
{
'Module:XML/testcases/people',
unindent [=[
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Source: https://github.com/manoelcampos/xml2lua/blob/master/people.xml -->
<people>
<person type="natural">
<![CDATA[
Just a CDATA tag that may contain anything, including XML code,
such as <tag>message</tag>.
Its content is extracted but not processed.
]]>
<!-- Just an example comment that will be ignored by the tree handler and processed by the other ones. -->
<name>Manoel</name>
<city>Palmas-TO</city>
</person>
<person type="natural">
<name>Breno</name>
<city>Palmas-TO</city>
</person>
<person type="legal">
<name>University of Brasília</name>
<city>Brasília-DF</city>
</person>
</people>
]=]
},
{
'Module:XML/testcases/infobox',
unindent [=[
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- XML schema for Wikia's propietary XML syntax. -->
<!-- For simplicity, this file does not include MediaWiki and HTML tags. -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- # Validator restrictions used in infobox attributes. # -->
<!-- ## Infobox title color validation. ## -->
<!-- Source: [[github:Wikia/app/blob/release-1073.001/extensions/wikia/PortableInfobox/services/Helpers/InfoboxParamsValidator.php#L45]] -->
<xs:simpleType name="piColor">
<xs:restriction base="xs:string">
<xs:pattern value="[a-f0-9]{3}([a-f0-9]{3})?)" />
</xs:restriction>
</xs:simpleType>
<!-- ## Infobox layout attribute validation. ## -->
<!-- Source: [[github:Wikia/app/blob/release-1073.001/extensions/wikia/PortableInfobox/services/Helpers/InfoboxParamsValidator.php#L54]] -->
<xs:simpleType name="piInfoboxLayout">
<xs:restriction base="xs:string">
<xs:enumeration value="default" />
<xs:enumeration value="stacked" />
</xs:restriction>
</xs:simpleType>
<!-- ## Group layout attribute validation. ## -->
<!-- Source: [[github:Wikia/app/blob/release-1073.001/extensions/wikia/PortableInfobox/services/Parser/Nodes/NodeGroup.php#L7]] -->
<xs:simpleType name="piGroupLayout">
<xs:restriction base="xs:string">
<xs:enumeration value="default" />
<xs:enumeration value="horizontal" />
</xs:restriction>
</xs:simpleType>
<!-- ## Group show attribute validation. ## -->
<!-- Source: [[github:Wikia/app/blob/release-1073.001/extensions/wikia/PortableInfobox/services/Parser/Nodes/NodeGroup.php#L9]] -->
<xs:simpleType name="pigroupShow">
<xs:restriction base="xs:string">
<xs:enumeration value="default" />
<xs:enumeration value="incomplete" />
</xs:restriction>
</xs:simpleType>
<!-- ## Group collapse attribute validation. ## -->
<!-- Source: [[github:Wikia/app/blob/release-1073.001/extensions/wikia/PortableInfobox/services/Parser/Nodes/NodeGroup.php#L12]] -->
<xs:simpleType name="piGroupCollapse">
<xs:restriction base="xs:string">
<xs:enumeration value="open" />
<xs:enumeration value="closed" />
</xs:restriction>
</xs:simpleType>
<!-- # Group element definition. # -->
<xs:element name="group">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element maxOccurs="unbounded" ref="panel" />
<xs:element maxOccurs="unbounded" ref="header" />
<xs:element maxOccurs="unbounded" ref="title" />
<xs:element maxOccurs="unbounded" ref="image" />
<xs:element maxOccurs="unbounded" ref="navigation" />
<xs:element maxOccurs="unbounded" ref="data" />
</xs:choice>
<xs:attribute name="layout" type="piGroupLayout" />
<xs:attribute name="show" type="pigroupShow" />
<xs:attribute name="collapse" type="piGroupCollapse" />
<xs:attribute name="row-items" type="xs:int" />
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
<!-- # Panel element definition. # -->
<xs:element name="panel">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element maxOccurs="unbounded" ref="section" />
<xs:element maxOccurs="unbounded" ref="header" />
</xs:choice>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
<!-- # Section element definition. # -->
<!-- Serves as tabbed group in panel container -->
<xs:element name="section">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element maxOccurs="1" ref="label" />
<xs:element maxOccurs="unbounded" ref="group" />
<xs:element maxOccurs="unbounded" ref="header" />
<xs:element maxOccurs="unbounded" ref="title" />
<xs:element maxOccurs="unbounded" ref="image" />
<xs:element maxOccurs="unbounded" ref="navigation" />
<xs:element maxOccurs="unbounded" ref="data" />
</xs:choice>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
<!-- # Header element definition. # -->
<xs:element name="header">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<!-- # Navigation element definition. # -->
<xs:element name="navigation">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<!-- # Title element definition. # -->
<xs:element name="title">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="format" />
<xs:element ref="default" />
</xs:choice>
<xs:attribute name="source" type="xs:string" />
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
<!-- # Data element definitions. # -->
<xs:element name="data">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="label" />
<xs:element ref="format" />
<xs:element ref="default" />
</xs:choice>
<xs:attribute name="source" type="xs:string" />
<xs:attribute name="span" type="xs:string" />
<xs:attribute name="layout" type="xs:string" />
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="label" type="xs:string" />
<xs:element name="format" type="xs:string" />
<xs:element name="default" type="xs:string" />
<!-- # Image element definitions. # -->
<xs:element name="image">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element maxOccurs="1" ref="alt" />
<xs:element maxOccurs="1" ref="caption" />
<xs:element maxOccurs="1" ref="default" />
</xs:choice>
<xs:attribute name="source" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="alt">
<xs:complexType>
<xs:choice>
<xs:element ref="default" minOccurs="0" />
</xs:choice>
<xs:attribute name="source" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="caption">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element maxOccurs="1" ref="format" />
<xs:element maxOccurs="1" ref="default" />
</xs:choice>
<xs:attribute name="source" type="xs:string" />
</xs:complexType>
</xs:element>
<!-- # Infobox element definition. # -->
<!-- Serves as infobox container & delimiter. -->
<xs:element name="infobox">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element maxOccurs="unbounded" ref="group" />
<xs:element maxOccurs="unbounded" ref="panel" />
<xs:element maxOccurs="unbounded" ref="title" />
<xs:element maxOccurs="unbounded" ref="image" />
<xs:element maxOccurs="unbounded" ref="navigation" />
<xs:element maxOccurs="unbounded" ref="data" />
</xs:choice>
<xs:attribute name="layout">
<xs:simpleType>
<xs:restriction base="piInfoboxLayout" />
</xs:simpleType>
</xs:attribute>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="theme" type="xs:string" />
<xs:attribute name="theme-source" type="xs:string" />
<xs:attribute name="type" type="xs:string" />
<xs:attribute name="accent-color-source">
<xs:simpleType>
<xs:restriction base="piColor" />
</xs:simpleType>
</xs:attribute>
<xs:attribute name="accent-color-default">
<xs:simpleType>
<xs:restriction base="piColor" />
</xs:simpleType>
</xs:attribute>
<xs:attribute name="accent-color-text-source">
<xs:simpleType>
<xs:restriction base="piColor" />
</xs:simpleType>
</xs:attribute>
<xs:attribute name="accent-color-text-default">
<xs:simpleType>
<xs:restriction base="piColor" />
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
]=]
}
}
},
parse = {
options = {
mode = 'method',
unpk = true,
deep = true,
nowiki = true
},
tests = {
{
{ xml.load('Module:XML/testcases/infobox') },
require('Module:XML/testcases/infobox/dom')
},
{
{ xml.load('Module:XML/testcases/books') },
require('Module:XML/testcases/books/dom')
},
{
{ xml.load('Module:XML/testcases/books'), 'Tree' },
require('Module:XML/testcases/books/tree')
},
{
{ xml.load('Module:XML/testcases/books'), 'Print' },
require('Module:XML/testcases/books/print')
},
{
{ xml.load('Module:XML/testcases/people') },
require('Module:XML/testcases/people/dom')
},
{
{ xml.load('Module:XML/testcases/people'), 'Tree' },
require('Module:XML/testcases/people/tree')
},
{
{ xml.load('Module:XML/testcases/people'), 'Print' },
require('Module:XML/testcases/people/print')
},
{
{ xml.load('Module:XML/testcases/infobox'), 'Tree' },
require('Module:XML/testcases/infobox/tree')
},
{
{ xml.load('Module:XML/testcases/infobox'), 'Print' },
require('Module:XML/testcases/infobox/print')
}
}
},
serialise = {
options = {
mode = 'method',
nowiki = true
},
tests = {
{
require('Dev:XML/testcases/infobox/print'),
'cannot serialise this value. Are you using a handler other than "xml.handlers.DOM" and "xml.handlers.Tree"?',
{ err = true }
},
{
require('Module:XML/testcases/infobox/dom'),
unindent [=[
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- # Validator restrictions used in infobox attributes. # -->
<!-- ## Infobox title color validation. ## -->
<!-- Source: [[github:Wikia/app/blob/release-1073.001/extensions/wikia/PortableInfobox/services/Helpers/InfoboxParamsValidator.php#L45]] -->
<xs:simpleType name="piColor">
<xs:restriction base="xs:string">
<xs:pattern value="[a-f0-9]{3}([a-f0-9]{3})?)" />
</xs:restriction>
</xs:simpleType>
<!-- ## Infobox layout attribute validation. ## -->
<!-- Source: [[github:Wikia/app/blob/release-1073.001/extensions/wikia/PortableInfobox/services/Helpers/InfoboxParamsValidator.php#L54]] -->
<xs:simpleType name="piInfoboxLayout">
<xs:restriction base="xs:string">
<xs:enumeration value="default" />
<xs:enumeration value="stacked" />
</xs:restriction>
</xs:simpleType>
<!-- ## Group layout attribute validation. ## -->
<!-- Source: [[github:Wikia/app/blob/release-1073.001/extensions/wikia/PortableInfobox/services/Parser/Nodes/NodeGroup.php#L7]] -->
<xs:simpleType name="piGroupLayout">
<xs:restriction base="xs:string">
<xs:enumeration value="default" />
<xs:enumeration value="horizontal" />
</xs:restriction>
</xs:simpleType>
<!-- ## Group show attribute validation. ## -->
<!-- Source: [[github:Wikia/app/blob/release-1073.001/extensions/wikia/PortableInfobox/services/Parser/Nodes/NodeGroup.php#L9]] -->
<xs:simpleType name="pigroupShow">
<xs:restriction base="xs:string">
<xs:enumeration value="default" />
<xs:enumeration value="incomplete" />
</xs:restriction>
</xs:simpleType>
<!-- ## Group collapse attribute validation. ## -->
<!-- Source: [[github:Wikia/app/blob/release-1073.001/extensions/wikia/PortableInfobox/services/Parser/Nodes/NodeGroup.php#L12]] -->
<xs:simpleType name="piGroupCollapse">
<xs:restriction base="xs:string">
<xs:enumeration value="open" />
<xs:enumeration value="closed" />
</xs:restriction>
</xs:simpleType>
<!-- # Group element definition. # -->
<xs:element name="group">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element maxOccurs="unbounded" ref="panel" />
<xs:element maxOccurs="unbounded" ref="header" />
<xs:element maxOccurs="unbounded" ref="title" />
<xs:element maxOccurs="unbounded" ref="image" />
<xs:element maxOccurs="unbounded" ref="navigation" />
<xs:element maxOccurs="unbounded" ref="data" />
</xs:choice>
<xs:attribute name="layout" type="piGroupLayout" />
<xs:attribute name="show" type="pigroupShow" />
<xs:attribute name="collapse" type="piGroupCollapse" />
<xs:attribute name="row-items" type="xs:int" />
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
<!-- # Panel element definition. # -->
<xs:element name="panel">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element maxOccurs="unbounded" ref="section" />
<xs:element maxOccurs="unbounded" ref="header" />
</xs:choice>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
<!-- # Section element definition. # -->
<!-- Serves as tabbed group in panel container -->
<xs:element name="section">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element maxOccurs="1" ref="label" />
<xs:element maxOccurs="unbounded" ref="group" />
<xs:element maxOccurs="unbounded" ref="header" />
<xs:element maxOccurs="unbounded" ref="title" />
<xs:element maxOccurs="unbounded" ref="image" />
<xs:element maxOccurs="unbounded" ref="navigation" />
<xs:element maxOccurs="unbounded" ref="data" />
</xs:choice>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
<!-- # Header element definition. # -->
<xs:element name="header">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<!-- # Navigation element definition. # -->
<xs:element name="navigation">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<!-- # Title element definition. # -->
<xs:element name="title">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="format" />
<xs:element ref="default" />
</xs:choice>
<xs:attribute name="source" type="xs:string" />
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
<!-- # Data element definitions. # -->
<xs:element name="data">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="label" />
<xs:element ref="format" />
<xs:element ref="default" />
</xs:choice>
<xs:attribute name="source" type="xs:string" />
<xs:attribute name="span" type="xs:string" />
<xs:attribute name="layout" type="xs:string" />
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="label" type="xs:string" />
<xs:element name="format" type="xs:string" />
<xs:element name="default" type="xs:string" />
<!-- # Image element definitions. # -->
<xs:element name="image">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element maxOccurs="1" ref="alt" />
<xs:element maxOccurs="1" ref="caption" />
<xs:element maxOccurs="1" ref="default" />
</xs:choice>
<xs:attribute name="source" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="alt">
<xs:complexType>
<xs:choice>
<xs:element ref="default" minOccurs="0" />
</xs:choice>
<xs:attribute name="source" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="caption">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element maxOccurs="1" ref="format" />
<xs:element maxOccurs="1" ref="default" />
</xs:choice>
<xs:attribute name="source" type="xs:string" />
</xs:complexType>
</xs:element>
<!-- # Infobox element definition. # -->
<!-- Serves as infobox container & delimiter. -->
<xs:element name="infobox">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element maxOccurs="unbounded" ref="group" />
<xs:element maxOccurs="unbounded" ref="panel" />
<xs:element maxOccurs="unbounded" ref="title" />
<xs:element maxOccurs="unbounded" ref="image" />
<xs:element maxOccurs="unbounded" ref="navigation" />
<xs:element maxOccurs="unbounded" ref="data" />
</xs:choice>
<xs:attribute name="layout">
<xs:simpleType>
<xs:restriction base="piInfoboxLayout" />
</xs:simpleType>
</xs:attribute>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="theme" type="xs:string" />
<xs:attribute name="theme-source" type="xs:string" />
<xs:attribute name="type" type="xs:string" />
<xs:attribute name="accent-color-source">
<xs:simpleType>
<xs:restriction base="piColor" />
</xs:simpleType>
</xs:attribute>
<xs:attribute name="accent-color-default">
<xs:simpleType>
<xs:restriction base="piColor" />
</xs:simpleType>
</xs:attribute>
<xs:attribute name="accent-color-text-source">
<xs:simpleType>
<xs:restriction base="piColor" />
</xs:simpleType>
</xs:attribute>
<xs:attribute name="accent-color-text-default">
<xs:simpleType>
<xs:restriction base="piColor" />
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
]=]
},
{
require('Module:XML/testcases/books/dom'),
unindent [=[
<catalog>
<book>
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book>
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book>
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
</catalog>
]=]
},
{
require('Module:XML/testcases/people/dom'),
unindent [=[
<people>
<person type="natural">
<![CDATA[
Just a CDATA tag that may contain anything, including XML code,
such as <tag>message</tag>.
Its content is extracted but not processed.
]]>
<!-- Just an example comment that will be ignored by the tree handler and processed by the other ones. -->
<name>Manoel</name>
<city>Palmas-TO</city>
</person>
<person type="natural">
<name>Breno</name>
<city>Palmas-TO</city>
</person>
<person type="legal">
<name>University of Brasília</name>
<city>Brasília-DF</city>
</person>
</people>
]=]
}
}
}
}