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.
This commit is contained in:
Ingo Schommer 2012-01-31 11:44:16 +01:00
parent e1e5546ab6
commit 618d767dcb
4 changed files with 63 additions and 22 deletions

View File

@ -192,12 +192,15 @@ abstract class DBField extends ViewableData {
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 @@ abstract class DBField extends ViewableData {
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 ''

View File

@ -13,6 +13,8 @@ abstract class StringField extends DBField {
"LimitCharacters" => "Text",
"Lower" => "Text",
"Upper" => "Text",
"LowerCase" => "Text",
"UpperCase" => "Text",
);
/**
@ -103,18 +105,38 @@ abstract class StringField extends DBField {
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();
}
}

View File

@ -213,8 +213,8 @@ class DBFieldTest extends SapphireTest {
$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());
}
}

View File

@ -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() {}
}