Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added tests

  • Loading branch information...
commit b2d22f9186cc4da22f6693e55c1cd03baa67f65c 1 parent 2a3713b
Tatsuhiko Miyagawa authored June 08, 2011
58  t/31-external-entities-libxml.t
... ...
@@ -0,0 +1,58 @@
  1
+use strict;
  2
+use Test::More;
  3
+
  4
+use XML::Atom::Entry;
  5
+use FindBin;
  6
+my $filepath = "$FindBin::Bin/samples/entry-ns.xml";
  7
+
  8
+BEGIN {
  9
+    unless (eval { require XML::LibXML }) {
  10
+        plan skip_all => 'LibXML required for this test';
  11
+    }
  12
+}
  13
+plan tests => 4;
  14
+
  15
+my $xml = <<"EOX";
  16
+<?xml version="1.0" encoding="utf-8"?>
  17
+<!DOCTYPE entry [
  18
+<!ENTITY ref SYSTEM "file://$filepath">
  19
+]>
  20
+  <entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
  21
+    <title>Guest Author</title>
  22
+    <link rel="alternate" type="text/html" href="http://ben.stupidfool.org/typepad/2003/07/guest_author.html" />
  23
+    <link rel="service.edit" title="Edit" type="application/x.atom+xml" href="http://www.example.com/atom/entry_id=75207" />
  24
+    <id>tag:typepad.com:post:75207</id>
  25
+    <issued>2003-07-21T02:47:34-07:00</issued>
  26
+    <modified>2003-08-22T18:36:57-07:00</modified>
  27
+    <created>2003-07-21T02:47:34-07:00</created>
  28
+    <summary>No, Ben isn&apos;t updating. It&apos;s me testing out guest author functionality....</summary>
  29
+    <author>
  30
+      <name>Mena</name>
  31
+      <url>http://mena.typepad.com/</url>
  32
+    </author>
  33
+    <dc:subject>Food</dc:subject>
  34
+    <dc:subject>Cats</dc:subject>
  35
+    <content type="text/html" xml:lang="en-us">&ref;
  36
+<div xmlns="http://www.w3.org/1999/xhtml"><p>No, Ben isn't updating. It's me testing out guest author functionality.</p></div>
  37
+</content>
  38
+  </entry>
  39
+EOX
  40
+
  41
+## default sane parser
  42
+{
  43
+    my $entry = XML::Atom::Entry->new(Stream => \$xml);
  44
+    is $entry->title, "Guest Author", "got title";
  45
+    my $content = $entry->content->body;
  46
+    unlike $content, qr/This is what you get when you do unit testing/,
  47
+        "ignored entity";
  48
+}
  49
+
  50
+## custom parser
  51
+{
  52
+    my $libxml = XML::LibXML->new;
  53
+    my $entry = XML::Atom::Entry->new(Stream => \$xml, Parser => $libxml);
  54
+    is $entry->title, "Guest Author", "got title";
  55
+    my $content = $entry->content->body;
  56
+    like $content, qr/This is what you get when you do unit testing/,
  57
+        "resolved entity";
  58
+}
71  t/31-external-entities-xpath.t
... ...
@@ -0,0 +1,71 @@
  1
+use strict;
  2
+use Test::More;
  3
+
  4
+BEGIN {
  5
+    unless (eval { require XML::XPath }) {
  6
+        plan skip_all => 'XML::XPath required for this test';
  7
+    }
  8
+}
  9
+
  10
+plan tests => 4;
  11
+BEGIN {
  12
+    ## hardcore, because XML::Atom doesn't make it easy to change it at
  13
+    ## runtime
  14
+    require XML::Atom;
  15
+    if (XML::Atom->LIBXML) {
  16
+        no strict 'refs';
  17
+        diag "XPath Override in place";
  18
+        *{XML::Atom::LIBXML} = sub() {0};
  19
+    }
  20
+}
  21
+
  22
+use XML::Parser;
  23
+use XML::Atom::Entry;
  24
+use FindBin;
  25
+my $filepath = "$FindBin::Bin/samples/entry-ns.xml";
  26
+
  27
+my $xml = <<"EOX";
  28
+<?xml version="1.0" encoding="utf-8"?>
  29
+<!DOCTYPE entry [
  30
+<!ENTITY ref SYSTEM "file://$filepath">
  31
+]>
  32
+  <entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
  33
+    <title>Guest Author</title>
  34
+    <link rel="alternate" type="text/html" href="http://ben.stupidfool.org/typepad/2003/07/guest_author.html" />
  35
+    <link rel="service.edit" title="Edit" type="application/x.atom+xml" href="http://www.example.com/atom/entry_id=75207" />
  36
+    <id>tag:typepad.com:post:75207</id>
  37
+    <issued>2003-07-21T02:47:34-07:00</issued>
  38
+    <modified>2003-08-22T18:36:57-07:00</modified>
  39
+    <created>2003-07-21T02:47:34-07:00</created>
  40
+    <summary>No, Ben isn&apos;t updating. It&apos;s me testing out guest author functionality....</summary>
  41
+    <author>
  42
+      <name>Mena</name>
  43
+      <url>http://mena.typepad.com/</url>
  44
+    </author>
  45
+    <dc:subject>Food</dc:subject>
  46
+    <dc:subject>Cats</dc:subject>
  47
+    <content type="text/html" xml:lang="en-us">&ref;
  48
+<div xmlns="http://www.w3.org/1999/xhtml"><p>No, Ben isn't updating. It's me testing out guest author functionality.</p></div>
  49
+</content>
  50
+  </entry>
  51
+EOX
  52
+
  53
+## Sane default
  54
+{
  55
+    $DB::single = 1;
  56
+    my $entry = XML::Atom::Entry->new(Stream => \$xml);
  57
+    is $entry->title, "Guest Author", "got title";
  58
+    my $content = $entry->content->body;
  59
+    unlike $content, qr/This is what you get when you do unit testing/,
  60
+        "ignored entity";
  61
+}
  62
+
  63
+## custom parser
  64
+{
  65
+    my $parser = XML::Parser->new(); # no option
  66
+    my $entry = XML::Atom::Entry->new(Stream => \$xml, Parser => $parser);
  67
+    is $entry->title, "Guest Author", "got title";
  68
+    my $content = $entry->content->body;
  69
+    like $content, qr/This is what you get when you do unit testing/,
  70
+        "resolved entity";
  71
+}

0 notes on commit b2d22f9

Please sign in to comment.
Something went wrong with that request. Please try again.