]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/tests/FeedMungerTest.php
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / plugins / OStatus / tests / FeedMungerTest.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 require_once 'XML/Feed/Parser.php';
16
17 class FeedMungerTest extends PHPUnit_Framework_TestCase
18 {
19     /**
20      * @dataProvider profileProvider
21      *
22      */
23     public function testProfiles($xml, $expected)
24     {
25         $feed = new XML_Feed_Parser($xml, false, false, true);
26         
27         $munger = new FeedMunger($feed);
28         $profile = $munger->profile();
29
30         foreach ($expected as $field => $val) {
31             $this->assertEquals($expected[$field], $profile->$field, "profile->$field");
32         }
33     }
34
35     static public function profileProvider()
36     {
37         return array(
38                      array(self::samplefeed(),
39                            array('nickname' => 'leŭksman', // @todo does this need to be asciified?
40                                  'fullname' => 'leŭksman',
41                                  'bio' => 'reticula, electronica, & oddities',
42                                  'homepage' => 'http://leuksman.com/log')));
43     }
44
45     /**
46      * @dataProvider noticeProvider
47      *
48      */
49     public function testNotices($xml, $entryIndex, $expected)
50     {
51         $feed = new XML_Feed_Parser($xml, false, false, true);
52         $entry = $feed->getEntryByOffset($entryIndex);
53
54         $munger = new FeedMunger($feed);
55         $notice = $munger->noticeFromEntry($entry);
56
57         $this->assertTrue(mb_strlen($notice) <= Notice::maxContent());
58         $this->assertEquals($expected, $notice);
59     }
60
61     static public function noticeProvider()
62     {
63         return array(
64                      array('<rss version="2.0"><channel><item><title>A fairly short title</title><link>http://example.com/short/link</link></item></channel></rss>', 0,
65                            'New post: "A fairly short title" http://example.com/short/link'),
66                      // Requires URL shortening ...
67                      array('<rss version="2.0"><channel><item><title>A fairly short title</title><link>http://example.com/but/a/very/long/link/indeed/this/is/far/too/long/for/mere/humans/to/comprehend/oh/my/gosh</link></item></channel></rss>', 0,
68                            'New post: "A fairly short title" http://ur1.ca/g2o1'),
69                      array('<rss version="2.0"><channel><item><title>A fairly long title in this case, which will have to get cut down at some point alongside its very long link. Really who even makes titles this long? It\'s just ridiculous imo...</title><link>http://example.com/but/a/very/long/link/indeed/this/is/far/too/long/for/mere/humans/to/comprehend/oh/my/gosh</link></item></channel></rss>', 0,
70                            'New post: "A fairly long title in this case, which will have to get cut down at some point alongside its very long li…" http://ur1.ca/g2o1'),
71                      // Some real sample feeds
72                      array(self::samplefeed(), 0,
73                            'New post: "Compiling PHP on Snow Leopard" http://leuksman.com/log/2009/11/12/compiling-php-on-snow-leopard/'),
74                      array(self::samplefeedBlogspot(), 0,
75                            'New post: "I love posting" http://briontest.blogspot.com/2009/11/i-love-posting.html'),
76                      array(self::samplefeedBlogspot(), 1,
77                            'New post: "Hey dude" http://briontest.blogspot.com/2009/11/hey-dude.html'),
78         );
79     }
80
81     static protected function samplefeed()
82     {
83         $xml = '<' . '?xml version="1.0" encoding="UTF-8"?' . ">\n";
84         $samplefeed = $xml . <<<END
85 <rss version="2.0"
86         xmlns:content="http://purl.org/rss/1.0/modules/content/"
87         xmlns:wfw="http://wellformedweb.org/CommentAPI/"
88         xmlns:dc="http://purl.org/dc/elements/1.1/"
89         xmlns:atom="http://www.w3.org/2005/Atom"
90         xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
91         xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
92         >
93
94 <channel>
95         <title>leŭksman</title>
96         <atom:link href="http://leuksman.com/log/feed/" rel="self" type="application/rss+xml" />
97         <link>http://leuksman.com/log</link>
98         <description>reticula, electronica, &#38; oddities</description>
99
100         <lastBuildDate>Thu, 12 Nov 2009 17:44:42 +0000</lastBuildDate>
101         <generator>http://wordpress.org/?v=2.8.6</generator>
102         <language>en</language>
103         <sy:updatePeriod>hourly</sy:updatePeriod>
104         <sy:updateFrequency>1</sy:updateFrequency>
105                         <item>
106
107                 <title>Compiling PHP on Snow Leopard</title>
108                 <link>http://leuksman.com/log/2009/11/12/compiling-php-on-snow-leopard/</link>
109                 <comments>http://leuksman.com/log/2009/11/12/compiling-php-on-snow-leopard/#comments</comments>
110                 <pubDate>Thu, 12 Nov 2009 17:44:42 +0000</pubDate>
111                 <dc:creator>brion</dc:creator>
112                                 <category><![CDATA[apple]]></category>
113
114                 <category><![CDATA[devel]]></category>
115
116                 <guid isPermaLink="false">http://leuksman.com/log/?p=649</guid>
117                 <description><![CDATA[If you&#8217;ve been having trouble compiling your own PHP installations on Mac OS X 10.6, here&#8217;s the secret to making it not suck! After running the configure script, edit the generated Makefile and make these fixes:
118
119 Find the EXTRA_LIBS definition and add -lresolv to the end
120 Find the EXE_EXT definition and remove .dSYM
121
122 Standard make and make install [...]]]></description>
123                         <content:encoded><![CDATA[<p>If you&#8217;ve been having trouble compiling your own PHP installations on Mac OS X 10.6, here&#8217;s the secret to making it not suck! After running the configure script, edit the generated Makefile and make these fixes:</p>
124 <ul>
125 <li>Find the <strong>EXTRA_LIBS</strong> definition and add <strong>-lresolv</strong> to the end</li>
126 <li>Find the <strong>EXE_EXT</strong> definition and remove <strong>.dSYM</strong></li>
127 </ul>
128 <p>Standard make and make install should work from here&#8230;</p>
129 <p>For reference, here&#8217;s the whole configure line I currently use; MySQL is installed from the downloadable installer; other deps from MacPorts:</p>
130 <p>&#8216;./configure&#8217; &#8216;&#8211;prefix=/opt/php52&#8242; &#8216;&#8211;with-mysql=/usr/local/mysql&#8217; &#8216;&#8211;with-zlib&#8217; &#8216;&#8211;with-bz2&#8242; &#8216;&#8211;enable-mbstring&#8217; &#8216;&#8211;enable-exif&#8217; &#8216;&#8211;enable-fastcgi&#8217; &#8216;&#8211;with-xmlrpc&#8217; &#8216;&#8211;with-xsl&#8217; &#8216;&#8211;with-readline=/opt/local&#8217; &#8211;without-iconv &#8211;with-gd &#8211;with-png-dir=/opt/local &#8211;with-jpeg-dir=/opt/local &#8211;with-curl &#8211;with-gettext=/opt/local &#8211;with-mysqli=/usr/local/mysql/bin/mysql_config &#8211;with-tidy=/opt/local &#8211;enable-pcntl &#8211;with-openssl</p>
131 ]]></content:encoded>
132                         <wfw:commentRss>http://leuksman.com/log/2009/11/12/compiling-php-on-snow-leopard/feed/</wfw:commentRss>
133                 <slash:comments>0</slash:comments>
134                 </item>
135 </channel>
136 </rss>
137 END;
138         return $samplefeed;
139     }
140     
141     static protected function samplefeedBlogspot()
142     {
143         return <<<END
144 <?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss'><id>tag:blogger.com,1999:blog-7780083508531697167</id><updated>2009-11-19T12:56:11.233-08:00</updated><title type='text'>Brion's Cool Test Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://briontest.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7780083508531697167/posts/default'/><link rel='alternate' type='text/html' href='http://briontest.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>brion</name><uri>http://www.blogger.com/profile/12932299467049762017</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7780083508531697167.post-8456671879000290677</id><published>2009-11-19T12:55:00.000-08:00</published><updated>2009-11-19T12:56:11.241-08:00</updated><title type='text'>I love posting</title><content type='html'>It's pretty awesome, if you like that sort of thing.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7780083508531697167-8456671879000290677?l=briontest.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://briontest.blogspot.com/feeds/8456671879000290677/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://briontest.blogspot.com/2009/11/i-love-posting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7780083508531697167/posts/default/8456671879000290677'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7780083508531697167/posts/default/8456671879000290677'/><link rel='alternate' type='text/html' href='http://briontest.blogspot.com/2009/11/i-love-posting.html' title='I love posting'/><author><name>brion</name><uri>http://www.blogger.com/profile/12932299467049762017</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05912464053145602436'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7780083508531697167.post-8202296917897346633</id><published>2009-11-18T13:52:00.001-08:00</published><updated>2009-11-18T13:52:48.444-08:00</updated><title type='text'>Hey dude</title><content type='html'>testingggggggggg&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7780083508531697167-8202296917897346633?l=briontest.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://briontest.blogspot.com/feeds/8202296917897346633/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://briontest.blogspot.com/2009/11/hey-dude.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7780083508531697167/posts/default/8202296917897346633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7780083508531697167/posts/default/8202296917897346633'/><link rel='alternate' type='text/html' href='http://briontest.blogspot.com/2009/11/hey-dude.html' title='Hey dude'/><author><name>brion</name><uri>http://www.blogger.com/profile/12932299467049762017</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05912464053145602436'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry></feed>
145 END;
146     }
147 }