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