Commits

Shlomi Fish committed f87e648

Add the modified patch from https://rt.cpan.org/Ticket/Display.html?id=63655 .

Regarding the failing test in the Relax-NG validation due to namespaces.

As reported by OPERA@cpan.org.

Comments (0)

Files changed (3)

 test/relaxng/demo3.rng
 test/relaxng/demo4.rng
 test/relaxng/invaliddemo.xml
+test/relaxng/ns.rng
 test/relaxng/schema.rng
 test/schema/badschema.xsd
 test/schema/demo.xml
     use XML::LibXML;
 
     if ( XML::LibXML::LIBXML_VERSION >= 20510 ) {
-        plan tests => 13;
+        plan tests => 17;
     }
     else {
         plan skip_all => 'Skip No RNG Support compiled';
 my $validfile    = "test/relaxng/demo.xml";
 my $invalidfile  = "test/relaxng/invaliddemo.xml";
 my $demo4        = "test/relaxng/demo4.rng";
+my $namespace    = "test/relaxng/ns.rng";
 
 print "# 1 parse schema from a file\n";
 {
 
 }
 
+# 6 re-validate a modified document
+{
+    my $parser = new XML::LibXML();
+
+    my $rngschema = XML::LibXML::RelaxNG->new(location => $namespace);
+    my $doc = $parser->parse_string(<<EOD);
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE datastore SYSTEM "//test/test/datastore" [
+<!ATTLIST element id ID #IMPLIED>
+]>
+<!-- datastore -->
+<datastore xmlns="http://xmlns.example.com/2007/test/datastore">
+  <data>
+    <active>
+      <element id="uuidtest1">
+        <title>Ze element</title>
+        <payload>Ze element payload</payload>
+      </element>
+    </active>
+  </data>
+</datastore>
+EOD
+    eval{$rngschema->validate($doc);}; 
+    # TEST
+    ok (!$@);
+
+    my $node = $doc->createElement("element");
+
+    my $title = $doc->createElement("title");
+    $title->appendText("Annoying tests are annoying");
+    $node->appendChild($title);
+
+    my $payload = $doc->createElement("payload");
+    $payload->appendText("some payload");
+    $node->appendChild($payload);
+
+    $node->setAttribute('id', 'uuidIamAtestElement');
+
+    my ($active) = $doc->getElementsByTagName("active");
+    eval{$rngschema->validate($doc);}; 
+    # TEST
+    ok (!$@);
+    $active->appendChild($node);
+
+    # If there's a bug in the dynamically-generated content, this test
+    # will always fail no matter what. Hence, we reparse the document
+    # and validate that (that always works) to make sure our
+    # modifications are really valid
+    my $reparsed_doc = $parser->parse_string($doc->toString);
+    eval{$rngschema->validate($reparsed_doc);}; 
+    # TEST
+    ok (!$@);
+
+    eval{$rngschema->validate($doc);}; 
+    # TEST
+    ok (!$@);
+}
+
 
 } # Version >= 20510 test 

test/relaxng/ns.rng

+<?xml version="1.0" encoding="UTF-8"?>
+<!-- grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" -->
+<grammar ns="http://xmlns.example.com/2007/test/datastore" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+  <!-- Document -->
+  <start>
+    <ref name="Datastore"/>
+  </start>
+  <define name="Datastore">
+    <element name="datastore">
+      <ref name="Data"/>
+    </element>
+  </define>
+  <define name="Data">
+    <element name="data">
+      <ref name="Active"/>
+    </element>
+  </define>
+  <!-- Structure elements -->
+  <define name="Active">
+    <element name="active">
+      <choice>
+        <interleave>
+          <zeroOrMore>
+            <ref name="Element"/>
+          </zeroOrMore>
+        </interleave>
+        <empty/>
+      </choice>
+    </element>
+  </define>
+  <define name="Element">
+    <element name="element">
+      <choice>
+        <ref name="Id"/>
+        <ref name="Did"/>
+      </choice>
+      <interleave>
+        <optional>
+          <ref name="Title"/>
+        </optional>
+        <optional>
+          <ref name="Payload"/>
+        </optional>
+      </interleave>
+    </element>
+  </define>
+
+  <!-- Simple elements -->
+  <define name="Title">
+    <element name="title">
+      <data type="token"/>
+    </element>
+  </define>
+  <define name="Payload">
+    <element name="payload">
+      <data type="token"/>
+    </element>
+  </define>
+  <!-- Attributes -->
+  <define name="Id">
+    <attribute name="id">
+      <data type="ID"/>
+    </attribute>
+  </define>
+  <define name="Did">
+    <attribute name="did">
+      <data type="token"/>
+    </attribute>
+  </define>
+</grammar>