/plugins/sfFeed2Plugin/test/unit/sfRss10FeedTest.php

https://github.com/malacon/rbwords · PHP · 127 lines · 109 code · 17 blank · 1 comment · 0 complexity · 2a3e3af60ef425ae50a8b8484a2355ab MD5 · raw file

  1. <?php
  2. define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/../../../..'));
  3. define('SF_APP', 'frontend');
  4. include(dirname(__FILE__).'/../../../../test/bootstrap/functional.php');
  5. $b = new sfTestBrowser();
  6. $b->initialize();
  7. $feedParams = array(
  8. 'title' => 'foo',
  9. 'link' => 'http://foobar',
  10. 'description' => 'foobar baz',
  11. 'language' => 'fr',
  12. 'authorName' => 'francois',
  13. 'authorEmail' => 'foo@bar.com',
  14. 'authorLink' => 'http://bar.baz',
  15. 'subtitle' => 'hey, foo, this is bar',
  16. 'categories' => array('foo', 'bar'),
  17. 'feedUrl' => 'http://www.example.com',
  18. 'encoding' => 'UTF-16'
  19. );
  20. $enclosureParams = array(
  21. 'url' => 'foo.com',
  22. 'length' => '1234',
  23. 'mimeType' => 'foobarmimetype',
  24. );
  25. $enclosure = new sfFeedEnclosure();
  26. $enclosure->initialize($enclosureParams);
  27. $itemParams = array(
  28. 'title' => 'fooitem',
  29. 'link' => 'http://www.example.com/item1',
  30. 'description' => 'foobar baz item',
  31. 'content' => 'this is foo bar baz',
  32. 'authorName' => 'francois item',
  33. 'authorEmail' => 'fooitem@bar.com',
  34. 'authorLink' => 'http://bar.baz.item',
  35. 'categories' => array('fooitem', 'baritem'),
  36. 'pubDate' => '12345',
  37. 'comments' => 'gee',
  38. 'uniqueId' => '98765',
  39. 'enclosure' => $enclosure,
  40. 'categories' => array('fooitem', 'baritem'),
  41. );
  42. $item2Params = array(
  43. 'title' => 'foobaritem',
  44. 'pubDate' => '123456',
  45. 'authorEmail' => 'fooitem2@bar.com',
  46. 'link' => 'http://www.example.com/item2',
  47. );
  48. $feed = new sfRss10Feed();
  49. $feed->initialize($feedParams);
  50. $feedItem = new sfFeedItem();
  51. $feedItem->initialize($itemParams);
  52. $feed->addItem($feedItem);
  53. $feedItem2 = new sfFeedItem();
  54. $feedItem2->initialize($item2Params);
  55. $feed->addItem($feedItem2);
  56. $t = new lime_test(35, new lime_output_color());
  57. $t->diag('toXML() - generated feed');
  58. $feedString = $feed->toXml();
  59. // we get rid of namespaces to avoid simpleXML headaches
  60. $feedString = str_replace(
  61. array('<dc:', '</dc:', '<rdf:', '</rdf:', '<content:', '</content:'),
  62. array('<', '</', '<', '</', '<', '</'),
  63. $feedString
  64. );
  65. $feedXml = simplexml_load_string($feedString);
  66. $t->is($feedXml->getName(), 'RDF', '<rdf:RDF> is the main tag');
  67. preg_match('/^<\?xml\s*version="1\.0"\s*encoding="(.*?)".*?\?>$/mi', $feedString, $matches);
  68. $t->is($matches[1], $feed->getEncoding(), 'The encoding is set with the proper feed encoding');
  69. $t->is((string) $feedXml->channel[0]->title, $feedParams['title'], '<title> contains the feed title');
  70. $t->is((string) $feedXml->channel[0]->link, $feedParams['link'], '<link> contains the feed link');
  71. $t->is((string) $feedXml->channel[0]->description, $feedParams['description'], '<description> contains the feed description');
  72. $t->diag('toXML() - generated feed items');
  73. $t->is((string) $feedXml->item[0]->title, $itemParams['title'], '<item><title> contains the item title');
  74. $t->is((string) $feedXml->item[0]->link, $itemParams['link'], '<item><link> contains the proper item link');
  75. $t->is((string) $feedXml->item[0]->description, $itemParams['description'], '<item><description> contains the item description');
  76. $t->is((string) $feedXml->item[0]->encoded, $itemParams['content'], '<item><content:encoded> contains the item content');
  77. $t->is((string) $feedXml->item[0]->date, gmstrftime('%Y-%m-%dT%H:%M:%SZ', $itemParams['pubDate']), '<item><dc:date> contains the proper item publication date');
  78. $t->is((string) $feedXml->item[0]->creator, $itemParams['authorName'], '<item><dc:creator> contains the proper item author name');
  79. $t->diag('asXML() - generated feed');
  80. $feedString = $feed->asXml();
  81. $t->is(sfContext::getInstance()->getResponse()->getContentType(), 'application/rss+xml; charset=UTF-16', 'The reponse comes with the correct Content-Type');
  82. $t->diag('fromXML() - generated feed');
  83. $generatedFeed = new sfRss10Feed();
  84. $generatedFeed->fromXml($feedString);
  85. $t->is($generatedFeed->getTitle(), $feed->getTitle(), 'The title property is properly set');
  86. $t->is($generatedFeed->getLink(), $feed->getLink(), 'The link property is properly set');
  87. $t->is($generatedFeed->getDescription(), $feed->getDescription(), 'The description property is properly set');
  88. $t->isnt($generatedFeed->getLanguage(), $feed->getLanguage(), 'The language property cannot be set from a RSS 1.0 feed');
  89. $t->isnt($generatedFeed->getAuthorEmail(), $feed->getAuthorEmail(), 'The author email property cannot be set from a RSS 1.0 feed');
  90. $t->isnt($generatedFeed->getAuthorName(), $feed->getAuthorName(), 'The author name property cannot be set from a RSS 1.0 feed');
  91. $t->isnt($generatedFeed->getAuthorLink(), $feed->getAuthorLink(), 'The author link property cannot be set from a RSS 1.0 feed');
  92. $t->isnt($generatedFeed->getSubtitle(), $feed->getSubtitle(), 'The subtitle property cannot be set from a RSS 1.0 feed');
  93. $t->isnt($generatedFeed->getCategories(), $feed->getCategories(), 'The categories property cannot be set from a RSS 1.0 feed');
  94. $t->isnt($generatedFeed->getFeedUrl(), $feed->getFeedUrl(), 'The feedUrl property cannot be set from a RSS 1.0 feed');
  95. $t->is($generatedFeed->getEncoding(), $feed->getEncoding(), 'The encoding property is properly set');
  96. $t->diag('fromXML() - generated feed items');
  97. $items = $generatedFeed->getItems();
  98. $generatedItem = $items[0];
  99. $t->is($generatedItem->getTitle(), $feedItem->getTitle(), 'The title property is properly set');
  100. $t->is($generatedItem->getLink(), $feedItem->getLink(), 'The link property is properly set');
  101. $t->is($generatedItem->getDescription(), $feedItem->getDescription(), 'The description property is properly set');
  102. $t->is($generatedItem->getContent(), $feedItem->getContent(), 'The content property is properly set');
  103. $t->isnt($generatedItem->getAuthorEmail(), $feedItem->getAuthorEmail(), 'The author email property cannot be set from a RSS 1.0 feed');
  104. $t->is($generatedItem->getAuthorName(), $feedItem->getAuthorName(), 'The author name property is properly set');
  105. $t->isnt($generatedItem->getAuthorLink(), $feedItem->getAuthorLink(), 'The author link property cannot be set from a RSS 1.0 feed');
  106. $t->is($generatedItem->getPubDate(), $feedItem->getPubdate(), 'The publication date property is properly set');
  107. $t->isnt($generatedItem->getComments(), $feedItem->getComments(), 'The comments property cannot be set from a RSS 1.0 feed');
  108. $t->isnt($generatedItem->getUniqueId(), $feedItem->getUniqueId(), 'The unique id property cannot be set from a RSS 1.0 feed');
  109. $t->is($generatedItem->getEnclosure(), '', 'The enclosure property cannot be set from a RSS 1.0 feed');
  110. $t->isnt($generatedItem->getCategories(), $feedItem->getCategories(), 'The categories property cannot be set from a RSS 1.0 feed');