File: 04_atom.t

package info (click to toggle)
libxml-feedpp-perl 0.95-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 400 kB
  • sloc: perl: 1,877; sh: 28; makefile: 2
file content (247 lines) | stat: -rw-r--r-- 13,700 bytes parent folder | download | duplicates (4)
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# ----------------------------------------------------------------
    use strict;
    use Test::More tests => 94;
    BEGIN { use_ok('XML::FeedPP') };
# ----------------------------------------------------------------
    my $ftitle = "Title of the site";
    my $fdesc  = "Description of the site";
    my $fdateA = "Mon, 02 Jan 2006 03:04:05 +0600";
    my $fdateB = "2006-01-02T03:04:05+06:00";
    my $fright = "Owner of the site";
    my $flink  = "http://www.kawa.net/";
    my $flang  = "ja";
# ----------------------------------------------------------------
    my $link1 = "http://www.perl.org/";
    my $link2  = "http://use.perl.org/";
    my $link3 = "http://cpan.perl.org/";
    my $title1 = "The Perl Directory - perl.org";
    my $title2 = "use Perl: All the Perl that's Practical to Extract and Report";
    my $title3 = "The Comprehensive Perl Archive Network";
# ----------------------------------------------------------------
    my $idesc  = "Description of the first item";
    my $icate  = "Category of the first item";
    my $idateA = "Sun, 11 Dec 2005 10:09:08 -0700";
    my $idateB = "2005-12-11T10:09:08-07:00";
    my $iauthor = "Author";
    my $iguid   = "GUID";
# ----------------------------------------------------------------
#   Atom (default version)
# ----------------------------------------------------------------
    my $feed1 = XML::FeedPP::Atom->new();
    $feed1->title( $ftitle );
    $feed1->description( $fdesc );
    $feed1->pubDate( $fdateB );
    $feed1->copyright( $fright );
    $feed1->link( $flink );
    $feed1->language( $flang );
# ----------------------------------------------------------------
    ok( 0 == $feed1->get_item(), "0 item" );
# ----------------------------------------------------------------
    my $item1 = $feed1->add_item( $link1 );
    $item1->title( $title1 );
    $item1->pubDate( $idateB );
    ok( 1 == $feed1->get_item(), "1 item" );
# ----------------------------------------------------------------
    $item1->description( $idesc );
    $item1->category( $icate );
    $item1->author( $iauthor, isPermaLink => "false" );
    $item1->guid( $iguid );
# ----------------------------------------------------------------
    my $item2 = $feed1->add_item( $link2 );
    $item2->title( $title2 );
    $item2->pubDate( $idateA );
    ok( 2 == $feed1->get_item(), "2 items" );
# ----------------------------------------------------------------
    my $item3 = $feed1->add_item( $link3 );
    $item3->title( $title3 );
    $item3->pubDate( $idateA );
    ok( 3 == $feed1->get_item(), "3 items" );
# ----------------------------------------------------------------
    my $source1 = $feed1->to_string();
    my $feed2 = XML::FeedPP::Atom->new( $source1 );
    ok( 3 == $feed2->get_item(), "3 items" );
# ----------------------------------------------------------------
    is( $feed2->title(),            $ftitle,    "Atom->title()" );
    is( $feed2->description(),      $fdesc,     "Atom->description()" );
    is( $feed2->pubDate(),          $fdateB,    "Atom->pubDate()" );
    is( $feed2->copyright(),        $fright,    "Atom->copyright()" );
    is( $feed2->link(),             $flink,     "Atom->link()" );
    is( $feed2->language(),         $flang,     "Atom->language()" );
# ----------------------------------------------------------------
    my $item4 = $feed2->get_item( 0 );
# ----------------------------------------------------------------
    is( $item4->link(),             $link1,     "Entry->link()" );
    is( $item4->title(),            $title1,    "Entry->title()" );
    is( $item4->pubDate(),          $idateB,    "Entry->pubDate()" );
    is( $item4->description(),      $idesc,     "Entry->description()" );
    is( $item4->category(),         undef,      "Entry->category()" );
    is( $item4->author(),           $iauthor,   "Entry->author()" );
    is( $item4->guid(),             $iguid,     "Entry->guid()" );
# ----------------------------------------------------------------
    my $source2 = $feed1->to_string();
#   warn "\n$source2\n";
    is( $source1, $source2, "turn around - rss source." );
# ----------------------------------------------------------------
    like( $source2, qr/<title[^>]*>\s*      \Q$ftitle\E/x,  "<title>" );
    like( $source2, qr/<tagline[^>]*>\s*    \Q$fdesc\E/x,   "<tagline>" );
    like( $source2, qr/<modified[^>]*>\s*   \Q$fdateB\E/x,  "<modified>" );
    like( $source2, qr/<copyright[^>]*>\s*  \Q$fright\E/x,  "<copyright>" );
    like( $source2, qr/<link[^>]*     href="\Q$flink\E/x,   '<link href="">' );
    like( $source2, qr/<feed[^>]* xml:lang="\Q$flang\E/x,   '<feed xml:lang="">' );
# ----------------------------------------------------------------
    like( $source2, qr/<link[^>]*           href="\Q$link1\E/x,   '<link href="">' );
    like( $source2, qr/<title[^>]*>\s*            \Q$title1\E/x,  "<title>" );
    like( $source2, qr/<issued[^>]*>\s*           \Q$idateB\E/x,  "<issued>" );
    like( $source2, qr/<content[^>]*>\s*          \Q$idesc\E/x,   "<content>" );
#   like( $source2, qr/<category[^>]*>\s*         \Q$icate\E/x,   "<category>" );
    like( $source2, qr/<name[^>]*>\s*             \Q$iauthor\E/x, "<author><name>" );
    like( $source2, qr/<id[^>]*>\s*               \Q$iguid\E/x,   "<id>" );
# ----------------------------------------------------------------
#   Atom 0.3
# ----------------------------------------------------------------
    $feed1 = XML::FeedPP::Atom::Atom03->new();
    $feed1->title( $ftitle );
    $feed1->description( $fdesc );
    $feed1->pubDate( $fdateB );
    $feed1->copyright( $fright );
    $feed1->link( $flink );
    $feed1->language( $flang );
# ----------------------------------------------------------------
    ok( 0 == $feed1->get_item(), "0 item" );
# ----------------------------------------------------------------
    $item1 = $feed1->add_item( $link1 );
    $item1->title( $title1 );
    $item1->pubDate( $idateB );
    ok( 1 == $feed1->get_item(), "1 item" );
# ----------------------------------------------------------------
    $item1->description( $idesc );
    $item1->category( $icate );
    $item1->author( $iauthor, isPermaLink => "false" );
    $item1->guid( $iguid );
# ----------------------------------------------------------------
    $item2 = $feed1->add_item( $link2 );
    $item2->title( $title2 );
    $item2->pubDate( $idateA );
    ok( 2 == $feed1->get_item(), "2 items" );
# ----------------------------------------------------------------
    $item3 = $feed1->add_item( $link3 );
    $item3->title( $title3 );
    $item3->pubDate( $idateA );
    ok( 3 == $feed1->get_item(), "3 items" );
# ----------------------------------------------------------------
    $source1 = $feed1->to_string();
    $feed2 = XML::FeedPP::Atom::Atom03->new( $source1 );
    ok( 3 == $feed2->get_item(), "3 items" );
# ----------------------------------------------------------------
    is( $feed2->title(),            $ftitle,    "Atom->title()" );
    is( $feed2->description(),      $fdesc,     "Atom->description()" );
    is( $feed2->pubDate(),          $fdateB,    "Atom->pubDate()" );
    is( $feed2->copyright(),        $fright,    "Atom->copyright()" );
    is( $feed2->link(),             $flink,     "Atom->link()" );
    is( $feed2->language(),         $flang,     "Atom->language()" );
# ----------------------------------------------------------------
    $item4 = $feed2->get_item( 0 );
# ----------------------------------------------------------------
    is( $item4->link(),             $link1,     "Entry->link()" );
    is( $item4->title(),            $title1,    "Entry->title()" );
    is( $item4->pubDate(),          $idateB,    "Entry->pubDate()" );
    is( $item4->description(),      $idesc,     "Entry->description()" );
    is( $item4->category(),         undef,      "Entry->category()" );
    is( $item4->author(),           $iauthor,   "Entry->author()" );
    is( $item4->guid(),             $iguid,     "Entry->guid()" );
# ----------------------------------------------------------------
    $source2 = $feed1->to_string();
#   warn "\n$source2\n";
    is( $source1, $source2, "turn around - rss source." );
# ----------------------------------------------------------------
    like( $source2, qr/<title[^>]*>\s*      \Q$ftitle\E/x,  "<title>" );
    like( $source2, qr/<tagline[^>]*>\s*    \Q$fdesc\E/x,   "<tagline>" );
    like( $source2, qr/<modified[^>]*>\s*   \Q$fdateB\E/x,  "<modified>" );
    like( $source2, qr/<copyright[^>]*>\s*  \Q$fright\E/x,  "<copyright>" );
    like( $source2, qr/<link[^>]*     href="\Q$flink\E/x,   '<link href="">' );
    like( $source2, qr/<feed[^>]* xml:lang="\Q$flang\E/x,   '<feed xml:lang="">' );
# ----------------------------------------------------------------
    like( $source2, qr/<link[^>]*           href="\Q$link1\E/x,   '<link href="">' );
    like( $source2, qr/<title[^>]*>\s*            \Q$title1\E/x,  "<title>" );
    like( $source2, qr/<issued[^>]*>\s*           \Q$idateB\E/x,  "<issued>" );
    like( $source2, qr/<content[^>]*>\s*          \Q$idesc\E/x,   "<content>" );
#   like( $source2, qr/<category[^>]*>\s*         \Q$icate\E/x,   "<category>" );
    like( $source2, qr/<name[^>]*>\s*             \Q$iauthor\E/x, "<author><name>" );
    like( $source2, qr/<id[^>]*>\s*               \Q$iguid\E/x,   "<id>" );
# ----------------------------------------------------------------
#   Atom 1.0
# ----------------------------------------------------------------
    $feed1 = XML::FeedPP::Atom::Atom10->new();
    $feed1->title( $ftitle );
    $feed1->description( $fdesc );
    $feed1->pubDate( $fdateB );
    $feed1->copyright( $fright );
    $feed1->link( $flink );
    $feed1->language( $flang );
# ----------------------------------------------------------------
    ok( 0 == $feed1->get_item(), "0 item" );
# ----------------------------------------------------------------
    $item1 = $feed1->add_item( $link1 );
    $item1->title( $title1 );
    $item1->pubDate( $idateB );
    ok( 1 == $feed1->get_item(), "1 item" );
# ----------------------------------------------------------------
    $item1->description( $idesc );
    $item1->category( $icate );
    $item1->author( $iauthor, isPermaLink => "false" );
    $item1->guid( $iguid );
# ----------------------------------------------------------------
    $item2 = $feed1->add_item( $link2 );
    $item2->title( $title2 );
    $item2->pubDate( $idateA );
    ok( 2 == $feed1->get_item(), "2 items" );
# ----------------------------------------------------------------
    $item3 = $feed1->add_item( $link3 );
    $item3->title( $title3 );
    $item3->pubDate( $idateA );
    ok( 3 == $feed1->get_item(), "3 items" );
# ----------------------------------------------------------------
    $source1 = $feed1->to_string();
    $feed2 = XML::FeedPP::Atom::Atom10->new( $source1 );
    ok( 3 == $feed2->get_item(), "3 items" );
# ----------------------------------------------------------------
    is( $feed2->title(),            $ftitle,    "Atom->title()" );
    is( $feed2->description(),      $fdesc,     "Atom->description()" );
    is( $feed2->pubDate(),          $fdateB,    "Atom->pubDate()" );
    is( $feed2->copyright(),        $fright,    "Atom->copyright()" );
    is( $feed2->link(),             $flink,     "Atom->link()" );
    is( $feed2->language(),         $flang,     "Atom->language()" );
# ----------------------------------------------------------------
    $item4 = $feed2->get_item( 0 );
# ----------------------------------------------------------------
    is( $item4->link(),             $link1,     "Entry->link()" );
    is( $item4->title(),            $title1,    "Entry->title()" );
    is( $item4->pubDate(),          $idateB,    "Entry->pubDate()" );
    is( $item4->description(),      $idesc,     "Entry->description()" );
    is( $item4->category(),         $icate,     "Entry->category()" );
    is( $item4->author(),           $iauthor,   "Entry->author()" );
    is( $item4->guid(),             $iguid,     "Entry->guid()" );
# ----------------------------------------------------------------
    $source2 = $feed1->to_string();
#   warn "\n$source2\n";
    is( $source1, $source2, "turn around - rss source." );
# ----------------------------------------------------------------
    like( $source2, qr/<title[^>]*>\s*      \Q$ftitle\E/x,  "<title>" );
#   like( $source2, qr/<subtitle[^>]*>\s*   \Q$fdesc\E/x,  "<subtitle>" );
    like( $source2, qr/<content[^>]*>\s*    \Q$fdesc\E/x,  "<content>" );
    like( $source2, qr/<updated[^>]*>\s*    \Q$fdateB\E/x,  "<updated>" );
    like( $source2, qr/<rights[^>]*>\s*     \Q$fright\E/x,  "<rights>" );
    like( $source2, qr/<link[^>]*     href="\Q$flink\E/x,   '<link href="">' );
    like( $source2, qr/<feed[^>]* xml:lang="\Q$flang\E/x,   '<feed xml:lang="">' );
# ----------------------------------------------------------------
    like( $source2, qr/<link[^>]*           href="\Q$link1\E/x,   '<link href="">' );
    like( $source2, qr/<title[^>]*>\s*            \Q$title1\E/x,  "<title>" );
#   like( $source2, qr/<published[^>]*>\s*        \Q$idateB\E/x,  "<published>" );
    like( $source2, qr/<updated[^>]*>\s*          \Q$idateB\E/x,  "<updated>" );
    like( $source2, qr/<content[^>]*>\s*          \Q$idesc\E/x,   "<content>" );
#   like( $source2, qr/<category[^>]*>\s*         \Q$icate\E/x,   "<category>" );
    like( $source2, qr/<name[^>]*>\s*             \Q$iauthor\E/x, "<author><name>" );
    like( $source2, qr/<id[^>]*>\s*               \Q$iguid\E/x,   "<id>" );
# ----------------------------------------------------------------
;1;
# ----------------------------------------------------------------