API CHANGE Read-only fields no longer include companion hidden fields (see pull request #399)

BUGFIX Remove legacy code and template which is never picked-up so that TextareaField becomes 'readonly' when it is transfered to readonly field. Change TextareaFieldTest test cases to address a 'readonly' textarea field displaying the special html characters correctly.
This commit is contained in:
Normann Lou 2012-05-03 14:05:38 +12:00 committed by Ingo Schommer
parent f6c8468d56
commit 3b3b515571
4 changed files with 22 additions and 27 deletions

View File

@ -57,24 +57,6 @@ class TextareaField extends FormField {
);
}
function getTemplate() {
return ($this->isReadonly()) ? "{$this->template}_readonly" : $this->template;
}
/**
* Performs a readonly transformation on this field. You should still be
* able to copy from this field, and it should still send when you submit
* the form it's attached to.
*
* The element shouldn't be both disabled and readonly at the same time.
*/
function performReadonlyTransformation() {
$clone = clone $this;
$clone->setReadonly(true);
$clone->setDisabled(false);
return $clone;
}
/**
* Performs a disabled transformation on this field. You shouldn't be able to
* copy from this field, and it should not send any data when you submit the

View File

@ -1,2 +1,5 @@
<span id="$ID"<% if extraClass %> class="$extraClass"<% end_if %>>$Value</span>
<input $AttributesHTML>
<% if isReadonly %>
<span id="$ID"<% if extraClass %> class="$extraClass"<% end_if %>>$Value</span>
<% else %>
<input $AttributesHTML>
<% end_if %>

View File

@ -1 +0,0 @@
<span id="$ID" class="readonly$extraClass" name="$Name"><% if Value %>$Value<% else %><em>(<% _t('NONE', 'none') %>)</em><% end_if %></span>

View File

@ -6,21 +6,32 @@ class TextareaFieldTest extends SapphireTest {
* Quick smoke test to ensure that text is being encoded properly.
*/
function testTextEncoding() {
$inputText = "This is my <text>These are some unicodes: äöü&<>";
$inputText = "These are some unicodes: äöü";
$field = new TextareaField("Test", "Test");
$field->setValue($inputText);
$this->assertContains('This is my &lt;text&gt;These are some unicodes: &auml;&ouml;&uuml;&amp;&lt;&gt;', $field->Field());
$this->assertContains('These are some unicodes: &auml;&ouml;&uuml;', $field->Field());
}
/**
* Quick smoke test to ensure that text is being encoded properly in readonly fields.
* Quick smoke test to ensure that text with unicodes is being displayed properly in readonly fields.
*/
function testReadonlyTextEncoding() {
$inputText = "This is my <text>These are some unicodes: äöü&<>";
function testReadonlyDisplayUnicodes() {
$inputText = "These are some unicodes: äöü";
$field = new TextareaField("Test", "Test");
$field->setValue($inputText);
$field = $field->performReadonlyTransformation();
$this->assertContains('These are some unicodes: äöü', $field->Field());
}
/**
* Quick smoke test to ensure that text with special html chars is being displayed properly in readonly fields.
*/
function testReadonlyDisplaySepcialHTML() {
$inputText = "These are some special <html> chars including 'single' & \"double\" quotations";
$field = new TextareaField("Test", "Test");
$field = $field->performReadonlyTransformation();
$field->setValue($inputText);
$this->assertContains('This is my &lt;text&gt;These are some unicodes: &auml;&ouml;&uuml;&amp;&lt;&gt;', $field->Field());
$this->assertContains('These are some special &lt;html&gt; chars including &#039;single&#039; &amp; &quot;double&quot; quotations', $field->Field());
}
}