From b189c9500c3ea5362edfcbf818c2f847b4892da5 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 20 Nov 2009 09:42:19 -0800 Subject: Initial functional version of feed subscription plugin, currently supporting only PuSH-enabled feeds. --- plugins/FeedSub/tests/FeedDiscoveryTest.php | 111 +++++++++++++++++++++ plugins/FeedSub/tests/FeedMungerTest.php | 147 ++++++++++++++++++++++++++++ 2 files changed, 258 insertions(+) create mode 100644 plugins/FeedSub/tests/FeedDiscoveryTest.php create mode 100644 plugins/FeedSub/tests/FeedMungerTest.php (limited to 'plugins/FeedSub/tests') diff --git a/plugins/FeedSub/tests/FeedDiscoveryTest.php b/plugins/FeedSub/tests/FeedDiscoveryTest.php new file mode 100644 index 000000000..1c5249701 --- /dev/null +++ b/plugins/FeedSub/tests/FeedDiscoveryTest.php @@ -0,0 +1,111 @@ +discoverFromHTML($url, $html); + $this->assertEquals($expected, $url); + } + + static public function provider() + { + $sampleHeader = << + + + + + +leŭksman + + + + + + + + + + + + + + + + + + + + + +END; + return array( + array('http://example.com/', + '', + 'http://example.com/feed/rss'), + array('http://example.com/atom', + '', + 'http://example.com/feed/atom'), + array('http://example.com/empty', + '', + false), + array('http://example.com/tagsoup', + '
',
+                           'http://example.com/feed/rss'),
+                     array('http://example.com/relative/link2',
+                           '',
+                           'http://example.com/feed/rss'),
+                     array('http://example.com/relative/link3',
+                           '',
+                           'http://example.com/feed/rss'),
+                     array('http://example.com/base/link1',
+                           '',
+                           'http://target.example.com/feed/rss'),
+                     array('http://example.com/base/link2',
+                           '',
+                           'http://target.example.com/feed/rss'),
+                     array('http://example.com/base/link3',
+                           '',
+                           'http://target.example.com/feed/rss'),
+                     // Trick question! There's a  but no href on it
+                     array('http://example.com/relative/fauxbase',
+                           '',
+                           '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/FeedSub/tests/FeedMungerTest.php b/plugins/FeedSub/tests/FeedMungerTest.php
new file mode 100644
index 000000000..0ce24c9fb
--- /dev/null
+++ b/plugins/FeedSub/tests/FeedMungerTest.php
@@ -0,0 +1,147 @@
+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('A fairly short titlehttp://example.com/short/link', 0,
+                           'New post: "A fairly short title" http://example.com/short/link'),
+                     // Requires URL shortening ...
+                     array('A fairly short titlehttp://example.com/but/a/very/long/link/indeed/this/is/far/too/long/for/mere/humans/to/comprehend/oh/my/gosh', 0,
+                           'New post: "A fairly short title" http://ur1.ca/g2o1'),
+                     array('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...http://example.com/but/a/very/long/link/indeed/this/is/far/too/long/for/mere/humans/to/comprehend/oh/my/gosh', 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 . <<
+
+
+	leŭksman
+	
+	http://leuksman.com/log
+	reticula, electronica, & oddities
+
+	Thu, 12 Nov 2009 17:44:42 +0000
+	http://wordpress.org/?v=2.8.6
+	en
+	hourly
+	1
+			
+
+		Compiling PHP on Snow Leopard
+		http://leuksman.com/log/2009/11/12/compiling-php-on-snow-leopard/
+		http://leuksman.com/log/2009/11/12/compiling-php-on-snow-leopard/#comments
+		Thu, 12 Nov 2009 17:44:42 +0000
+		brion
+				
+
+		
+
+		http://leuksman.com/log/?p=649
+		
+			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 should work from here…

+

For reference, here’s the whole configure line I currently use; MySQL is installed from the downloadable installer; other deps from MacPorts:

+

‘./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

+]]>
+ http://leuksman.com/log/2009/11/12/compiling-php-on-snow-leopard/feed/ + 0 +
+
+ +END; + return $samplefeed; + } + + static protected function samplefeedBlogspot() + { + return <<tag:blogger.com,1999:blog-77800835085316971672009-11-19T12:56:11.233-08:00Brion's Cool Test Blogbrionhttp://www.blogger.com/profile/12932299467049762017noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-7780083508531697167.post-84566718790002906772009-11-19T12:55:00.000-08:002009-11-19T12:56:11.241-08:00I love postingIt'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>brionhttp://www.blogger.com/profile/12932299467049762017noreply@blogger.com0tag:blogger.com,1999:blog-7780083508531697167.post-82022969178973466332009-11-18T13:52:00.001-08:002009-11-18T13:52:48.444-08:00Hey dudetestingggggggggg<div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7780083508531697167-8202296917897346633?l=briontest.blogspot.com' alt='' /></div>brionhttp://www.blogger.com/profile/12932299467049762017noreply@blogger.com0 +END; + } +} -- cgit v1.2.3-54-g00ecf