Browse files

Added test for prepareForTwitter, TODO for converting some markdown o…

…r HTML to nicer twitter syntax
  • Loading branch information...
1 parent 8337496 commit 1550946468f40761c0690ccbb1698b66f2d324e4 @barnabywalters committed Nov 13, 2012
Showing with 12 additions and 1 deletion.
  1. +3 −1 BarnabyWalters/Posse/Helpers.php
  2. +9 −0 tests/BarnabyWalters/Posse/HelpersTest.php
View
4 BarnabyWalters/Posse/Helpers.php
@@ -32,6 +32,8 @@ class Helpers {
* @param string $url = null A URL to append to the content, if any
* @param string $inReplyTo = null A URL the content is in reply to
* @return array An assoc. array ready to pass as POST vars to `statuses/update`
+ *
+ * @todo Add some intelligent blockquote/other markdown handling
*/
public static function prepareForTwitter($text, $url = null, $inReplyTo = null) {
// Create the tweet array
@@ -42,7 +44,7 @@ public static function prepareForTwitter($text, $url = null, $inReplyTo = null)
// Run THE TRUNCENATOR using defaults suitable for twitter
ob_start();
- $tweet['status'] = H::truncate(
+ $tweet['status'] = Truncenator::truncate(
strip_tags(H::expandImg($tweet['status'])),
$length = 140,
$uri = $url,
View
9 tests/BarnabyWalters/Posse/HelpersTest.php
@@ -2,6 +2,8 @@
namespace Tests\BarnabyWalters\Posse;
+use BarnabyWalters\Posse\Helpers;
+
/**
* Description of HelpersTest
*
@@ -17,7 +19,14 @@ class HelpersTest extends \PHPUnit_Framework_TestCase {
* dealt with (e.g. in reply to URL), and that the return format is correct.
*/
public function testPrepareContentForTwitter() {
+ $text = 'Lots and lots and lots of very long text Lots and lots and lots of very long text Lots and lots and lots of very long text';
+ $url = 'http://example.com';
+ $inReplyTo = 'https://twitter.com/someuser/status/100';
+
+ $result = Helpers::prepareForTwitter($text, $url, $inReplyTo);
+ $this->assertTrue(strlen($result['status']) <= 140);
+ $this->assertEquals('100', $result['in_reply_to_status_id']);
}
}

0 comments on commit 1550946

Please sign in to comment.