diff --git a/core/model/fieldtypes/Text.php b/core/model/fieldtypes/Text.php index e0600c809..8f93f8162 100644 --- a/core/model/fieldtypes/Text.php +++ b/core/model/fieldtypes/Text.php @@ -181,7 +181,6 @@ class Text extends DBField { return ""; $sentences = explode( '.', $data ); - $count = count( explode( ' ', $sentences[0] ) ); // if the first sentence is too long, show only the first $maxWords words @@ -190,13 +189,15 @@ class Text extends DBField { } // add each sentence while there are enough words to do so do { - $result .= trim(array_shift( $sentences )).'. ' ; - $count += count( explode( ' ', $sentences[0] ) ); + $result .= trim(array_shift($sentences)); + if($sentences) { + $result .= '. '; + $count += count(explode(' ', $sentences[0])); + } // Ensure that we don't trim half way through a tag or a link $brokenLink = (substr_count($result,'<') != substr_count($result,'>')) || (substr_count($result,']*>/', $result ) && !preg_match( '/<\/a>/', $result ) ) diff --git a/tests/fieldtypes/TextTest.php b/tests/fieldtypes/TextTest.php index db84a4a66..2f6490e89 100644 --- a/tests/fieldtypes/TextTest.php +++ b/tests/fieldtypes/TextTest.php @@ -87,5 +87,22 @@ class TextTest extends SapphireTest { } } + /** + * Test {@link Text->BigSummary()} + */ + function testBigSummary() { + $cases = array( + 'This text has multiple sentences. Big Summary uses this to split sentences up.' => 'This text has multiple...', + 'This text does not have multiple sentences' => 'This text does not...', + 'Very short' => 'Very short', + '' => '' + ); + + foreach($cases as $originalValue => $expectedValue) { + $textObj = DBField::create('Text', $originalValue); + $this->assertEquals($expectedValue, $textObj->BigSummary(4)); + } + } + } ?> \ No newline at end of file