Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jedupdate #3

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Set default behaviour, in case users don't have core.autocrlf set.
* text=auto
*.xml text
*.xsd text
*.dtd text
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ schemas
=======

Schemas for the Joomla! CMS

7 changes: 7 additions & 0 deletions xsd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

call validate like this

phpunit --bootstrap bootstrap.php validate.php



5 changes: 5 additions & 0 deletions xsd/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

// set this to a directory containing joomla
$joomla_root = "";
$joomla_version = "v3";
7 changes: 7 additions & 0 deletions xsd/jed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

call validate like this

phpunit validate.php



30 changes: 30 additions & 0 deletions xsd/jed/jedupdate-sample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<jedupdate version="1" xsi:noNamespaceSchemaLocation="./jedupdate.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<core_body>
An introduction text.

### a title
* a list entry
* another list entry

### another title
Some text.

</core_body>

<homepage_link>http://www.acme.com</homepage_link>
<download_link>https://www.acme.com/download/</download_link>
<demo_link>https://www.acme.com/demo/</demo_link>
<documentation_link>https://www.acme.com/doc/</documentation_link>
<support_link>https://www.acme.com/forums/</support_link>
<license_link>https://www.acme.com/licence/</license_link>

<version>1.0.0</version>

<compatibility>
<version>25</version>
<version>30</version>
</compatibility>
</jedupdate>
41 changes: 41 additions & 0 deletions xsd/jed/jedupdate.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

<xs:element name="jedupdate">
<xs:complexType>
<xs:all>
<xs:element name="core_body" type="xs:string"/>
<xs:element name="homepage_link" type="xs:anyURI"/>
<xs:element name="download_link" type="xs:anyURI"/>
<xs:element name="demo_link" type="xs:anyURI"/>
<xs:element name="documentation_link" type="xs:anyURI"/>
<xs:element name="support_link" type="xs:anyURI"/>
<xs:element name="license_link" type="xs:anyURI"/>
<xs:element name="version" type="xs:string"/>
<xs:element ref="compatibility"/>
</xs:all>
<xs:attribute name="version" use="required" type="jedupdateVersionType"/>
</xs:complexType>
</xs:element>

<xs:element name="compatibility">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="version"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="version" type="xs:string"/>

<xs:simpleType name="jedupdateVersionType">
<xs:annotation>
<xs:documentation xml:lang="en">This attribute describes the version.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="1"/>
</xs:restriction>
</xs:simpleType>

</xs:schema>
66 changes: 66 additions & 0 deletions xsd/jed/validate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

class validateJedUpdate extends PHPUnit_Framework_TestCase
{
protected $xml;

protected function setUp()
{
$this->xml = new DOMDocument();
libxml_use_internal_errors(true);
}

public function testValidate_forFileJedUpdateSample_expectValidTrue()
{
// Arrange
$jedupdates = array();
$jedupdates = dirname(__FILE__) . "/jedupdate-sample.xml";
$schema = dirname(__FILE__) . "/jedupdate.xsd";

// Act
foreach ($jedupdates as $jedupdate) {
$this->xml->load($jedupdate);
$schemaValidate = $this->xml->schemaValidate($schema);

// Assert
$this->libxml_display_errors();
$this->assertEquals(TRUE, $schemaValidate);
}
}

function libxml_display_error($error)
{
$return = "<br/>\n";
switch ($error->level) {
case LIBXML_ERR_WARNING:
$return .= "<b>Warning $error->code</b>: ";
break;
case LIBXML_ERR_ERROR:
$return .= "<b>Error $error->code</b>: ";
break;
case LIBXML_ERR_FATAL:
$return .= "<b>Fatal Error $error->code</b>: ";
break;
}
$return .= trim($error->message);
if ($error->file) {
$return .= " in <b>$error->file</b>";
}
$return .= " on line <b>$error->line</b>\n";

return $return;
}

private function libxml_display_errors()
{
$errors = libxml_get_errors();

self::$errors = self::$errors + sizeof($errors);

foreach ($errors as $error) {
print $this->libxml_display_error($error);
}
libxml_clear_errors();
}

}
Loading