]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/FeedSub/tests/FeedDiscoveryTest.php
Moderator can make users admins of a group
[quix0rs-gnu-social.git] / plugins / FeedSub / tests / FeedDiscoveryTest.php
1 <?php
2
3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4     print "This script must be run from the command line\n";
5     exit();
6 }
7
8 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
9 define('STATUSNET', true);
10 define('LACONICA', true);
11
12 require_once INSTALLDIR . '/lib/common.php';
13 require_once INSTALLDIR . '/plugins/FeedSub/feedsub.php';
14
15 class FeedDiscoveryTest extends PHPUnit_Framework_TestCase
16 {
17     /**
18      * @dataProvider provider
19      *
20      */
21     public function testProduction($url, $html, $expected)
22     {
23         $sub = new FeedDiscovery();
24         $url = $sub->discoverFromHTML($url, $html);
25         $this->assertEquals($expected, $url);
26     }
27
28     static public function provider()
29     {
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">
33
34 <head profile="http://gmpg.org/xfn/11">
35 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
36
37 <title>leŭksman  </title>
38
39 <meta name="generator" content="WordPress 2.8.6" /> <!-- leave this for stats -->
40
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" />
44
45 <meta name="viewport" content="width = 640" />
46
47 <xmeta name="viewport" content="initial-scale=2.3, user-scalable=no" />
48
49 <style type="text/css" media="screen">
50
51         #page { background: url("http://leuksman.com/log/wp-content/themes/leuksman/images/kubrickbg.jpg") repeat-y top; border: none; }
52
53 </style>
54
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" />
59 </head>
60 <body>
61 </body>
62 </html>
63 END;
64         return array(
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">',
73                            false),
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                      array('http://example.com/tagsoup2',
79                            '<body><pre><LINK rel=" feeders    alternate 467" hRef=http://example.com/feed/rss type=application/rss+xml><fnork',
80                            false),
81                      array('http://example.com/tagsoup3',
82                            '<body><pre><LINK rel=ALTERNATE hRef=http://example.com/feed/rss type=application/rss+xml><fnork',
83                            false),
84                      array('http://example.com/relative/link1',
85                            '<html><link rel="alternate" href="/feed/rss" type="application/rss+xml">',
86                            'http://example.com/feed/rss'),
87                      array('http://example.com/relative/link2',
88                            '<html><link rel="alternate" href="../feed/rss" type="application/rss+xml">',
89                            'http://example.com/feed/rss'),
90                      array('http://example.com/relative/link3',
91                            '<html><link rel="alternate" href="http:/feed/rss" type="application/rss+xml">',
92                            'http://example.com/feed/rss'),
93                      array('http://example.com/base/link1',
94                            '<html><link rel="alternate" href="/feed/rss" type="application/rss+xml"><base href="http://target.example.com/">',
95                            'http://target.example.com/feed/rss'),
96                      array('http://example.com/base/link2',
97                            '<html><link rel="alternate" href="feed/rss" type="application/rss+xml"><base href="http://target.example.com/">',
98                            'http://target.example.com/feed/rss'),
99                      array('http://example.com/base/link3',
100                            '<html><link rel="alternate" href="http:/feed/rss" type="application/rss+xml"><base href="http://target.example.com/">',
101                            'http://target.example.com/feed/rss'),
102                      // Trick question! There's a <base> but no href on it
103                      array('http://example.com/relative/fauxbase',
104                            '<html><link rel="alternate" href="../feed/rss" type="application/rss+xml"><base target="top">',
105                            'http://example.com/feed/rss'),
106                      // Actual WordPress blog header example
107                      array('http://leuksman.com/log/',
108                            $sampleHeader,
109                            'http://leuksman.com/log/feed/'));
110     }
111 }