Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved truncenator to it’s own file, same for it’s tests. Set up a tes…

…t bootstrap to autoload stuff. Made template classes for Posse Helpers and their tests
  • Loading branch information...
commit ddae8294979d8cf0292e7b398cc940ad03291304 1 parent 5d42414
Barnaby Walters authored
84 BarnabyWalters/Helpers/Helpers.php
View
@@ -52,90 +52,6 @@ public static function authorFromUri($uri) {
}
/**
- * ~ THE TRUNCENATOR ~
- *
- * Takes a string (tweet-like note) and some config params, produces a truncated version to spec.
- *
- * @param string $string The string to be truncated
- * @param int $length The maximum length of the output
- * @param string $ellipsis The string to append in the case of truncation
- * @param string $uri The canonical URI of the post, to be added to the end
- * @param int $urilen Treat any URLs as if they were this length
- * @param bool $parens If trucation is not required, surround the canon. link with parens (())
- * @param int $hashtags The number of hashtags present in the text to preserve if trucation occurs
- *
- * @return string The truncated string
- * @todo A lot of this functionality is not properly implemented
- */
- public static function truncate($string, $length = 140, $uri = null, $urilen = null, $parens = true, $ellipsis = '', $hastags = 1) {
- mb_internal_encoding('UTF-8');
-
- // Figure out total append length if truncation occurs
- $append = $ellipsis;
- if (!empty($uri))
- $append .= ' ' . $uri;
-
- // if $urilen is set, create array of URIs within the text and replace them with dummy text @ $urilen chars
- if (is_int($urilen)) {
- $uris = array();
- foreach (Helpers::findUrls($string, $tidy = false) as $key => $url) {
- $dummy = 'URL' . $key;
- $dummy .= str_repeat('X', $urilen - mb_strlen($dummy));
- $uris[$dummy] = $url;
- $string = str_replace($url, $dummy, $string);
- }
- }
-
- // Truncate string to nearest WB below that length
- $matches = array();
- $words = array();
- preg_match_all('/\b\w+\b/', $string, $matches, PREG_OFFSET_CAPTURE);
- foreach ($matches[0] as $match) {
- // For each match
- $words[] = array($match[1], $match[0]);
- }
- // $words = {[offset, 'string'], [offset, 'string'] •••}
-
- $maxplainlen = $length - Helpers::uriMbStrlen($append, $urilen);
-
- // See if truncation will happen
- if (Helpers::uriMbStrlen($string, $urilen) > $maxplainlen) {
- foreach ($words as $key => $word) {
- // Is the current word the first to cross $maxplainlen?
- if ($word[0] > $maxplainlen or $word[0] + mb_strlen($word[1]) > $maxplainlen) {
- // Yes. The current word and all words after it must be removed
- $plaintargetlen = $words[$key - 1][0] + mb_strlen($words[$key - 1][1]);
- break;
- }
- }
-
- if (!isset($plaintargetlen))
- $plaintargetlen = $maxplainlen;
-
- // Truncate string
- $truncatedplain = mb_substr($string, 0, $plaintargetlen);
-
- // Add the append
- $trunc = $truncatedplain . $append;
- }
- else {
- // If no trucation required, just append the URL
- // TODO: if adding the space and brackets will push over the edge, remove enough words to compensate
- // TODO: write edge-case test to cover that scenario
- $trunc = $string . ' (' . $uri . ')';
- }
-
- // if $urilen set, expand dummies into full URIs
- if (is_int($urilen)) {
- foreach ($uris as $dummy => $uri) {
- $trunc = str_replace($dummy, $uri, $trunc);
- }
- }
-
- return $trunc;
- }
-
- /**
* Replace <img> elements with their @href
*
* Finds all img elements and replaces them with the value of their @href.
14 BarnabyWalters/Posse/Helpers.php
View
@@ -0,0 +1,14 @@
+<?php
+
+namespace BarnabyWalters\Posse;
+
+/**
+ * Description of Helpers
+ *
+ * @author barnabywalters
+ */
+class Helpers {
+
+}
+
+// EOF
99 BarnabyWalters/Posse/Truncenator.php
View
@@ -0,0 +1,99 @@
+<?php
+
+namespace BarnabyWalters\Posse;
+
+use BarnabyWalters\Helpers\Helpers as H;
+
+/**
+ * THE TRUNCENATOR
+ *
+ * @author Barnaby Walters
+ */
+class Truncenator {
+
+ /**
+ * ~ THE TRUNCENATOR ~
+ *
+ * Takes a string (tweet-like note) and some config params, produces a truncated version to spec.
+ *
+ * @param string $string The string to be truncated
+ * @param int $length The maximum length of the output
+ * @param string $ellipsis The string to append in the case of truncation
+ * @param string $uri The canonical URI of the post, to be added to the end
+ * @param int $urilen Treat any URLs as if they were this length
+ * @param bool $parens If trucation is not required, surround the canon. link with parens (())
+ * @param int $hashtags The number of hashtags present in the text to preserve if trucation occurs
+ *
+ * @return string The truncated string
+ * @todo A lot of this functionality is not properly implemented
+ */
+ public static function truncate($string, $length = 140, $uri = null, $urilen = null, $parens = true, $ellipsis = '', $hastags = 1) {
+ mb_internal_encoding('UTF-8');
+
+ // Figure out total append length if truncation occurs
+ $append = $ellipsis;
+ if (!empty($uri))
+ $append .= ' ' . $uri;
+
+ // if $urilen is set, create array of URIs within the text and replace them with dummy text @ $urilen chars
+ if (is_int($urilen)) {
+ $uris = array();
+ foreach (H::findUrls($string, $tidy = false) as $key => $url) {
+ $dummy = 'URL' . $key;
+ $dummy .= str_repeat('X', $urilen - mb_strlen($dummy));
+ $uris[$dummy] = $url;
+ $string = str_replace($url, $dummy, $string);
+ }
+ }
+
+ // Truncate string to nearest WB below that length
+ $matches = array();
+ $words = array();
+ preg_match_all('/\b\w+\b/', $string, $matches, PREG_OFFSET_CAPTURE);
+ foreach ($matches[0] as $match) {
+ // For each match
+ $words[] = array($match[1], $match[0]);
+ }
+ // $words = {[offset, 'string'], [offset, 'string'] •••}
+
+ $maxplainlen = $length - H::uriMbStrlen($append, $urilen);
+
+ // See if truncation will happen
+ if (H::uriMbStrlen($string, $urilen) > $maxplainlen) {
+ foreach ($words as $key => $word) {
+ // Is the current word the first to cross $maxplainlen?
+ if ($word[0] > $maxplainlen or $word[0] + mb_strlen($word[1]) > $maxplainlen) {
+ // Yes. The current word and all words after it must be removed
+ $plaintargetlen = $words[$key - 1][0] + mb_strlen($words[$key - 1][1]);
+ break;
+ }
+ }
+
+ if (!isset($plaintargetlen))
+ $plaintargetlen = $maxplainlen;
+
+ // Truncate string
+ $truncatedplain = mb_substr($string, 0, $plaintargetlen);
+
+ // Add the append
+ $trunc = $truncatedplain . $append;
+ }
+ else {
+ // If no trucation required, just append the URL
+ // TODO: if adding the space and brackets will push over the edge, remove enough words to compensate
+ // TODO: write edge-case test to cover that scenario
+ $trunc = $string . ' (' . $uri . ')';
+ }
+
+ // if $urilen set, expand dummies into full URIs
+ if (is_int($urilen)) {
+ foreach ($uris as $dummy => $uri) {
+ $trunc = str_replace($dummy, $uri, $trunc);
+ }
+ }
+
+ return $trunc;
+ }
+}
+
+// EOF
6 nbproject/project.properties
View
@@ -1,8 +1,8 @@
include.path=${php.global.include.path}
php.version=PHP_54
-phpunit.bootstrap=
-phpunit.bootstrap.create.tests=false
-phpunit.configuration=
+phpunit.bootstrap=tests/bootstrap.php
+phpunit.bootstrap.create.tests=true
+phpunit.configuration=phpunit.xml
phpunit.run.test.files=true
phpunit.script=
phpunit.suite=
21 phpunit.xml
View
@@ -1,4 +1,5 @@
<phpunit backupGlobals="true"
+ bootstrap="Tests/bootstrap.php"
backupStaticAttributes="false"
cacheTokens="false"
colors="false"
@@ -15,14 +16,14 @@
stopOnSkipped="false"
strict="false"
verbose="false">
- <testsuites>
- <testsuite name="Test Suite">
- <directory suffix="Test.php">tests/</directory>
- </testsuite>
- </testsuites>
- <logging>
- <log type="coverage-html" target="tmp/report" charset="UTF-8"
- highlight="true"/>
- <log type="testdox-html" target="tmp/index.html"/>
- </logging>
+ <testsuites>
+ <testsuite name="Test Suite">
+ <directory suffix="Test.php">Tests/</directory>
+ </testsuite>
+ </testsuites>
+ <logging>
+ <log type="coverage-html" target="tmp/report" charset="UTF-8"
+ highlight="true"/>
+ <log type="testdox-html" target="tmp/index.html"/>
+ </logging>
</phpunit>
196 tests/BarnabyWalters/Helpers/HelpersTest.php
View
@@ -0,0 +1,196 @@
+<?php
+
+namespace Tests\BarnabyWalters\Helpers;
+
+use BarnabyWalters\Helpers\Helpers as H;
+
+/**
+ * A test suite for barnabywalters/helpers
+ *
+ * Contains tests for all my helper functions
+ *
+ * @author Barnaby Walters http://waterpigs.co.uk
+ * @autor app\helpers\tests
+ * @todo Move all traces of THE TRUNCENATOR out of here and into their own package
+ */
+class HelpersTest extends \PHPUnit_Framework_TestCase {
+ // !Logic
+
+ /**
+ * Test the truest() function
+ *
+ * @group unit
+ * @group logic
+ * @group helpers
+ */
+ public function testTruestReturnsTrue() {
+ // Should return the first true-ish value in args
+ $this->assertTrue(H::truest(false, '', true));
+ }
+
+ /**
+ * @group unit
+ * @group logic
+ */
+ public function testTruestReturnFalseIfNoneTrue() {
+ $this->assertFalse(H::truest(false, '', ''));
+ }
+
+ // !Text
+
+ /**
+ * @group text
+ */
+ public function testExpandImgExpandsImages() {
+ $test = 'blah blah <img src="thevalue" />';
+ $expected = 'blah blah thevalue';
+ $this->assertEquals($expected, H::expandImg($test));
+ }
+
+ /**
+ * @group text
+ */
+ public function testToAsciiSanitizes() {
+ $test = 'QQQ!’^*+MOREQ';
+ $expected = 'qqq-moreq';
+ $this->assertEquals($expected, H::toAscii($test));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ */
+ public function testAuthorFromUriTwitter() {
+ $input = 'https://twitter.com/BarnabyWalters/status/254199790307524610';
+ $expected = '@barnabywalters';
+ $this->assertEquals($expected, H::authorFromUri($input));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ */
+ public function testAuthorFromUriIndieweb() {
+ $input = 'http://waterpigs.co.uk/notes/254';
+ $expected = 'waterpigs.co.uk';
+ $this->assertEquals($expected, H::authorFromUri($input));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ */
+ public function testTimeElement() {
+ $testTime = new \DateTime();
+ $result = '<time datetime="' . $testTime->format('Y-m-d') . '" title="' . $testTime->format('Y-z') . '">' . $testTime->format('Y-m-d') . '</time>';
+ $this->assertEquals($result, H::timeElement($testTime));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ */
+ public function testTagstringToArray() {
+ $testTagstring = 'a tag, anothertag, <sometag>';
+ $testResult = array('a tag', 'anothertag', '&lt;sometag&gt;');
+ $this->assertEquals($testResult, H::tagstringToArray($testTagstring));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ */
+ public function testTagstringClean() {
+ $testTagstring = 'a tag, anothertag, <sometag>';
+ $testResult = 'a tag,anothertag,&lt;sometag&gt;';
+ $this->assertEquals($testResult, H::tagstringClean($testTagstring));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ */
+ public function testAutolinkHashTags() {
+ $testText = 'Hey there, #this tag should be auto-linked, as should #this';
+ $expected = 'Hey there, <a rel="tag" href="/my/tags/this">#this</a> tag should be auto-linked, as should <a rel="tag" href="/my/tags/this">#this</a>';
+
+ $this->assertEquals($expected, H::autolinkHashTags($testText, '/my/tags/'));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ */
+ public function testGetPrivacyTagsIgnoresNonAuthTags() {
+ $tags = array('sometag', 'someothertag');
+ $expected = array();
+
+ $this->assertEquals($expected, H::getAuthTags($tags));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ */
+ public function testGetPrivacyTagsParsesMultiplePrivateTagsCorrectly() {
+ $tags = array('auth:private=domain.com', 'auth:private=someotherdomain.com');
+ $expected = array(
+ 'private' => array(
+ 'domain.com',
+ 'someotherdomain.com'
+ )
+ );
+
+ $this->assertEquals($expected, H::getAuthTags($tags));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ */
+ public function testGetPrivacyTagsParsesMultiplePrivateAndEditableTagsCorrectly() {
+ $tags = array('auth:private=domain.com', 'auth:private=someotherdomain.com', 'auth:editable=someotherdomain.com');
+ $expected = array(
+ 'private' => array(
+ 'domain.com',
+ 'someotherdomain.com'
+ ),
+ 'editable' => array(
+ 'someotherdomain.com'
+ )
+ );
+
+ $this->assertEquals($expected, H::getAuthTags($tags));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ */
+ public function testAtomDate() {
+ $this->assertEquals('2012-10-15T22:46:00+00:00', H::atomDate('15th October 2012 22:46'));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ */
+ public function testFindURLs() {
+ $testString = 'Okay, so this string contains some URLs. http://waterpigs.co.uk, identi.ca, aaron.pk';
+ $testArray = array('http://waterpigs.co.uk', 'http://identi.ca', 'http://aaron.pk');
+ $this->assertEquals($testArray, H::findUrls($testString));
+ }
+
+}
+
+// EOF
14 tests/BarnabyWalters/Posse/HelpersTest.php
View
@@ -0,0 +1,14 @@
+<?php
+
+namespace Tests\BarnabyWalters\Posse;
+
+/**
+ * Description of HelpersTest
+ *
+ * @author barnabywalters
+ */
+class HelpersTest {
+ //put your code here
+}
+
+// EOF
144 tests/BarnabyWalters/Posse/TruncenatorTest.php
View
@@ -0,0 +1,144 @@
+<?php
+
+namespace Tests\BarnabyWalters\Posse;
+
+use BarnabyWalters\Posse\Truncenator;
+
+/**
+ * Description of TruncenatorTest
+ *
+ * @author Barnaby Walters
+ */
+class TruncenatorTest extends \PHPUnit_Framework_TestCase {
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ * @group truncenator
+ */
+ public function testTruncateRespectsLength() {
+ $input = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is some text which is over 140 characters long';
+ $expected = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is some text which is over 140…';
+ $this->assertEquals($expected, Truncenator::truncate($input, $length = 140));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ * @group truncenator
+ */
+ public function testTruncatePreservesWords() {
+ $input = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is some text which is over longlonglongword';
+ $expected = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is some text which is over…';
+ $this->assertEquals($expected, Truncenator::truncate($input, $length = 140));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ * @group truncenator
+ */
+ public function testTruncateAppendsURI() {
+ $input = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is some text which is over 140 characters long';
+ $uri = 'http://example.org/notes/14';
+ $expected = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is… http://example.org/notes/14';
+ $this->assertEquals($expected, Truncenator::truncate($input, $length = 140, $uri = $uri));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ * @group truncenator
+ */
+ public function testTruncateAppendsURIPreservingWords() {
+ $input = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters longwordlongwordlongwordlongword';
+ $uri = 'http://example.org/notes/15';
+ $expected = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters… http://example.org/notes/15';
+ $this->assertEquals($expected, Truncenator::truncate($input, $length = 140, $uri = $uri));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ * @group truncenator
+ */
+ public function testTruncateParenthesisesURIIfNotTruncated() {
+ $input = 'Here is some really short text';
+ $uri = 'http://example.org/notes/16';
+ $expected = 'Here is some really short text (http://example.org/notes/16)';
+ $this->assertEquals($expected, Truncenator::truncate($input, $length = 140, $uri = $uri));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ * @group truncenator
+ */
+ public function testTruncateRespectsURILength() {
+ $input = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is some text which is over 140 characters long';
+ $uri = 'http://example.org/notes/14';
+ $urilen = 20;
+ $expected = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is some… http://example.org/notes/14';
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ * @group truncenator
+ */
+ public function testTruncateRespectsTextURILength() {
+ $input = 'Here is some text with a URI in: http://example.com and one without a protocol: example.org long Here is some text which is over 140 characters long Here is some text which is over 140 characters long';
+ $uri = 'http://example.org/notes/14';
+ $urilen = 20;
+ $expected = 'Here is some text with a URI in: http://example.com and one without a protocol: example.org long Here is… http://example.org/notes/14';
+ $this->assertEquals($expected, Truncenator::truncate($input, $length = 140, $uri = $uri, $urilen = $urilen));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ * @group truncenator
+ */
+ public function testTruncateURILenOverloadsAppendURILength() {
+ $input = 'Here is some text over 140 characters long Here is some text over 140 characters long Here is some text over 140 characters long Here is some text over 140 characters long';
+ $uri = 'http://example.org/notes/14';
+ $urilen = 30; // over-engineering
+ $expected = 'Here is some text over 140 characters long Here is some text over 140 characters long Here is some text over… http://example.org/notes/14';
+ $this->assertEquals($expected, Truncenator::truncate($input, $length = 140, $uri = $uri, $urilen = $urilen));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ * @group truncenator
+ */
+ public function testTruncatePreservesHashtags() {
+ $input = 'Here is some text with #hashtags in! Woo! And it’s really long really long really long really long really long really long really long with #morehashtags at the #end';
+ $uri = 'http://example.com/notes/34';
+ $expected = 'Here is some text with #hashtags in! Woo! And it’s really long really long really long really… #morehashtags http://example.com/notes/34';
+ $this->assertEquals($expected, Truncenator::truncate($input, $length = 140, $uri = $uri));
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ * @group truncenator
+ */
+ public function testTruncateNoParenthesisLengthOkay() {
+ $input = 'Here is a piece of text 109 characters long Here is a piece of text 109 characters long there is piece text';
+ $uri = 'http://example.com/articles/34'; // 30 long
+ $expected = 'Here is a piece of text 109 characters long Here is a piece of text 109 characters long there is piece text (http://example.com/articles/34)';
+ $this->assertEquals($expected, Truncenator::truncate($input, $length = 140, $uri = $uri));
+ }
+}
+
+// EOF
337 tests/HelpersTest.php
View
@@ -1,337 +0,0 @@
-<?php
-
-namespace BarnabyWalters\Helpers\Test;
-
-use BarnabyWalters\Helpers\Helpers as H;
-
-// Load files
-$vendorPath = realpath(dirname(__DIR__) . '/vendor/autoload.php');
-if (file_exists($vendorPath)) {
- // If the vendor dir exists (the user is in a testing environment) load the autoloader
- ob_start();
- require $vendorPath;
- ob_end_clean();
-} else {
- die('Cannot run tests as you haven’t installed the required dependencies');
-}
-
-/**
- * A test suite for barnabywalters/helpers
- *
- * Contains tests for all my helper functions
- *
- * @author Barnaby Walters http://waterpigs.co.uk
- * @autor app\helpers\tests
- * @todo Move all traces of THE TRUNCENATOR out of here and into their own package
- */
-class HelpersTest extends \PHPUnit_Framework_TestCase {
- // !Logic
-
- /**
- * Test the truest() function
- *
- * @group unit
- * @group logic
- * @group helpers
- */
- public function testTruestReturnsTrue() {
- // Should return the first true-ish value in args
- $this->assertTrue(H::truest(false, '', true));
- }
-
- /**
- * @group unit
- * @group logic
- */
- public function testTruestReturnFalseIfNoneTrue() {
- $this->assertFalse(H::truest(false, '', ''));
- }
-
- // !Text
-
- /**
- * @group text
- */
- public function testExpandImgExpandsImages() {
- $test = 'blah blah <img src="thevalue" />';
- $expected = 'blah blah thevalue';
- $this->assertEquals($expected, H::expandImg($test));
- }
-
- /**
- * @group text
- */
- public function testToAsciiSanitizes() {
- $test = 'QQQ!’^*+MOREQ';
- $expected = 'qqq-moreq';
- $this->assertEquals($expected, H::toAscii($test));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- */
- public function testAuthorFromUriTwitter() {
- $input = 'https://twitter.com/BarnabyWalters/status/254199790307524610';
- $expected = '@barnabywalters';
- $this->assertEquals($expected, H::authorFromUri($input));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- */
- public function testAuthorFromUriIndieweb() {
- $input = 'http://waterpigs.co.uk/notes/254';
- $expected = 'waterpigs.co.uk';
- $this->assertEquals($expected, H::authorFromUri($input));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- * @group truncenator
- */
- public function testTruncateRespectsLength() {
- $input = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is some text which is over 140 characters long';
- $expected = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is some text which is over 140…';
- $this->assertEquals($expected, H::truncate($input, $length = 140));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- * @group truncenator
- */
- public function testTruncatePreservesWords() {
- $input = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is some text which is over longlonglongword';
- $expected = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is some text which is over…';
- $this->assertEquals($expected, H::truncate($input, $length = 140));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- * @group truncenator
- */
- public function testTruncateAppendsURI() {
- $input = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is some text which is over 140 characters long';
- $uri = 'http://example.org/notes/14';
- $expected = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is… http://example.org/notes/14';
- $this->assertEquals($expected, H::truncate($input, $length = 140, $uri = $uri));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- * @group truncenator
- */
- public function testTruncateAppendsURIPreservingWords() {
- $input = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters longwordlongwordlongwordlongword';
- $uri = 'http://example.org/notes/15';
- $expected = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters… http://example.org/notes/15';
- $this->assertEquals($expected, H::truncate($input, $length = 140, $uri = $uri));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- * @group truncenator
- */
- public function testTruncateParenthesisesURIIfNotTruncated() {
- $input = 'Here is some really short text';
- $uri = 'http://example.org/notes/16';
- $expected = 'Here is some really short text (http://example.org/notes/16)';
- $this->assertEquals($expected, H::truncate($input, $length = 140, $uri = $uri));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- * @group truncenator
- */
- public function testTruncateRespectsURILength() {
- $input = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is some text which is over 140 characters long';
- $uri = 'http://example.org/notes/14';
- $urilen = 20;
- $expected = 'Here is some text which is over 140 characters long Here is some text which is over 140 characters long Here is some… http://example.org/notes/14';
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- * @group truncenator
- */
- public function testTruncateRespectsTextURILength() {
- $input = 'Here is some text with a URI in: http://example.com and one without a protocol: example.org long Here is some text which is over 140 characters long Here is some text which is over 140 characters long';
- $uri = 'http://example.org/notes/14';
- $urilen = 20;
- $expected = 'Here is some text with a URI in: http://example.com and one without a protocol: example.org long Here is… http://example.org/notes/14';
- $this->assertEquals($expected, H::truncate($input, $length = 140, $uri = $uri, $urilen = $urilen));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- * @group truncenator
- */
- public function testTruncateURILenOverloadsAppendURILength() {
- $input = 'Here is some text over 140 characters long Here is some text over 140 characters long Here is some text over 140 characters long Here is some text over 140 characters long';
- $uri = 'http://example.org/notes/14';
- $urilen = 30; // over-engineering
- $expected = 'Here is some text over 140 characters long Here is some text over 140 characters long Here is some text over… http://example.org/notes/14';
- $this->assertEquals($expected, H::truncate($input, $length = 140, $uri = $uri, $urilen = $urilen));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- * @group truncenator
- */
- public function testTruncatePreservesHashtags() {
- $input = 'Here is some text with #hashtags in! Woo! And it’s really long really long really long really long really long really long really long with #morehashtags at the #end';
- $uri = 'http://example.com/notes/34';
- $expected = 'Here is some text with #hashtags in! Woo! And it’s really long really long really long really… #morehashtags http://example.com/notes/34';
- $this->assertEquals($expected, H::truncate($input, $length = 140, $uri = $uri));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- * @group truncenator
- */
- public function testTruncateNoParenthesisLengthOkay() {
- $input = 'Here is a piece of text 109 characters long Here is a piece of text 109 characters long there is piece text';
- $uri = 'http://example.com/articles/34'; // 30 long
- $expected = 'Here is a piece of text 109 characters long Here is a piece of text 109 characters long there is piece text (http://example.com/articles/34)';
- $this->assertEquals($expected, H::truncate($input, $length = 140, $uri = $uri));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- */
- public function testTimeElement() {
- $testTime = new \DateTime();
- $result = '<time datetime="' . $testTime->format('Y-m-d') . '" title="' . $testTime->format('Y-z') . '">' . $testTime->format('Y-m-d') . '</time>';
- $this->assertEquals($result, H::timeElement($testTime));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- */
- public function testTagstringToArray() {
- $testTagstring = 'a tag, anothertag, <sometag>';
- $testResult = array('a tag', 'anothertag', '&lt;sometag&gt;');
- $this->assertEquals($testResult, H::tagstringToArray($testTagstring));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- */
- public function testTagstringClean() {
- $testTagstring = 'a tag, anothertag, <sometag>';
- $testResult = 'a tag,anothertag,&lt;sometag&gt;';
- $this->assertEquals($testResult, H::tagstringClean($testTagstring));
- }
-
- /**
- * @group unit
- * @group text
- */
- public function testAutolinkHashTags() {
- $testText = 'Hey there, #this tag should be auto-linked, as should #this';
- $expected = 'Hey there, <a rel="tag" href="/my/tags/this">#this</a> tag should be auto-linked, as should <a rel="tag" href="/my/tags/this">#this</a>';
-
- $this->assertEquals($expected, H::autolinkHashTags($testText, '/my/tags/'));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- */
- public function testGetPrivacyTagsIgnoresNonAuthTags() {
- $tags = array('sometag', 'someothertag');
- $expected = array();
-
- $this->assertEquals($expected, H::getAuthTags($tags));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- */
- public function testGetPrivacyTagsParsesMultiplePrivateTagsCorrectly() {
- $tags = array('auth:private=domain.com', 'auth:private=someotherdomain.com');
- $expected = array(
- 'private' => array(
- 'domain.com',
- 'someotherdomain.com'
- )
- );
-
- $this->assertEquals($expected, H::getAuthTags($tags));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- */
- public function testGetPrivacyTagsParsesMultiplePrivateAndEditableTagsCorrectly() {
- $tags = array('auth:private=domain.com', 'auth:private=someotherdomain.com', 'auth:editable=someotherdomain.com');
- $expected = array(
- 'private' => array(
- 'domain.com',
- 'someotherdomain.com'
- ),
- 'editable' => array(
- 'someotherdomain.com'
- )
- );
-
- $this->assertEquals($expected, H::getAuthTags($tags));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- */
- public function testAtomDate() {
- $this->assertEquals('2012-10-15T22:46:00+00:00', H::atomDate('15th October 2012 22:46'));
- }
-
- /**
- * @group unit
- * @group text
- * @group helpers
- */
- public function testFindURLs() {
- $testString = 'Okay, so this string contains some URLs. http://waterpigs.co.uk, identi.ca, aaron.pk';
- $testArray = array('http://waterpigs.co.uk', 'http://identi.ca', 'http://aaron.pk');
- $this->assertEquals($testArray, H::findUrls($testString));
- }
-
-}
-
-// EOF
5 tests/bootstrap.php
View
@@ -0,0 +1,5 @@
+<?php
+
+require realpath(__DIR__ . '/../vendor/autoload.php');
+
+// EOF
Please sign in to comment.
Something went wrong with that request. Please try again.