FeedDiscoveryTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
  3. print "This script must be run from the command line\n";
  4. exit();
  5. }
  6. define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
  7. define('GNUSOCIAL', true);
  8. define('STATUSNET', true); // compatibility
  9. require_once INSTALLDIR . '/lib/util/common.php';
  10. require_once INSTALLDIR . '/plugins/OStatus/lib/feeddiscovery.php';
  11. class FeedDiscoveryTest extends PHPUnit_Framework_TestCase
  12. {
  13. /**
  14. * @dataProvider provider
  15. *
  16. */
  17. public function testProduction($url, $html, $expected)
  18. {
  19. $sub = new FeedDiscovery();
  20. $url = $sub->discoverFromHTML($url, $html);
  21. $this->assertEquals($expected, $url);
  22. }
  23. static public function provider()
  24. {
  25. $sampleHeader = <<<END
  26. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  27. <html xmlns="http://www.w3.org/1999/xhtml">
  28. <head profile="http://gmpg.org/xfn/11">
  29. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  30. <title>leŭksman </title>
  31. <meta name="generator" content="WordPress 2.8.6" /> <!-- leave this for stats -->
  32. <link rel="stylesheet" href="http://leuksman.com/log/wp-content/themes/leuksman/style.css" type="text/css" media="screen" />
  33. <link rel="alternate" type="application/rss+xml" title="leŭksman RSS Feed" href="http://leuksman.com/log/feed/" />
  34. <link rel="pingback" href="http://leuksman.com/log/xmlrpc.php" />
  35. <meta name="viewport" content="width = 640" />
  36. <xmeta name="viewport" content="initial-scale=2.3, user-scalable=no" />
  37. <style type="text/css" media="screen">
  38. #page { background: url("http://leuksman.com/log/wp-content/themes/leuksman/images/kubrickbg.jpg") repeat-y top; border: none; }
  39. </style>
  40. <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://leuksman.com/log/xmlrpc.php?rsd" />
  41. <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://leuksman.com/log/wp-includes/wlwmanifest.xml" />
  42. <link rel='index' title='leŭksman' href='http://leuksman.com/log' />
  43. <meta name="generator" content="WordPress 2.8.6" />
  44. </head>
  45. <body>
  46. </body>
  47. </html>
  48. END;
  49. return array(
  50. array('http://example.com/',
  51. '<html><link rel="alternate" href="http://example.com/feed/rss" type="application/rss+xml">',
  52. 'http://example.com/feed/rss'),
  53. array('http://example.com/atom',
  54. '<html><link rel="alternate" href="http://example.com/feed/atom" type="application/atom+xml">',
  55. 'http://example.com/feed/atom'),
  56. array('http://example.com/empty',
  57. '<html><link rel="alternate" href="http://example.com/index.pdf" type="application/pdf">',
  58. false),
  59. array('http://example.com/tagsoup',
  60. '<body><pre><LINK rel=alternate hRef=http://example.com/feed/rss type=application/rss+xml><fnork',
  61. 'http://example.com/feed/rss'),
  62. // 'rel' attribute must be lowercase, alone per http://www.rssboard.org/rss-autodiscovery
  63. // but we're going to be liberal in what we receive.
  64. array('http://example.com/tagsoup2',
  65. '<body><pre><LINK rel=" feeders alternate 467" hRef=http://example.com/feed/rss type=application/rss+xml><fnork',
  66. 'http://example.com/feed/rss'),
  67. array('http://example.com/tagsoup3',
  68. '<body><pre><LINK rel=ALTERNATE hRef=http://example.com/feed/rss type=application/rss+xml><fnork',
  69. false),
  70. array('http://example.com/relative/link1',
  71. '<html><link rel="alternate" href="/feed/rss" type="application/rss+xml">',
  72. 'http://example.com/feed/rss'),
  73. array('http://example.com/relative/link2',
  74. '<html><link rel="alternate" href="../feed/rss" type="application/rss+xml">',
  75. 'http://example.com/feed/rss'),
  76. // This one can't resolve correctly; relative link is bogus.
  77. array('http://example.com/relative/link3',
  78. '<html><link rel="alternate" href="http:/feed/rss" type="application/rss+xml">',
  79. 'http:/feed/rss'),
  80. array('http://example.com/base/link1',
  81. '<html><link rel="alternate" href="/feed/rss" type="application/rss+xml"><base href="http://target.example.com/">',
  82. 'http://target.example.com/feed/rss'),
  83. array('http://example.com/base/link2',
  84. '<html><link rel="alternate" href="feed/rss" type="application/rss+xml"><base href="http://target.example.com/">',
  85. 'http://target.example.com/feed/rss'),
  86. // This one can't resolve; relative link is bogus.
  87. array('http://example.com/base/link3',
  88. '<html><link rel="alternate" href="http:/feed/rss" type="application/rss+xml"><base href="http://target.example.com/">',
  89. 'http:/feed/rss'),
  90. // Trick question! There's a <base> but no href on it
  91. array('http://example.com/relative/fauxbase',
  92. '<html><link rel="alternate" href="../feed/rss" type="application/rss+xml"><base target="top">',
  93. 'http://example.com/feed/rss'),
  94. // Actual WordPress blog header example
  95. array('http://leuksman.com/log/',
  96. $sampleHeader,
  97. 'http://leuksman.com/log/feed/'));
  98. }
  99. }