ISSUE 7833: Invoke ShortcodeParser on RestfulServer output

This commit is contained in:
Elliot Sawyer 2012-09-17 13:17:54 +12:00
parent a6f5b99a5c
commit 71758c782f
3 changed files with 31 additions and 3 deletions

View File

@ -56,7 +56,7 @@ class JSONDataFormatter extends DataFormatter {
// Field filtering
if($fields && !in_array($fieldName, $fields)) continue;
$fieldValue = $obj->$fieldName;
$fieldValue = $obj->obj($fieldName)->forTemplate();
$serobj->$fieldName = $fieldValue;
}

View File

@ -49,8 +49,7 @@ class XMLDataFormatter extends DataFormatter {
foreach($this->getFieldsForObj($obj) as $fieldName => $fieldType) {
// Field filtering
if($fields && !in_array($fieldName, $fields)) continue;
$fieldValue = $obj->$fieldName;
$fieldValue = $obj->obj($fieldName)->forTemplate();
if(!mb_check_encoding($fieldValue,'utf-8')) $fieldValue = "(data is badly encoded)";
if(is_object($fieldValue) && is_subclass_of($fieldValue, 'Object') && $fieldValue->hasMethod('toXML')) {

View File

@ -28,6 +28,35 @@ class XMLDataFormatterTest extends SapphireTest {
);
}
public function testShortcodesInDataObject() {
$formatter = new XMLDataFormatter();
$page1 = new Page();
$page1->Title = 'Test page1';
$page1->Content = '[sitetree_link,id=-1]';
$page1->write();
$page2 = new Page();
$page2->Title = 'Test page 2';
$page2->Content = 'This is some test content [sitetree_link,id='.$page1->ID.']';
$page2->write();
$page1->Content = '[bad_code,id=1]';
$page1->write();
$xml = new SimpleXMLElement('<?xml version="1.0"?>' . $formatter->convertDataObjectWithoutHeader($page2));
$this->assertContains('This is some test content '.$page1->Link(), $xml->Content);
$xml = new SimpleXMLElement('<?xml version="1.0"?>' . $formatter->convertDataObjectWithoutHeader($page1));
$this->assertEmpty('', $xml->Content);
$xml = new SimpleXMLElement('<?xml version="1.0"?>' . $formatter->convertDataObjectWithoutHeader($page1));
$this->assertContains('[bad_code,id=1]', $xml->Content);
$page1->delete();
$page2->delete();
}
}
class XMLDataFormatterTest_DataObject extends DataObject implements TestOnly {