File: xml-header.t

package info (click to toggle)
libxml-rss-perl 1.49-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 768 kB
  • sloc: perl: 6,894; xml: 378; makefile: 8
file content (174 lines) | stat: -rw-r--r-- 3,675 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 8;

use XML::RSS;

sub starts_with
{
    local $Test::Builder::Level = $Test::Builder::Level + 1;
    my ($rss, $prefix, $msg) = @_;
    
    my $rss_output = $rss->as_string();
    my $ok = is (
        substr($rss_output, 0, length($prefix)-1),
        substr($prefix, 0, length($prefix)-1),
        $msg
    );
}

sub create_rss_1
{
    my $args = shift;
    my @style =
        exists($args->{stylesheet}) ? 
            (stylesheet => $args->{stylesheet}) :
            ()
            ;
    my $rss = XML::RSS->new(
        version => $args->{version},
        @style
    );
    my $image_link = exists($args->{image_link}) ? $args->{image_link} : 
        "http://freshmeat.net/";

    my $extra_image_params = $args->{image_params} || [];

    $rss->channel(
        title => "freshmeat.net",
        link  => "http://freshmeat.net",
        description => "the one-stop-shop for all your Linux software needs",
        );

    $rss->image(
        title => "freshmeat.net",
        url   => "0",
        link  => $image_link,
        @{$extra_image_params},
        );

    $rss->add_item(
        title => "GTKeyboard 0.85",
        link  => "http://freshmeat.net/news/1999/06/21/930003829.html"
        );

    return $rss;
}

{
    # TEST
    starts_with(
        create_rss_1({'version' => "0.9"}),
        <<'EOF',
<?xml version="1.0" encoding="UTF-8"?>

<rdf:RDF
EOF
        "header of RSS 0.9 without the stylesheet"
    );
}

{
    # TEST
    starts_with(
        create_rss_1({'version' => "0.91"}),
        <<'EOF',
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN"
            "http://www.rssboard.org/rss-0.91.dtd">

<rss version="0.91">
EOF
        "header of RSS 0.9.1 without the stylesheet"
    );
}


{
    # TEST
    starts_with(
        create_rss_1({'version' => "1.0"}),
        <<'EOF',
<?xml version="1.0" encoding="UTF-8"?>

<rdf:RDF
EOF
        "header of RSS 1.0 without the stylesheet"
    );
}

{
    # TEST
    starts_with(
        create_rss_1({'version' => "2.0"}),
        <<'EOF',
<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0"
EOF
        "header of RSS 2.0 without the stylesheet"
    );
}

{
    # TEST
    starts_with(
        create_rss_1({'version' => "0.9", stylesheet => "http://myhost.tld/foo.xsl"}),
        <<'EOF',
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="http://myhost.tld/foo.xsl"?>

<rdf:RDF
EOF
        "header of RSS 0.9 with the stylesheet"
    );
}

{
    # TEST
    starts_with(
        create_rss_1({'version' => "0.91", stylesheet => "http://myhost.tld/foo.xsl"}),
        <<'EOF',
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="http://myhost.tld/foo.xsl"?>

<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN"
            "http://www.rssboard.org/rss-0.91.dtd">

<rss version="0.91">
EOF
        "header of RSS 0.9.1 with the stylesheet"
    );
}

{
    # TEST
    starts_with(
        create_rss_1({'version' => "1.0", stylesheet => "http://myhost.tld/foo.xsl"}),
        <<'EOF',
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="http://myhost.tld/foo.xsl"?>

<rdf:RDF
EOF
        "header of RSS 1.0 without the stylesheet"
    );
}

{
    # TEST
    starts_with(
        create_rss_1({'version' => "2.0", stylesheet => "http://myhost.tld/foo.xsl"}),
        <<'EOF',
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="http://myhost.tld/foo.xsl"?>

<rss version="2.0"
EOF
        "header of RSS 2.0 without the stylesheet"
    );
}