mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Text::BigSummary() fails with undefined $data when $plain = false
This commit is contained in:
parent
461481d56a
commit
776f6976c9
@ -159,14 +159,14 @@ class Text extends StringField {
|
|||||||
* Performs the same function as the big summary, but doesn't trim new paragraphs off data.
|
* Performs the same function as the big summary, but doesn't trim new paragraphs off data.
|
||||||
* Caution: Not XML/HTML-safe - does not respect closing tags.
|
* Caution: Not XML/HTML-safe - does not respect closing tags.
|
||||||
*/
|
*/
|
||||||
public function BigSummary($maxWords = 50, $plain = 1) {
|
public function BigSummary($maxWords = 50, $plain = true) {
|
||||||
$result = "";
|
$result = '';
|
||||||
|
|
||||||
// get first sentence?
|
// get first sentence?
|
||||||
// this needs to be more robust
|
// this needs to be more robust
|
||||||
if($plain) $data = Convert::xml2raw($this->value, true);
|
$data = $plain ? Convert::xml2raw($this->value, true) : $this->value;
|
||||||
|
|
||||||
if(!$data) return "";
|
if(!$data) return '';
|
||||||
|
|
||||||
$sentences = explode('.', $data);
|
$sentences = explode('.', $data);
|
||||||
$count = count(explode(' ', $sentences[0]));
|
$count = count(explode(' ', $sentences[0]));
|
||||||
|
@ -112,9 +112,9 @@ class TextTest extends SapphireTest {
|
|||||||
/**
|
/**
|
||||||
* Test {@link Text->BigSummary()}
|
* Test {@link Text->BigSummary()}
|
||||||
*/
|
*/
|
||||||
public function testBigSummary() {
|
public function testBigSummaryPlain() {
|
||||||
$cases = array(
|
$cases = array(
|
||||||
'This text has multiple sentences. Big Summary uses this to split sentences up.'
|
'<p>This text has multiple sentences. Big Summary uses this to split sentences up.</p>'
|
||||||
=> 'This text has multiple...',
|
=> 'This text has multiple...',
|
||||||
'This text does not have multiple sentences' => 'This text does not...',
|
'This text does not have multiple sentences' => 'This text does not...',
|
||||||
'Very short' => 'Very short',
|
'Very short' => 'Very short',
|
||||||
@ -123,7 +123,25 @@ class TextTest extends SapphireTest {
|
|||||||
|
|
||||||
foreach($cases as $originalValue => $expectedValue) {
|
foreach($cases as $originalValue => $expectedValue) {
|
||||||
$textObj = DBField::create_field('Text', $originalValue);
|
$textObj = DBField::create_field('Text', $originalValue);
|
||||||
$this->assertEquals($expectedValue, $textObj->BigSummary(4));
|
$this->assertEquals($expectedValue, $textObj->BigSummary(4, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test {@link Text->BigSummary()}
|
||||||
|
*/
|
||||||
|
public function testBigSummary() {
|
||||||
|
$cases = array(
|
||||||
|
'<strong>This</strong> text has multiple sentences. Big Summary uses this to split sentences up.</p>'
|
||||||
|
=> '<strong>This</strong> 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_field('Text', $originalValue);
|
||||||
|
$this->assertEquals($expectedValue, $textObj->BigSummary(4, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user