BUG Text::BigSummary() fails with undefined $data when $plain = false

This commit is contained in:
Sean Harvey 2014-10-01 16:02:28 +13:00
parent 461481d56a
commit 776f6976c9
2 changed files with 29 additions and 11 deletions

View File

@ -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]));

View File

@ -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));
} }
} }