Permalink
Browse files

ISSUE 7833: Invoke ShortcodeParser on RestfulServer output

  • Loading branch information...
elliot-sawyer committed Sep 17, 2012
1 parent a6f5b99 commit 71758c782fd4bb839cc0ea1b87693e089aa30089
Showing with 31 additions and 3 deletions.
  1. +1 −1 api/JSONDataFormatter.php
  2. +1 −2 api/XMLDataFormatter.php
  3. +29 −0 tests/api/XMLDataFormatterTest.php
@@ -56,7 +56,7 @@ public function convertDataObjectToJSONObject(DataObjectInterface $obj, $fields
// Field filtering
if($fields && !in_array($fieldName, $fields)) continue;
- $fieldValue = $obj->$fieldName;
+ $fieldValue = $obj->obj($fieldName)->forTemplate();
$serobj->$fieldName = $fieldValue;
}
View
@@ -49,8 +49,7 @@ public function convertDataObjectWithoutHeader(DataObject $obj, $fields = null,
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')) {
@@ -28,6 +28,35 @@ public function testConvertDataObjectWithoutHeader() {
);
}
+ 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 {

0 comments on commit 71758c7

Please sign in to comment.