File: 0.9-strict.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 (193 lines) | stat: -rw-r--r-- 4,396 bytes parent folder | download | duplicates (3)
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/perl

# Test the strict mode of RSS 0.9 and RSS 0.91

use strict;
use warnings;

use Test::More tests => 12;

use XML::RSS;

sub item_throws_like
{
    local $Test::Builder::Level = $Test::Builder::Level + 1;
    my ($rss, $params, $regex, $msg) = @_;
    eval {
        $rss->add_item(@$params);
    };

    like ($@, $regex, $msg);
}

{
    my $rss = XML::RSS->new(version => "0.9");

    $rss->strict(1);

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

    # TEST
    item_throws_like($rss, [link => "http://foobar.tld/from/"], 
        qr{\Atitle and link elements are required},
        "strict - checking for exception on non-specified title"
    );

    # TEST
    item_throws_like($rss, [title => "From Foobar"], 
        qr{\Atitle and link elements are required},
        "strict - checking for exception on non-specified link"
    );

    # TEST
    item_throws_like($rss, [link => "http://foobar.tld/", 
        title => ("Very long title indeed" x 50)], 
        qr{\Atitle cannot exceed},
        "strict - checking for long title"
    );

    # TEST
    item_throws_like($rss, [
        link => "http://" . ("foobarminimoni" x 200) . ".tld/", 
        title => "Short Title"
        ], 
        qr{\Alink cannot exceed},
        "strict - checking for long link"
    );

    # TEST
    item_throws_like($rss, [
        link => "http://foobar.tld/from/", 
        title => "Short Title",
        description => ("This description is way too long!" x 100),
        ],
        qr{\Adescription cannot exceed},
        "strict - checking for a long description"
    );
}

{
    my $rss = XML::RSS->new(version => "0.9");

    $rss->strict(1);

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

    foreach my $i (1 .. 15)
    {
        $rss->add_item(
            link => "http://foobar.tld/item-$i",
            title => "Item $i",
        );
    }

    # TEST
    item_throws_like($rss, [
        link => "http://foobar.tld/from/", 
        title => "Short Title",
        description => "Good description",
        ],
        qr{\Atotal items cannot exceed},
        "strict - checking for too many items"
    );
}

{
    my $rss = XML::RSS->new(version => "0.9");

    $rss->strict(1);

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

    # TEST
    ok (1, "Can add unknown keys of unlimited size without restriction");

}

{
    my $rss = XML::RSS->new(version => "0.9");

    $rss->strict(1);

    eval {
        $rss->channel(
            title => "freshmeat.net",
            link  => "http://freshmeat.net",
            description => ("I think therefore I am." x 1000),
        );
    };

    # TEST
    like ($@, qr{\Adescription cannot exceed 500 characters in length},
        "Testing for exception thrown on a very long key"
    );
}

{
    my $rss = XML::RSS->new(version => "0.9");

    $rss->strict(1);

    eval {
        $rss->skipHours(
            hour => 5,
        );
    };

    # TEST
    like ($@, qr{\AUnregistered entity: Can't access skipHours field in object of class},
        "Testing for exception thrown on an unknown field"
    );
}

{
    my $rss = XML::RSS->new(version => "0.9");

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

    # TEST
    is ($rss->channel()->{title},
        "freshmeat.net",
        "Testing for an AUTOLOAD accessor with 0 arguments"
    );
    
    # TEST
    is ($rss->channel('title'),
        "freshmeat.net",
        "Testing for an AUTOLOAD accessor with 1 argument"
    );
}

{
    my $rss = XML::RSS->new(version => "0.91");

    $rss->strict(1);

    eval {
        $rss->skipDays(
            day => "FoolambdaCroakThemOfMonetaryJudgement"
        );
    };

    # TEST
    like ($@, qr{\Aday cannot exceed 10 characters in length},
        "Testing for exception thrown on a key for 0.91"
    );
}