2009-06-17 13:36:49 +02:00
|
|
|
<?php
|
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Forms\Tests;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Forms\TextareaField;
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class TextareaFieldTest extends SapphireTest
|
|
|
|
{
|
|
|
|
|
2016-12-28 14:52:49 +01:00
|
|
|
public function testCasting()
|
|
|
|
{
|
|
|
|
// Test special characters
|
|
|
|
$inputText = "These are some unicodes: ä, ö, & ü";
|
|
|
|
$field = new TextareaField("Test", "Test");
|
|
|
|
$field->setValue($inputText);
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString('These are some unicodes: ä, ö, & ü', $field->Field());
|
2016-12-28 14:52:49 +01:00
|
|
|
// Test shortcodes
|
|
|
|
$inputText = "Shortcode: [file_link id=4]";
|
|
|
|
$field = new TextareaField("Test", "Test");
|
|
|
|
$field->setValue($inputText);
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString('Shortcode: [file_link id=4]', $field->Field());
|
2016-12-28 14:52:49 +01:00
|
|
|
}
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* Quick smoke test to ensure that text with unicodes is being displayed properly in readonly fields.
|
|
|
|
*/
|
|
|
|
public function testReadonlyDisplayUnicodes()
|
|
|
|
{
|
|
|
|
$inputText = "These are some unicodes: äöü";
|
|
|
|
$field = new TextareaField("Test", "Test");
|
|
|
|
$field->setValue($inputText);
|
|
|
|
$field = $field->performReadonlyTransformation();
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString('These are some unicodes: äöü', $field->Field());
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Quick smoke test to ensure that text with special html chars is being displayed properly in readonly fields.
|
|
|
|
*/
|
|
|
|
public function testReadonlyDisplaySpecialHTML()
|
|
|
|
{
|
|
|
|
$inputText = "These are some special <html> chars including 'single' & \"double\" quotations";
|
|
|
|
$field = new TextareaField("Test", "Test");
|
|
|
|
$field = $field->performReadonlyTransformation();
|
|
|
|
$field->setValue($inputText);
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString(
|
2016-12-16 05:34:21 +01:00
|
|
|
'These are some special <html> chars including 'single' &'
|
|
|
|
. ' "double" quotations',
|
|
|
|
$field->Field()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testValueEntities()
|
|
|
|
{
|
|
|
|
$inputText = "These <b>are</b> some unicodes: äöü";
|
|
|
|
$field = new TextareaField("Test", "Test");
|
|
|
|
$field->setValue($inputText);
|
|
|
|
|
|
|
|
// Value should be safe-encoding only, but ValueEntities should be more aggressive
|
|
|
|
$this->assertEquals(
|
|
|
|
"These <b>are</b> some unicodes: äöü",
|
|
|
|
$field->obj('ValueEntities')->forTemplate()
|
|
|
|
);
|
|
|
|
|
|
|
|
// Shortcodes are disabled
|
|
|
|
$this->assertEquals(
|
|
|
|
false,
|
|
|
|
$field->obj('ValueEntities')->getProcessShortcodes()
|
|
|
|
);
|
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|