File: subcategory.t

package info (click to toggle)
libxml-rss-perl 1.65-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 904 kB
  • sloc: perl: 7,189; xml: 379; makefile: 12
file content (123 lines) | stat: -rw-r--r-- 2,678 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
use strict;
use warnings;

use XML::RSS;

use Test::More;

if (eval "require Test::Differences") {
    Test::Differences->import;
    plan tests => 3;
}
else {
    plan skip_all => 'Test::Differences required';
}

my $simple_xml = <<EOF;
<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0"
 xmlns:blogChannel="http://backend.userland.com/blogChannelModule"
 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
>

<channel>
<title></title>
<link></link>
<description></description>
<itunes:category text="Technology"/>

</channel>
</rss>
EOF

my $sub_xml = <<EOF;
<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0"
 xmlns:blogChannel="http://backend.userland.com/blogChannelModule"
 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
>

<channel>
<title></title>
<link></link>
<description></description>
<itunes:category text="Technology">
<itunes:category text="Computers"/>
</itunes:category>

</channel>
</rss>
EOF

my $complex_xml = <<EOF;
<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0"
 xmlns:blogChannel="http://backend.userland.com/blogChannelModule"
 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
>

<channel>
<title></title>
<link></link>
<description></description>
<itunes:category text="Society &#x26; Culture">
<itunes:category text="History"/>
</itunes:category>
<itunes:category text="Technology">
<itunes:category text="Gadgets"/>
<itunes:category text="Computers"/>
<itunes:category text="News"/>
</itunes:category>

</channel>
</rss>
EOF

my $simple_rss  = XML::RSS->new(version => '2.0');
my $sub_rss     = XML::RSS->new(version => '2.0');
my $complex_rss = XML::RSS->new(version => '2.0');

foreach my $rss ($simple_rss, $sub_rss, $complex_rss) {
    $rss->add_module(
        prefix => 'itunes',
        uri    => 'http://www.itunes.com/dtds/podcast-1.0.dtd'
    );
}

$simple_rss->channel(itunes => {category => {text => 'Technology'}});

$sub_rss->channel(
    itunes => {
        category => {
            text     => 'Technology',
            category => {text => 'Computers'}
        }
    }
);

$complex_rss->channel(
    itunes => {
        category => [
            {   text     => 'Society & Culture',
                category => {text => 'History'}
            },
            {   text     => 'Technology',
                category => [{text => 'Gadgets'}, {text => 'Computers'}, {text => 'News'}]
            }
        ]
    }
);


# TEST
eq_or_diff($simple_rss->as_string . "\n", $simple_xml, 'Single category');

# TEST
eq_or_diff($sub_rss->as_string . "\n", $sub_xml, 'Subcategory');

# TEST
eq_or_diff($complex_rss->as_string . "\n", $complex_xml, 'Multiple categories with subcategoris');