PageRenderTime 24ms CodeModel.GetById 7ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/XML-FeedPP/t/22_init_elements.t

http://xml-treepp.googlecode.com/
Unknown | 111 lines | 111 code | 0 blank | 0 comment | 0 complexity | 4aa4ce37aa1c85b87386e59feccb6547 MD5 | raw file
  1# ----------------------------------------------------------------
  2    use strict;
  3    use Test::More tests => 74;
  4    BEGIN { use_ok('XML::FeedPP') };
  5# ----------------------------------------------------------------
  6    my $ftitle = 'Kawa.net XP';
  7    my $fdesc  = 'Description';
  8    my $fdateA = 'Mon, 02 Jan 2006 03:04:05 +0600';
  9    my $fdateB = '2006-01-02T03:04:05+06:00';
 10    my $fright = 'Owner';
 11    my $flink  = 'http://www.kawa.net/';
 12    my $flang  = 'ja';
 13    my $forgkey = 'hoge:pomu';
 14    my $forgval = 'Original Namespace: hoge';
 15# ----------------------------------------------------------------
 16    my $ilink1  = 'http://kawa.at.webry.info/';
 17    my $ilink2  = 'http://kawanet.blogspot.com/';
 18    my $ilink3  = 'http://picasaweb.google.com/www.kawa.net/';
 19    my $ititle1 = 'Kawa.net Blog (ja)';
 20    my $ititle2 = 'Kawa.net Blog (en)';
 21    my $ititle3 = 'Kawa.net Albums';
 22    my $idateA  = 'Sun, 11 Dec 2005 10:09:08 -0700';
 23    my $idateB  = '2005-12-11T10:09:08-07:00';
 24    my $idesc   = 'Description';
 25    my $icate   = 'Category';
 26    my $iauthor = 'Author';
 27    my $iguid   = 'GUID';
 28    my $iorgkey = 'foo:bar';
 29    my $iorgval = 'Original Namespace: foo';
 30# ----------------------------------------------------------------
 31    my $initfeed = {
 32        title       =>  $ftitle,
 33        description =>  $fdesc,
 34        pubDate     =>  $fdateA,
 35        copyright   =>  $fright,
 36        link        =>  $flink,
 37        language    =>  $flang,
 38        $forgkey    =>  $forgval,
 39    };
 40# ----------------------------------------------------------------
 41    my $initem1 = {
 42        link        =>  $ilink1,
 43        title       =>  $ititle1,
 44        pubDate     =>  $idateA,
 45        description =>  $idesc,
 46        category    =>  $icate,
 47        author      =>  $iauthor,
 48        guid        =>  $iguid,
 49        $iorgkey    =>  $iorgval,
 50    };
 51# ----------------------------------------------------------------
 52    my $initem2 = {
 53        link        =>  $ilink2,
 54        title       =>  $ititle2,
 55        pubDate     =>  $idateB,
 56    };
 57# ----------------------------------------------------------------
 58    my $initem3 = {
 59        link        =>  $ilink3,
 60        title       =>  $ititle3,
 61        pubDate     =>  $idateA,
 62    };
 63# ----------------------------------------------------------------
 64    my $feeds = [
 65        XML::FeedPP::RSS->new( %$initfeed ),
 66        XML::FeedPP::RDF->new( %$initfeed ),
 67        XML::FeedPP::Atom->new( %$initfeed ),
 68    ];
 69# ----------------------------------------------------------------
 70    foreach my $feed1 ( @$feeds ) {
 71        my $type = ref $feed1;
 72        ok( 0 == $feed1->get_item(), "$type Feed has no item" );
 73        my $item1 = $feed1->add_item( %$initem1 );
 74        ok( 1 == $feed1->get_item(), "$type Feed has one item" );
 75        my $item2 = $feed1->add_item( %$initem2 );
 76        ok( 2 == $feed1->get_item(), "$type Feed has two items" );
 77        my $item3 = $feed1->add_item( %$initem3 );
 78        ok( 3 == $feed1->get_item(), "$type Feed has three items" );
 79# ----------------------------------------------------------------
 80        is( $feed1->title(),            $ftitle,    "$type Feed title()" );
 81        is( $feed1->description(),      $fdesc,     "$type Feed description()" );
 82        is( $feed1->pubDate(),          $fdateB,    "$type Feed pubDate()" );
 83        is( $feed1->copyright(),        $fright,    "$type Feed copyright()" );
 84        is( $feed1->link(),             $flink,     "$type Feed link()" );
 85        is( $feed1->language(),         $flang,     "$type Feed language()" );
 86        is( $feed1->get($forgkey),      $forgval,   "$type Feed set/get()" );
 87# ----------------------------------------------------------------
 88        is( $item1->link(),             $ilink1,    "$type Item1 link()" );
 89        is( $item1->title(),            $ititle1,   "$type Item1 title()" );
 90        is( $item1->get_pubDate_w3cdtf(), $idateB,  "$type Item1 pubDate()" );
 91        is( $item1->description(),      $idesc,     "$type Item1 description()" );
 92        is( $item1->author(),           $iauthor,   "$type Item1 author()" );
 93        is( $item1->get($iorgkey),      $iorgval,   "$type Item1 set/get()" );
 94        if ( $type ne 'XML::FeedPP::Atom' ) {
 95            is( $item1->category(),     $icate,     "$type Item1 category()" );
 96        }
 97        if ( $type ne 'XML::FeedPP::RDF' ) {
 98            is( $item1->guid(),         $iguid ,    "$type Item1 guid()" );
 99        }
100# ----------------------------------------------------------------
101        is( $item2->link(),             $ilink2,    "$type Item2 link()" );
102        is( $item2->title(),            $ititle2,   "$type Item2 title()" );
103        is( $item2->get_pubDate_rfc1123(), $idateA, "$type Item2 pubDate()" );
104# ----------------------------------------------------------------
105        is( $item3->link(),             $ilink3,    "$type Item3 link()" );
106        is( $item3->title(),            $ititle3,   "$type Item3 title()" );
107        is( $item3->get_pubDate_rfc1123(), $idateA, "$type Item3 pubDate()" );
108}
109# ----------------------------------------------------------------
110;1;
111# ----------------------------------------------------------------