From 4a158454d68d84a50f0c06ba1e8780bb64989ca5 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Thu, 30 May 2013 09:26:58 +0100 Subject: [PATCH] FIX: Convert newlines to
tags in string fields (fixes #1942) --- model/fieldtypes/StringField.php | 7 +++++++ tests/model/StringFieldTest.php | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/model/fieldtypes/StringField.php b/model/fieldtypes/StringField.php index de8719edc17..6bc92a73b5c 100644 --- a/model/fieldtypes/StringField.php +++ b/model/fieldtypes/StringField.php @@ -96,6 +96,13 @@ public function prepValueForDB($value) { return parent::prepValueForDB($value); } } + + /** + * @return string + */ + public function forTemplate() { + return nl2br($this->XML()); + } /** * Limit this field's content by a number of characters. diff --git a/tests/model/StringFieldTest.php b/tests/model/StringFieldTest.php index 47b15c7812d..0dfb9499d73 100644 --- a/tests/model/StringFieldTest.php +++ b/tests/model/StringFieldTest.php @@ -5,6 +5,16 @@ */ class StringFieldTest extends SapphireTest { + + /** + * @covers StringField->forTemplate() + */ + public function testForTemplate() { + $this->assertEquals( + "this is
\na test!", + DBField::create_field('StringFieldTest_MyStringField', "this is\na test!")->forTemplate() + ); + } /** * @covers StringField->LowerCase()