mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
e1e5546ab6
commit
618d767dcb
@ -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 ''
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
33
tests/model/StringFieldTest.php
Normal file
33
tests/model/StringFieldTest.php
Normal 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() {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user