Skip to content
This repository
Browse code

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

…ext, Varchar
  • Loading branch information...
commit 0085876495f0f8dda5dc58cb24a8f2220e7baf1e 1 parent 252e187
Ingo Schommer authored January 31, 2012
21  core/model/fieldtypes/HTMLText.php
@@ -28,6 +28,25 @@ function LimitCharacters($limit = 20, $add = "...") {
28 28
 		return (strlen($value) > $limit) ? substr($value, 0, $limit) . $add : $value;
29 29
 	}
30 30
 
  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
+
31 50
 	/**
32 51
 	 * Create a summary of the content. This will be some section of the first paragraph, limited by
33 52
 	 * $maxWords. All internal tags are stripped out - the return value is a string
@@ -133,4 +152,4 @@ public function scaffoldSearchField($title = null) {
133 152
 
134 153
 }
135 154
 
136  
-?>
  155
+?>
6  core/model/fieldtypes/StringField.php
@@ -9,6 +9,12 @@
9 9
 abstract class StringField extends DBField {
10 10
 	protected $nullifyEmpty = true;
11 11
 
  12
+	static $casting = array(
  13
+		"LimitCharacters" => "Text",
  14
+		"Lower" => "Text",
  15
+		"Upper" => "Text",
  16
+	);
  17
+
12 18
 	/**
13 19
 	 * Construct a string type field with a set of optional parameters
14 20
 	 * @param $name string The name of the field
14  core/model/fieldtypes/Text.php
@@ -17,8 +17,20 @@
17 17
  * @subpackage model
18 18
  */
19 19
 class Text extends StringField {
  20
+
20 21
 	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',
22 34
 	);
23 35
 	
24 36
  	/**
5  core/model/fieldtypes/Varchar.php
@@ -10,6 +10,11 @@
10 10
  * @subpackage model
11 11
  */
12 12
 class Varchar extends StringField {
  13
+
  14
+	static $casting = array(
  15
+		"Initial" => "Text",
  16
+		"URL" => "Text",
  17
+	);
13 18
 	
14 19
 	protected $size;
15 20
 	 
28  tests/fieldtypes/HTMLTextTest.php
@@ -102,5 +102,33 @@ function testFirstSentence() {
102 102
 			$this->assertEquals($match, $textObj->FirstSentence());
103 103
 		}
104 104
 	}	
  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
+	}
105 133
 }
106 134
 ?>
26  tests/fieldtypes/TextTest.php
@@ -142,6 +142,30 @@ function testContextSummary() {
142 142
 			'A dog <span class="highlight">ate</span> a cat while looking at a Foobar',
143 143
 			$textObj->ContextSummary(100, $testKeyword3a)
144 144
 		);
145  
-		
146 145
 	}	
  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
+	}
147 171
 }

1 note on commit 0085876

Sam Minnée
Owner

Adding casting is benign, so this is benign. The increased exec time should be okay, and if not, site devs should use partial caching! ;-)

Please sign in to comment.
Something went wrong with that request. Please try again.