PageRenderTime 41ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/OStatus/tests/FeedDiscoveryTest.php

https://gitlab.com/windigo-gs/windigos-gnu-social
PHP | 114 lines | 88 code | 15 blank | 11 comment | 3 complexity | c17defc9ac1503dccea1f5e51e2153c6 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, GPL-2.0
  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/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. }