diff --git a/model/fieldtypes/DBField.php b/model/fieldtypes/DBField.php index db8e821bd..71866782e 100644 --- a/model/fieldtypes/DBField.php +++ b/model/fieldtypes/DBField.php @@ -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 '' diff --git a/model/fieldtypes/StringField.php b/model/fieldtypes/StringField.php index de994c2af..0f843ef09 100644 --- a/model/fieldtypes/StringField.php +++ b/model/fieldtypes/StringField.php @@ -13,6 +13,8 @@ abstract class StringField extends DBField { "LimitCharacters" => "Text", "Lower" => "Text", "Upper" => "Text", + "LowerCase" => "Text", + "UpperCase" => "Text", ); /** @@ -102,19 +104,39 @@ 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(); } } diff --git a/tests/model/DBFieldTest.php b/tests/model/DBFieldTest.php index cb37fa417..4d38bde1d 100644 --- a/tests/model/DBFieldTest.php +++ b/tests/model/DBFieldTest.php @@ -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()); } } diff --git a/tests/model/StringFieldTest.php b/tests/model/StringFieldTest.php new file mode 100644 index 000000000..2bfd9b8f2 --- /dev/null +++ b/tests/model/StringFieldTest.php @@ -0,0 +1,33 @@ +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() {} +} \ No newline at end of file