From 0085876495f0f8dda5dc58cb24a8f2220e7baf1e Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 31 Jan 2012 01:07:24 +0100 Subject: [PATCH] BUGFIX Casting return values on text helper methods in StringField, Text, Varchar --- core/model/fieldtypes/HTMLText.php | 21 +++++++++++++++++++- core/model/fieldtypes/StringField.php | 6 ++++++ core/model/fieldtypes/Text.php | 14 +++++++++++++- core/model/fieldtypes/Varchar.php | 5 +++++ tests/fieldtypes/HTMLTextTest.php | 28 +++++++++++++++++++++++++++ tests/fieldtypes/TextTest.php | 26 ++++++++++++++++++++++++- 6 files changed, 97 insertions(+), 3 deletions(-) diff --git a/core/model/fieldtypes/HTMLText.php b/core/model/fieldtypes/HTMLText.php index 47fea31c4..3f4ee9e50 100755 --- a/core/model/fieldtypes/HTMLText.php +++ b/core/model/fieldtypes/HTMLText.php @@ -28,6 +28,25 @@ class HTMLText extends Text { return (strlen($value) > $limit) ? substr($value, 0, $limit) . $add : $value; } + static $casting = array( + "AbsoluteLinks" => "HTMLText", + "BigSummary" => "HTMLText", + "ContextSummary" => "HTMLText", + "FirstParagraph" => "HTMLText", + "FirstSentence" => "HTMLText", + "LimitCharacters" => "HTMLText", + "LimitSentences" => "HTMLText", + "Lower" => "HTMLText", + "LowerCase" => "HTMLText", + "Summary" => "HTMLText", + "Upper" => "HTMLText", + "UpperCase" => "HTMLText", + 'EscapeXML' => 'HTMLText', + 'LimitWordCount' => 'HTMLText', + 'LimitWordCountXML' => 'HTMLText', + 'NoHTML' => 'Text', + ); + /** * Create a summary of the content. This will be some section of the first paragraph, limited by * $maxWords. All internal tags are stripped out - the return value is a string @@ -133,4 +152,4 @@ class HTMLText extends Text { } -?> \ No newline at end of file +?> diff --git a/core/model/fieldtypes/StringField.php b/core/model/fieldtypes/StringField.php index 50c6ffd07..51429b126 100644 --- a/core/model/fieldtypes/StringField.php +++ b/core/model/fieldtypes/StringField.php @@ -9,6 +9,12 @@ abstract class StringField extends DBField { protected $nullifyEmpty = true; + static $casting = array( + "LimitCharacters" => "Text", + "Lower" => "Text", + "Upper" => "Text", + ); + /** * Construct a string type field with a set of optional parameters * @param $name string The name of the field diff --git a/core/model/fieldtypes/Text.php b/core/model/fieldtypes/Text.php index 7ace59ae5..df231a47b 100644 --- a/core/model/fieldtypes/Text.php +++ b/core/model/fieldtypes/Text.php @@ -17,8 +17,20 @@ * @subpackage model */ class Text extends StringField { + static $casting = array( - "AbsoluteLinks" => "HTMLText", + "AbsoluteLinks" => "Text", + "BigSummary" => "Text", + "ContextSummary" => "Text", + "FirstParagraph" => "Text", + "FirstSentence" => "Text", + "LimitCharacters" => "Text", + "LimitSentences" => "Text", + "Summary" => "Text", + 'EscapeXML' => 'Text', + 'LimitWordCount' => 'Text', + 'LimitWordCountXML' => 'HTMLText', + 'NoHTML' => 'Text', ); /** diff --git a/core/model/fieldtypes/Varchar.php b/core/model/fieldtypes/Varchar.php index 1d308638c..707926c8c 100644 --- a/core/model/fieldtypes/Varchar.php +++ b/core/model/fieldtypes/Varchar.php @@ -10,6 +10,11 @@ * @subpackage model */ class Varchar extends StringField { + + static $casting = array( + "Initial" => "Text", + "URL" => "Text", + ); protected $size; diff --git a/tests/fieldtypes/HTMLTextTest.php b/tests/fieldtypes/HTMLTextTest.php index 9303ba6bb..6a3ba0592 100644 --- a/tests/fieldtypes/HTMLTextTest.php +++ b/tests/fieldtypes/HTMLTextTest.php @@ -102,5 +102,33 @@ class HTMLTextTest extends SapphireTest { $this->assertEquals($match, $textObj->FirstSentence()); } } + + public function testRAW() { + $data = DBField::create('HTMLText', 'This & This'); + $this->assertEquals($data->RAW(), 'This & This'); + + $data = DBField::create('HTMLText', 'This & This'); + $this->assertEquals($data->RAW(), 'This & This'); + } + + public function testXML() { + $data = DBField::create('HTMLText', 'This & This'); + $this->assertEquals($data->XML(), 'This & This'); + } + + public function testHTML() { + $data = DBField::create('HTMLText', 'This & This'); + $this->assertEquals($data->HTML(), 'This & This'); + } + + public function testJS() { + $data = DBField::create('HTMLText', '"this is a test"'); + $this->assertEquals($data->JS(), '\"this is a test\"'); + } + + public function testATT() { + $data = DBField::create('HTMLText', '"this is a test"'); + $this->assertEquals($data->ATT(), '"this is a test"'); + } } ?> \ No newline at end of file diff --git a/tests/fieldtypes/TextTest.php b/tests/fieldtypes/TextTest.php index b4e29b6c3..97a280441 100644 --- a/tests/fieldtypes/TextTest.php +++ b/tests/fieldtypes/TextTest.php @@ -142,6 +142,30 @@ class TextTest extends SapphireTest { 'A dog ate a cat while looking at a Foobar', $textObj->ContextSummary(100, $testKeyword3a) ); - } + + public function testRAW() { + $data = DBField::create('Text', 'This & This'); + $this->assertEquals($data->RAW(), 'This & This'); + } + + public function testXML() { + $data = DBField::create('Text', 'This & This'); + $this->assertEquals($data->XML(), 'This & This'); + } + + public function testHTML() { + $data = DBField::create('Text', 'This & This'); + $this->assertEquals($data->HTML(), 'This & This'); + } + + public function testJS() { + $data = DBField::create('Text', '"this is a test"'); + $this->assertEquals($data->JS(), '\"this is a test\"'); + } + + public function testATT() { + $data = DBField::create('Text', '"this is a test"'); + $this->assertEquals($data->ATT(), '"this is a test"'); + } } \ No newline at end of file