Permalink
Browse files

API CHANGE Removed XML escaping in DBField->LowerCase() and UpperCase…

…(), in order to consistently allow SSViewer to deal with casting. Affects subclasses like Text, Varchar and HTMLText.

API CHANGE Deprecated StringField->Lower() and Upper(), use String->LowerCase() and UpperCase() instead. Moved methods from DBField to StringField.
  • Loading branch information...
chillu committed Jan 31, 2012
1 parent e1e5546 commit 618d767dcba0ae784412842be8efdc77aaba643a
Showing with 63 additions and 22 deletions.
  1. +3 −17 model/fieldtypes/DBField.php
  2. +25 −3 model/fieldtypes/StringField.php
  3. +2 −2 tests/model/DBFieldTest.php
  4. +33 −0 tests/model/StringFieldTest.php
@@ -192,12 +192,15 @@ public function forTemplate() {
function HTMLATT() {
return Convert::raw2htmlatt($this->value);
}
+
function URLATT() {
return urlencode($this->value);
}
+
function RAWURLATT() {
return rawurlencode($this->value);
}
+
function ATT() {
return Convert::raw2att($this->value);
}
@@ -218,23 +221,6 @@ function XML(){
return Convert::raw2xml($this->value);
}
- /**
- * Converts the current value for this Enum DBField to lowercase.
- * @return string
- */
- function LowerCase() {
- return Convert::raw2xml(strtolower($this->value));
- }
-
- /**
- * Converts the current value for this Enum DBField to uppercase.
- * @return string
- */
- function UpperCase() {
- return Convert::raw2xml(strtoupper($this->value));
- }
-
-
/**
* Returns the value to be set in the database to blank this field.
* Usually it's a choice between null, 0, and ''
@@ -13,6 +13,8 @@
"LimitCharacters" => "Text",
"Lower" => "Text",
"Upper" => "Text",
+ "LowerCase" => "Text",
+ "UpperCase" => "Text",
);
/**
@@ -102,19 +104,39 @@ function LimitCharacters($limit = 20, $add = '...') {
}
return $value;
}
-
+
+ /**
+ * Converts the current value for this Enum DBField to lowercase.
+ * @return string
+ */
+ function LowerCase() {
+ return mb_strtolower($this->value);
+ }
+
/**
* Return another DBField object with this value in lowercase.
+ * @deprecated 3.0 Use LowerCase() instead.
*/
function Lower() {
- return DBField::create(get_class($this), mb_strtolower($this->value), $this->name);
+ Deprecation::notice('3.0', 'Use LowerCase() instead.');
+ return $this->LowerCase();
+ }
+
+ /**
+ * Converts the current value for this Enum DBField to uppercase.
+ * @return string
+ */
+ function UpperCase() {
+ return mb_strtoupper($this->value);
}
/**
* Return another DBField object with this value in uppercase.
+ * @deprecated 3.0 Use UpperCase() instead.
*/
function Upper() {
- return DBField::create(get_class($this), mb_strtoupper($this->value), $this->name);
+ Deprecation::notice('3.0', 'Use UpperCase() instead.');
+ return $this->UpperCase();
}
}
@@ -213,8 +213,8 @@ function testStringFieldsWithMultibyteData() {
$this->assertEquals('üåäö&ÜÅÄ...', $stringField->LimitCharacters(8));
}
- $this->assertEquals('ÅÄÖ', DBField::create('Text', 'åäö')->Upper()->getValue());
- $this->assertEquals('åäö', DBField::create('Text', 'ÅÄÖ')->Lower()->getValue());
+ $this->assertEquals('ÅÄÖ', DBField::create('Text', 'åäö')->UpperCase());
+ $this->assertEquals('åäö', DBField::create('Text', 'ÅÄÖ')->LowerCase());
}
}
@@ -0,0 +1,33 @@
+<?php
+/**
+ * @package sapphire
+ * @subpackage tests
+ */
+
+class StringFieldTest extends SapphireTest {
+
+ /**
+ * @covers StringField->LowerCase()
+ */
+ function testLowerCase() {
+ $this->assertEquals(
+ 'this is a test!',
+ DBField::create('StringFieldTest_MyStringField', 'This is a TEST!')->LowerCase()
+ );
+ }
+
+ /**
+ * @covers StringField->UpperCase()
+ */
+ function testUpperCase() {
+ $this->assertEquals(
+ 'THIS IS A TEST!',
+ DBField::create('StringFieldTest_MyStringField', 'This is a TEST!')->UpperCase()
+ );
+ }
+
+}
+
+class StringFieldTest_MyStringField extends StringField implements TestOnly {
+ function requireField() {}
+}

0 comments on commit 618d767

Please sign in to comment.