1# ---------------------------------------------------------------- 2 use strict; 3 use Test::More tests => 14; 4 BEGIN { use_ok('XML::FeedPP') }; 5# ---------------------------------------------------------------- 6 &test_main(); 7# ---------------------------------------------------------------- 8sub test_main { 9 my $feed = XML::FeedPP::RSS->new(); 10 11 my $link0 = 'http://www.example.com/'; 12 my $link1 = 'http://www.example.com/sample1.html'; 13 my $link2 = 'http://www.example.com/sample2.html'; 14 my $link3 = 'http://www.example.com/sample3.html'; 15 my $title0 = 'sample channel'; 16 my $title1 = 'sample item 1'; 17 my $title2 = 'sample item 2'; 18 my $title3 = 'sample item 3'; 19 20 $feed->title( $title0 ); 21 is( $feed->title, $title0, 'feed title' ); 22 23 $feed->link( $link0 ); 24 is( $feed->link, $link0, 'feed link' ); 25 26 # default when missing 27 my $item1 = $feed->add_item( $link1 ); 28 is( $item1->link, $link1, 'item 1 link' ); 29 $item1->guid( $link1 ); 30 is( $item1->guid, $link1, 'guid without arguments' ); 31 is( $item1->{guid}->{-isPermaLink}, 'true', 'isPermaLink without arguments' ); 32 33 # old behavior 34 my $item2 = $feed->add_item( $link2 ); 35 is( $item2->link, $link2, 'item 2 link' ); 36 $item2->guid( $link2, 'false' ); 37 is( $item2->guid, $link2, 'guid with an argument' ); 38 is( $item2->{guid}->{-isPermaLink}, 'false', 'isPermaLink with an argument' ); 39 40 # documented behavior 41 my $item3 = $feed->add_item( $link3 ); 42 is( $item3->link, $link3, 'item 3 link' ); 43 $item3->guid( $link3, isPermaLink => 'false' ); 44 is( $item3->guid, $link3, 'guid with an argument' ); 45 is( $item3->{guid}->{-isPermaLink}, 'false', 'isPermaLink with arguments' ); 46 47 my $out = $feed->to_string(); 48 my $cnt = {}; 49 while ( $out =~ m#<guid isPermaLink="(\w+)">#g ) { 50 $cnt->{$1} ||= 0; 51 $cnt->{$1} ++; 52 } 53 is( $cnt->{true}, 1, 'isPermaLink true 1' ); 54 is( $cnt->{false}, 2, 'isPermaLink false 2' ); 55} 56# ---------------------------------------------------------------- 57