diff --git a/core/model/fieldtypes/Text.php b/core/model/fieldtypes/Text.php index 8f93f8162..0790d9cc1 100644 --- a/core/model/fieldtypes/Text.php +++ b/core/model/fieldtypes/Text.php @@ -262,18 +262,12 @@ class Text extends DBField { } $summary = substr($text, $position, $characters); - $stringPieces = explode(' ', $string); if($highlight) { - // Add a span around all occurences of the search term - $summary = str_ireplace($string, "$string", $summary); - // Add a span around all key words from the search term as well - if($stringPieces) { - foreach($stringPieces as $stringPiece) { - $summary = str_ireplace($stringPiece, "$stringPiece", $summary); - } + if($stringPieces) foreach($stringPieces as $stringPiece) { + $summary = str_ireplace($stringPiece, "$stringPiece", $summary); } } diff --git a/tests/fieldtypes/TextTest.php b/tests/fieldtypes/TextTest.php index 2f6490e89..233d6c77c 100644 --- a/tests/fieldtypes/TextTest.php +++ b/tests/fieldtypes/TextTest.php @@ -104,5 +104,25 @@ class TextTest extends SapphireTest { } } + function testContextSummary() { + $testString1 = '
This is some text. It is a test
'; + $testKeywords1 = 'test'; + $testString2 = 'This is some test text. Test test what if you have multiple keywords.
'; + $testKeywords2 = 'some test'; + $textObj = DBField::create('Text', $testString1, 'Text'); + + $this->assertEquals( + 'text. It is a test', + $textObj->ContextSummary(20, $testKeywords1) + ); + + $textObj->setValue($testString2); + + $this->assertEquals( + 'This is some test text. test test what if you have', + $textObj->ContextSummary(50, $testKeywords2) + ); + } + } -?> \ No newline at end of file +?>