Permalink
Browse files

BUGFIX Casting return values on text helper methods in StringField, T…

…ext, Varchar
  • Loading branch information...
chillu committed Jan 31, 2012
1 parent acf9e01 commit 15e9e059e5948ccf8f5a36dfcb435ad26ecec334
@@ -22,6 +22,28 @@ function LimitCharacters($limit = 20, $add = "...") {
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",
+ "LimitWordCount" => "HTMLText",
+ "LimitWordCountXML" => "HTMLText",
+ "LimitWordCountPlainText" => "Text",
+ "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
@@ -117,4 +139,4 @@ public function scaffoldSearchField($title = null) {
}
-?>
+?>
@@ -6,7 +6,21 @@
*/
class Text extends DBField {
static $casting = array(
- "AbsoluteLinks" => "HTMLText",
+ "AbsoluteLinks" => "Text",
+ "BigSummary" => "Text",
+ "ContextSummary" => "Text",
+ "FirstParagraph" => "Text",
+ "FirstSentence" => "Text",
+ "LimitCharacters" => "Text",
+ "LimitSentences" => "Text",
+ "LimitWordCount" => "Text",
+ "LimitWordCountXML" => "Text",
+ "LimitWordCountPlainText" => "Text",
+ "Summary" => "Text",
+ 'EscapeXML' => 'Text',
+ 'LimitWordCount' => 'Text',
+ 'LimitWordCountXML' => 'HTMLText',
+ 'NoHTML' => 'Text',
);
function requireField() {
@@ -5,6 +5,12 @@
* @subpackage model
*/
class Varchar extends DBField {
+
+ static $casting = array(
+ "Initial" => "Text",
+ "URL" => "Text",
+ "LimitCharacters" => "Text",
+ );
protected $size;
@@ -102,5 +102,33 @@ function testFirstSentence() {
$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"');
+ }
}
?>
@@ -84,7 +84,30 @@ function testContextSummary() {
'This is <span class="highlight">some</span> <span class="highlight">test</span> text. <span class="highlight">test</span> <span class="highlight">test</span> what if you have',
$textObj->ContextSummary(50, $testKeywords2)
);
+ }
+
+ public function testRAW() {
+ $data = DBField::create('Text', 'This &amp; This');
+ $this->assertEquals($data->RAW(), 'This &amp; This');
}
-}
-?>
+ public function testXML() {
+ $data = DBField::create('Text', 'This & This');
+ $this->assertEquals($data->XML(), 'This &amp; This');
+ }
+
+ public function testHTML() {
+ $data = DBField::create('Text', 'This & This');
+ $this->assertEquals($data->HTML(), 'This &amp; 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(), '&quot;this is a test&quot;');
+ }
+}

1 comment on commit 15e9e05

@sminnee

This comment has been minimized.

Show comment Hide comment
@sminnee

sminnee Jan 31, 2012

Member

Looks good.

Member

sminnee commented on 15e9e05 Jan 31, 2012

Looks good.

Please sign in to comment.