Skip to content

Commit 0085876

Browse files
committed
BUGFIX Casting return values on text helper methods in StringField, Text, Varchar
1 parent 252e187 commit 0085876

File tree

6 files changed

+97
-3
lines changed

6 files changed

+97
-3
lines changed

core/model/fieldtypes/HTMLText.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ function LimitCharacters($limit = 20, $add = "...") {
2828
return (strlen($value) > $limit) ? substr($value, 0, $limit) . $add : $value;
2929
}
3030

31+
static $casting = array(
32+
"AbsoluteLinks" => "HTMLText",
33+
"BigSummary" => "HTMLText",
34+
"ContextSummary" => "HTMLText",
35+
"FirstParagraph" => "HTMLText",
36+
"FirstSentence" => "HTMLText",
37+
"LimitCharacters" => "HTMLText",
38+
"LimitSentences" => "HTMLText",
39+
"Lower" => "HTMLText",
40+
"LowerCase" => "HTMLText",
41+
"Summary" => "HTMLText",
42+
"Upper" => "HTMLText",
43+
"UpperCase" => "HTMLText",
44+
'EscapeXML' => 'HTMLText',
45+
'LimitWordCount' => 'HTMLText',
46+
'LimitWordCountXML' => 'HTMLText',
47+
'NoHTML' => 'Text',
48+
);
49+
3150
/**
3251
* Create a summary of the content. This will be some section of the first paragraph, limited by
3352
* $maxWords. All internal tags are stripped out - the return value is a string
@@ -133,4 +152,4 @@ public function scaffoldSearchField($title = null) {
133152

134153
}
135154

136-
?>
155+
?>

core/model/fieldtypes/StringField.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
abstract class StringField extends DBField {
1010
protected $nullifyEmpty = true;
1111

12+
static $casting = array(
13+
"LimitCharacters" => "Text",
14+
"Lower" => "Text",
15+
"Upper" => "Text",
16+
);
17+
1218
/**
1319
* Construct a string type field with a set of optional parameters
1420
* @param $name string The name of the field

core/model/fieldtypes/Text.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,20 @@
1717
* @subpackage model
1818
*/
1919
class Text extends StringField {
20+
2021
static $casting = array(
21-
"AbsoluteLinks" => "HTMLText",
22+
"AbsoluteLinks" => "Text",
23+
"BigSummary" => "Text",
24+
"ContextSummary" => "Text",
25+
"FirstParagraph" => "Text",
26+
"FirstSentence" => "Text",
27+
"LimitCharacters" => "Text",
28+
"LimitSentences" => "Text",
29+
"Summary" => "Text",
30+
'EscapeXML' => 'Text',
31+
'LimitWordCount' => 'Text',
32+
'LimitWordCountXML' => 'HTMLText',
33+
'NoHTML' => 'Text',
2234
);
2335

2436
/**

core/model/fieldtypes/Varchar.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
* @subpackage model
1111
*/
1212
class Varchar extends StringField {
13+
14+
static $casting = array(
15+
"Initial" => "Text",
16+
"URL" => "Text",
17+
);
1318

1419
protected $size;
1520

tests/fieldtypes/HTMLTextTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,33 @@ function testFirstSentence() {
102102
$this->assertEquals($match, $textObj->FirstSentence());
103103
}
104104
}
105+
106+
public function testRAW() {
107+
$data = DBField::create('HTMLText', 'This & This');
108+
$this->assertEquals($data->RAW(), 'This & This');
109+
110+
$data = DBField::create('HTMLText', 'This & This');
111+
$this->assertEquals($data->RAW(), 'This & This');
112+
}
113+
114+
public function testXML() {
115+
$data = DBField::create('HTMLText', 'This & This');
116+
$this->assertEquals($data->XML(), 'This & This');
117+
}
118+
119+
public function testHTML() {
120+
$data = DBField::create('HTMLText', 'This & This');
121+
$this->assertEquals($data->HTML(), 'This & This');
122+
}
123+
124+
public function testJS() {
125+
$data = DBField::create('HTMLText', '"this is a test"');
126+
$this->assertEquals($data->JS(), '\"this is a test\"');
127+
}
128+
129+
public function testATT() {
130+
$data = DBField::create('HTMLText', '"this is a test"');
131+
$this->assertEquals($data->ATT(), '"this is a test"');
132+
}
105133
}
106134
?>

tests/fieldtypes/TextTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,30 @@ function testContextSummary() {
142142
'A dog <span class="highlight">ate</span> a cat while looking at a Foobar',
143143
$textObj->ContextSummary(100, $testKeyword3a)
144144
);
145-
146145
}
146+
147+
public function testRAW() {
148+
$data = DBField::create('Text', 'This &amp; This');
149+
$this->assertEquals($data->RAW(), 'This &amp; This');
150+
}
151+
152+
public function testXML() {
153+
$data = DBField::create('Text', 'This & This');
154+
$this->assertEquals($data->XML(), 'This &amp; This');
155+
}
156+
157+
public function testHTML() {
158+
$data = DBField::create('Text', 'This & This');
159+
$this->assertEquals($data->HTML(), 'This &amp; This');
160+
}
161+
162+
public function testJS() {
163+
$data = DBField::create('Text', '"this is a test"');
164+
$this->assertEquals($data->JS(), '\"this is a test\"');
165+
}
166+
167+
public function testATT() {
168+
$data = DBField::create('Text', '"this is a test"');
169+
$this->assertEquals($data->ATT(), '&quot;this is a test&quot;');
170+
}
147171
}

0 commit comments

Comments
 (0)