/XML-FeedPP/t/03_rdf.t

http://xml-treepp.googlecode.com/ · Raku · 98 lines · 95 code · 0 blank · 3 comment · 0 complexity · 1ed67b0e5eca8a5ce803a99cc7e67c97 MD5 · raw file

  1. # ----------------------------------------------------------------
  2. use strict;
  3. use Test::More tests => 32;
  4. BEGIN { use_ok('XML::FeedPP') };
  5. # ----------------------------------------------------------------
  6. my $ftitle = "Title of the site";
  7. my $fdesc = "Description of the site";
  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 of the site";
  11. my $flink = "http://www.kawa.net/";
  12. my $flang = "ja";
  13. # ----------------------------------------------------------------
  14. my $link1 = "http://www.perl.org/";
  15. my $link2 = "http://use.perl.org/";
  16. my $link3 = "http://cpan.perl.org/";
  17. my $title1 = "The Perl Directory - perl.org";
  18. my $title2 = "use Perl: All the Perl that's Practical to Extract and Report";
  19. my $title3 = "The Comprehensive Perl Archive Network";
  20. # ----------------------------------------------------------------
  21. my $idesc = "Description of the first item";
  22. my $icate = "Category of the first item";
  23. my $idateA = "Sun, 11 Dec 2005 10:09:08 -0700";
  24. my $idateB = "2005-12-11T10:09:08-07:00";
  25. my $iauthor = "Author";
  26. my $iguid = "GUID";
  27. # ----------------------------------------------------------------
  28. my $feed1 = XML::FeedPP::RDF->new();
  29. $feed1->title( $ftitle );
  30. $feed1->description( $fdesc );
  31. $feed1->pubDate( $fdateB );
  32. $feed1->copyright( $fright );
  33. $feed1->link( $flink );
  34. $feed1->language( $flang );
  35. # ----------------------------------------------------------------
  36. ok( 0 == $feed1->get_item(), "0 item" );
  37. # ----------------------------------------------------------------
  38. my $item1 = $feed1->add_item( $link1 );
  39. $item1->title( $title1 );
  40. $item1->pubDate( $idateB );
  41. ok( 1 == $feed1->get_item(), "1 item" );
  42. # ----------------------------------------------------------------
  43. $item1->description( $idesc );
  44. $item1->category( $icate );
  45. $item1->author( $iauthor, isPermaLink => "false" );
  46. $item1->guid( $iguid );
  47. # ----------------------------------------------------------------
  48. my $item2 = $feed1->add_item( $link2 );
  49. $item2->title( $title2 );
  50. $item2->pubDate( $idateA );
  51. ok( 2 == $feed1->get_item(), "2 items" );
  52. # ----------------------------------------------------------------
  53. my $item3 = $feed1->add_item( $link3 );
  54. $item3->title( $title3 );
  55. $item3->pubDate( $idateA );
  56. ok( 3 == $feed1->get_item(), "3 items" );
  57. # ----------------------------------------------------------------
  58. my $source1 = $feed1->to_string();
  59. my $feed2 = XML::FeedPP::RDF->new( $source1 );
  60. ok( 3 == $feed2->get_item(), "3 items" );
  61. # ----------------------------------------------------------------
  62. is( $feed2->title(), $ftitle, "RDF->title()" );
  63. is( $feed2->description(), $fdesc, "RDF->description()" );
  64. is( $feed2->pubDate(), $fdateB, "RDF->pubDate()" );
  65. is( $feed2->copyright(), $fright, "RDF->copyright()" );
  66. is( $feed2->link(), $flink, "RDF->link()" );
  67. is( $feed2->language(), $flang, "RDF->language()" );
  68. # ----------------------------------------------------------------
  69. my $item4 = $feed2->get_item( 0 );
  70. # ----------------------------------------------------------------
  71. is( $item4->link(), $link1, "Item->title()" );
  72. is( $item4->title(), $title1, "Item->title()" );
  73. is( $item4->pubDate(), $idateB, "Item->pubDate()" );
  74. is( $item4->description(), $idesc, "Item->description()" );
  75. is( $item4->category(), $icate, "Item->category()" );
  76. is( $item4->author(), $iauthor, "Item->author()" );
  77. is( $item4->guid(), undef, "Item->guid()" );
  78. # ----------------------------------------------------------------
  79. my $source2 = $feed1->to_string();
  80. is( $source1, $source2, "turn around - rss source." );
  81. # ----------------------------------------------------------------
  82. like( $source2, qr/<title[^>]*>\s* \Q$ftitle\E/x, "<title>" );
  83. like( $source2, qr/<description[^>]*>\s* \Q$fdesc\E/x, "<description>" );
  84. like( $source2, qr/<dc:date[^>]*>\s* \Q$fdateB\E/x, "<dc:date>" );
  85. like( $source2, qr/<dc:rights[^>]*>\s* \Q$fright\E/x, "<dc:rights>" );
  86. like( $source2, qr/<link[^>]*>\s* \Q$flink\E/x, "<link>" );
  87. like( $source2, qr/<dc:lang[^>]*>\s* \Q$flang\E/x, "<dc:lang>" );
  88. # ----------------------------------------------------------------
  89. like( $source2, qr/<link[^>]*>\s* \Q$link1\E/x, "<link>" );
  90. like( $source2, qr/<title[^>]*>\s* \Q$title1\E/x, "<title>" );
  91. like( $source2, qr/<dc:date[^>]*>\s* \Q$idateB\E/x, "<dc:date>" );
  92. like( $source2, qr/<description[^>]*>\s* \Q$idesc\E/x, "<description>" );
  93. like( $source2, qr/<dc:subject[^>]*>\s* \Q$icate\E/x, "<dc:subject>" );
  94. like( $source2, qr/<dc:creator[^>]*>\s* \Q$iauthor\E/x, "<creator>" );
  95. # like( $source2, qr/<guid[^>]*>\s* \Q$iguid\E/x, "<guid>" );
  96. # ----------------------------------------------------------------
  97. ;1;
  98. # ----------------------------------------------------------------