diff options
author | Brion Vibber <brion@pobox.com> | 2010-02-08 11:06:03 -0800 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2010-02-08 11:15:29 -0800 |
commit | dc09453a77f33c4dfdff306321ce93cf5fbd2d57 (patch) | |
tree | df3ff3713cf36a84efeb09b5650dd49399edc8f4 /plugins/OStatus/tests | |
parent | 5fdcd88176010a72b6a157170784a8aad7bf4131 (diff) |
First steps on converting FeedSub into the pub/sub basis for OStatus communications:
* renamed FeedSub plugin to OStatus
* now setting avatar on subscriptions
* general fixes for subscription
* integrated PuSH hub to handle only user timelines on canonical ID url; sends updates directly
* set $config['feedsub']['nohub'] = true to test w/ foreign feeds that don't have hubs (won't actually receive updates though)
* a few bits of code documentation
* HMAC support for verified distributions (safest if sub setup is on HTTPS)
And a couple core changes:
* minimizing HTML output for exceptions in API requests to aid in debugging
* fix for rel=self link in apitimelineuser when id given
This does not not yet include any of the individual subscription management (Salmon notifications for sub/unsub, etc) nor a nice UI for user subscriptions.
Needs some further cleanup to treat posts as status updates instead of link references.
Diffstat (limited to 'plugins/OStatus/tests')
-rw-r--r-- | plugins/OStatus/tests/FeedDiscoveryTest.php | 111 | ||||
-rw-r--r-- | plugins/OStatus/tests/FeedMungerTest.php | 147 | ||||
-rw-r--r-- | plugins/OStatus/tests/gettext-speedtest.php | 78 |
3 files changed, 336 insertions, 0 deletions
diff --git a/plugins/OStatus/tests/FeedDiscoveryTest.php b/plugins/OStatus/tests/FeedDiscoveryTest.php new file mode 100644 index 000000000..1c5249701 --- /dev/null +++ b/plugins/OStatus/tests/FeedDiscoveryTest.php @@ -0,0 +1,111 @@ +<?php + +if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { + print "This script must be run from the command line\n"; + exit(); +} + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); +define('STATUSNET', true); +define('LACONICA', true); + +require_once INSTALLDIR . '/lib/common.php'; +require_once INSTALLDIR . '/plugins/FeedSub/feedsub.php'; + +class FeedDiscoveryTest extends PHPUnit_Framework_TestCase +{ + /** + * @dataProvider provider + * + */ + public function testProduction($url, $html, $expected) + { + $sub = new FeedDiscovery(); + $url = $sub->discoverFromHTML($url, $html); + $this->assertEquals($expected, $url); + } + + static public function provider() + { + $sampleHeader = <<<END +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> + +<head profile="http://gmpg.org/xfn/11"> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + +<title>leŭksman </title> + +<meta name="generator" content="WordPress 2.8.6" /> <!-- leave this for stats --> + +<link rel="stylesheet" href="http://leuksman.com/log/wp-content/themes/leuksman/style.css" type="text/css" media="screen" /> +<link rel="alternate" type="application/rss+xml" title="leŭksman RSS Feed" href="http://leuksman.com/log/feed/" /> +<link rel="pingback" href="http://leuksman.com/log/xmlrpc.php" /> + +<meta name="viewport" content="width = 640" /> + +<xmeta name="viewport" content="initial-scale=2.3, user-scalable=no" /> + +<style type="text/css" media="screen"> + + #page { background: url("http://leuksman.com/log/wp-content/themes/leuksman/images/kubrickbg.jpg") repeat-y top; border: none; } + +</style> + +<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://leuksman.com/log/xmlrpc.php?rsd" /> +<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://leuksman.com/log/wp-includes/wlwmanifest.xml" /> +<link rel='index' title='leŭksman' href='http://leuksman.com/log' /> +<meta name="generator" content="WordPress 2.8.6" /> +</head> +<body> +</body> +</html> +END; + return array( + array('http://example.com/', + '<html><link rel="alternate" href="http://example.com/feed/rss" type="application/rss+xml">', + 'http://example.com/feed/rss'), + array('http://example.com/atom', + '<html><link rel="alternate" href="http://example.com/feed/atom" type="application/atom+xml">', + 'http://example.com/feed/atom'), + array('http://example.com/empty', + '<html><link rel="alternate" href="http://example.com/index.pdf" type="application/pdf">', + false), + array('http://example.com/tagsoup', + '<body><pre><LINK rel=alternate hRef=http://example.com/feed/rss type=application/rss+xml><fnork', + 'http://example.com/feed/rss'), + // 'rel' attribute must be lowercase, alone per http://www.rssboard.org/rss-autodiscovery + array('http://example.com/tagsoup2', + '<body><pre><LINK rel=" feeders alternate 467" hRef=http://example.com/feed/rss type=application/rss+xml><fnork', + false), + array('http://example.com/tagsoup3', + '<body><pre><LINK rel=ALTERNATE hRef=http://example.com/feed/rss type=application/rss+xml><fnork', + false), + array('http://example.com/relative/link1', + '<html><link rel="alternate" href="/feed/rss" type="application/rss+xml">', + 'http://example.com/feed/rss'), + array('http://example.com/relative/link2', + '<html><link rel="alternate" href="../feed/rss" type="application/rss+xml">', + 'http://example.com/feed/rss'), + array('http://example.com/relative/link3', + '<html><link rel="alternate" href="http:/feed/rss" type="application/rss+xml">', + 'http://example.com/feed/rss'), + array('http://example.com/base/link1', + '<html><link rel="alternate" href="/feed/rss" type="application/rss+xml"><base href="http://target.example.com/">', + 'http://target.example.com/feed/rss'), + array('http://example.com/base/link2', + '<html><link rel="alternate" href="feed/rss" type="application/rss+xml"><base href="http://target.example.com/">', + 'http://target.example.com/feed/rss'), + array('http://example.com/base/link3', + '<html><link rel="alternate" href="http:/feed/rss" type="application/rss+xml"><base href="http://target.example.com/">', + 'http://target.example.com/feed/rss'), + // Trick question! There's a <base> but no href on it + array('http://example.com/relative/fauxbase', + '<html><link rel="alternate" href="../feed/rss" type="application/rss+xml"><base target="top">', + 'http://example.com/feed/rss'), + // Actual WordPress blog header example + array('http://leuksman.com/log/', + $sampleHeader, + 'http://leuksman.com/log/feed/')); + } +} diff --git a/plugins/OStatus/tests/FeedMungerTest.php b/plugins/OStatus/tests/FeedMungerTest.php new file mode 100644 index 000000000..0ce24c9fb --- /dev/null +++ b/plugins/OStatus/tests/FeedMungerTest.php @@ -0,0 +1,147 @@ +<?php + +if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { + print "This script must be run from the command line\n"; + exit(); +} + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); +define('STATUSNET', true); +define('LACONICA', true); + +require_once INSTALLDIR . '/lib/common.php'; +require_once INSTALLDIR . '/plugins/FeedSub/feedsub.php'; + +require_once 'XML/Feed/Parser.php'; + +class FeedMungerTest extends PHPUnit_Framework_TestCase +{ + /** + * @dataProvider profileProvider + * + */ + public function testProfiles($xml, $expected) + { + $feed = new XML_Feed_Parser($xml, false, false, true); + + $munger = new FeedMunger($feed); + $profile = $munger->profile(); + + foreach ($expected as $field => $val) { + $this->assertEquals($expected[$field], $profile->$field, "profile->$field"); + } + } + + static public function profileProvider() + { + return array( + array(self::samplefeed(), + array('nickname' => 'leŭksman', // @todo does this need to be asciified? + 'fullname' => 'leŭksman', + 'bio' => 'reticula, electronica, & oddities', + 'homepage' => 'http://leuksman.com/log'))); + } + + /** + * @dataProvider noticeProvider + * + */ + public function testNotices($xml, $entryIndex, $expected) + { + $feed = new XML_Feed_Parser($xml, false, false, true); + $entry = $feed->getEntryByOffset($entryIndex); + + $munger = new FeedMunger($feed); + $notice = $munger->noticeFromEntry($entry); + + $this->assertTrue(mb_strlen($notice) <= Notice::maxContent()); + $this->assertEquals($expected, $notice); + } + + static public function noticeProvider() + { + return array( + array('<rss version="2.0"><channel><item><title>A fairly short title</title><link>http://example.com/short/link</link></item></channel></rss>', 0, + 'New post: "A fairly short title" http://example.com/short/link'), + // Requires URL shortening ... + 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, + 'New post: "A fairly short title" http://ur1.ca/g2o1'), + 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, + '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'), + // Some real sample feeds + array(self::samplefeed(), 0, + 'New post: "Compiling PHP on Snow Leopard" http://leuksman.com/log/2009/11/12/compiling-php-on-snow-leopard/'), + array(self::samplefeedBlogspot(), 0, + 'New post: "I love posting" http://briontest.blogspot.com/2009/11/i-love-posting.html'), + array(self::samplefeedBlogspot(), 1, + 'New post: "Hey dude" http://briontest.blogspot.com/2009/11/hey-dude.html'), + ); + } + + static protected function samplefeed() + { + $xml = '<' . '?xml version="1.0" encoding="UTF-8"?' . ">\n"; + $samplefeed = $xml . <<<END +<rss version="2.0" + xmlns:content="http://purl.org/rss/1.0/modules/content/" + xmlns:wfw="http://wellformedweb.org/CommentAPI/" + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:atom="http://www.w3.org/2005/Atom" + xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" + xmlns:slash="http://purl.org/rss/1.0/modules/slash/" + > + +<channel> + <title>leŭksman</title> + <atom:link href="http://leuksman.com/log/feed/" rel="self" type="application/rss+xml" /> + <link>http://leuksman.com/log</link> + <description>reticula, electronica, & oddities</description> + + <lastBuildDate>Thu, 12 Nov 2009 17:44:42 +0000</lastBuildDate> + <generator>http://wordpress.org/?v=2.8.6</generator> + <language>en</language> + <sy:updatePeriod>hourly</sy:updatePeriod> + <sy:updateFrequency>1</sy:updateFrequency> + <item> + + <title>Compiling PHP on Snow Leopard</title> + <link>http://leuksman.com/log/2009/11/12/compiling-php-on-snow-leopard/</link> + <comments>http://leuksman.com/log/2009/11/12/compiling-php-on-snow-leopard/#comments</comments> + <pubDate>Thu, 12 Nov 2009 17:44:42 +0000</pubDate> + <dc:creator>brion</dc:creator> + <category><![CDATA[apple]]></category> + + <category><![CDATA[devel]]></category> + + <guid isPermaLink="false">http://leuksman.com/log/?p=649</guid> + <description><![CDATA[If you’ve been having trouble compiling your own PHP installations on Mac OS X 10.6, here’s the secret to making it not suck! After running the configure script, edit the generated Makefile and make these fixes: + +Find the EXTRA_LIBS definition and add -lresolv to the end +Find the EXE_EXT definition and remove .dSYM + +Standard make and make install [...]]]></description> + <content:encoded><![CDATA[<p>If you’ve been having trouble compiling your own PHP installations on Mac OS X 10.6, here’s the secret to making it not suck! After running the configure script, edit the generated Makefile and make these fixes:</p> +<ul> +<li>Find the <strong>EXTRA_LIBS</strong> definition and add <strong>-lresolv</strong> to the end</li> +<li>Find the <strong>EXE_EXT</strong> definition and remove <strong>.dSYM</strong></li> +</ul> +<p>Standard make and make install should work from here…</p> +<p>For reference, here’s the whole configure line I currently use; MySQL is installed from the downloadable installer; other deps from MacPorts:</p> +<p>‘./configure’ ‘–prefix=/opt/php52′ ‘–with-mysql=/usr/local/mysql’ ‘–with-zlib’ ‘–with-bz2′ ‘–enable-mbstring’ ‘–enable-exif’ ‘–enable-fastcgi’ ‘–with-xmlrpc’ ‘–with-xsl’ ‘–with-readline=/opt/local’ –without-iconv –with-gd –with-png-dir=/opt/local –with-jpeg-dir=/opt/local –with-curl –with-gettext=/opt/local –with-mysqli=/usr/local/mysql/bin/mysql_config –with-tidy=/opt/local –enable-pcntl –with-openssl</p> +]]></content:encoded> + <wfw:commentRss>http://leuksman.com/log/2009/11/12/compiling-php-on-snow-leopard/feed/</wfw:commentRss> + <slash:comments>0</slash:comments> + </item> +</channel> +</rss> +END; + return $samplefeed; + } + + static protected function samplefeedBlogspot() + { + return <<<END +<?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.<div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7780083508531697167-8456671879000290677?l=briontest.blogspot.com' alt='' /></div></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<div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7780083508531697167-8202296917897346633?l=briontest.blogspot.com' alt='' /></div></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> +END; + } +} diff --git a/plugins/OStatus/tests/gettext-speedtest.php b/plugins/OStatus/tests/gettext-speedtest.php new file mode 100644 index 000000000..8bbdf5e89 --- /dev/null +++ b/plugins/OStatus/tests/gettext-speedtest.php @@ -0,0 +1,78 @@ +<?php + +if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { + print "This script must be run from the command line\n"; + exit(); +} + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); +define('STATUSNET', true); +define('LACONICA', true); + +require_once INSTALLDIR . '/scripts/commandline.inc'; +require_once INSTALLDIR . '/extlib/php-gettext/gettext.inc'; + +common_init_locale("en_US"); +common_init_locale('fr'); + + +putenv("LANG=fr"); +putenv("LANGUAGE=fr"); +setlocale('fr.utf8'); +_setlocale('fr.utf8'); + +_bindtextdomain("statusnet", INSTALLDIR . '/locale'); +_bindtextdomain("FeedSub", INSTALLDIR . '/plugins/FeedSub/locale'); + +$times = 10000; +$delta = array(); + +$start = microtime(true); +for($i = 0; $i < $times; $i++) { + $result = _("Send"); +} +$delta["_"] = array((microtime(true) - $start) / $times, $result); + +$start = microtime(true); +for($i = 0; $i < $times; $i++) { + $result = __("Send"); +} +$delta["__"] = array((microtime(true) - $start) / $times, $result); + +$start = microtime(true); +for($i = 0; $i < $times; $i++) { + $result = dgettext("FeedSub", "Feeds"); +} +$delta["dgettext"] = array((microtime(true) - $start) / $times, $result); + +$start = microtime(true); +for($i = 0; $i < $times; $i++) { + $result = _dgettext("FeedSub", "Feeds"); +} +$delta["_dgettext"] = array((microtime(true) - $start) / $times, $result); + + +$start = microtime(true); +for($i = 0; $i < $times; $i++) { + $result = _m("Feeds"); +} +$delta["_m"] = array((microtime(true) - $start) / $times, $result); + + +$start = microtime(true); +for($i = 0; $i < $times; $i++) { + $result = fake("Feeds"); +} +$delta["fake"] = array((microtime(true) - $start) / $times, $result); + +foreach ($delta as $func => $bits) { + list($time, $result) = $bits; + $ms = $time * 1000.0; + printf("%10s %2.4fms %s\n", $func, $ms, $result); +} + + +function fake($str) { + return $str; +} + |