PageRenderTime 33ms CodeModel.GetById 8ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 0ms

/XML-FeedPP/t/45_cdata_multi.t

http://xml-treepp.googlecode.com/
Unknown | 53 lines | 50 code | 3 blank | 0 comment | 0 complexity | a8fd2f351e50743bb58fd28bbe04d6c4 MD5 | raw file
 1# ----------------------------------------------------------------
 2    use strict;
 3    use Test::More tests => 23;
 4    BEGIN { use_ok('XML::FeedPP') };
 5# ----------------------------------------------------------------
 6    my $url = "http://www.kawa.net/";
 7    my $cate1 = "hoge";
 8    my $cate2 = "pomu";
 9    my $cate3 = "foobar";
10    my $catem = [ \$cate1, \$cate2, \$cate3 ];
11    my $caten = scalar @$catem;
12# ----------------------------------------------------------------
13    my $feed0 = XML::FeedPP::RSS->new();
14    $feed0->link( $url );
15    my $item0 = $feed0->add_item( $url );
16    $item0->category( $catem );
17    ok( ref $item0->category(), "init multi ref" );
18    my $source = $feed0->to_string();
19    like( $source, qr/><!\[CDATA\[\Q$cate1\E\]\]></s, "init multi 1/3" );
20    like( $source, qr/><!\[CDATA\[\Q$cate2\E\]\]></s, "init multi 2/3" );
21    like( $source, qr/><!\[CDATA\[\Q$cate3\E\]\]></s, "init multi 3/3" );
22# ----------------------------------------------------------------
23    my $feeds = [
24        XML::FeedPP::RDF->new(),
25        XML::FeedPP::RSS->new(),
26#       XML::FeedPP::Atom::Atom10->new(),   # Atom 1.0's <category> doesn't use CDATA
27    ];
28# ----------------------------------------------------------------
29    foreach my $feed1 ( @$feeds ) {
30        my $type = ref $feed1;
31        $feed1->merge( $source );
32        my $item1 = $feed1->get_item(0);
33        my $icate = $item1->category();
34        ok( ref $icate, "$type load ref" );
35        is( scalar @$icate, $caten, "$type load count" );
36
37        $item1->category( \$cate1 );
38        is( $item1->category(), $cate1, "$type one" );
39        like( $feed1->to_string(), qr/><!\[CDATA\[\Q$cate1\E\]\]></s, "$type one source" );
40
41        $item1->category( $catem );
42        my $jcate = $item1->category();
43        ok( ref $jcate, "$type multi ref" );
44        is( scalar @$jcate, $caten, "$type multi count" );
45
46        $source = $feed1->to_string();
47        like( $source, qr/><!\[CDATA\[\Q$cate1\E\]\]></s, "$type multi 1/3" );
48        like( $source, qr/><!\[CDATA\[\Q$cate2\E\]\]></s, "$type multi 2/3" );
49        like( $source, qr/><!\[CDATA\[\Q$cate3\E\]\]></s, "$type multi 3/3" );
50    }
51# ----------------------------------------------------------------
52;1;
53# ----------------------------------------------------------------