mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch 'bugfix/apishortcodes' of https://github.com/elliot-sawyer/sapphire into 3.0
This commit is contained in:
commit
4e3c684b62
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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')) {
|
||||
|
@ -1,8 +1,21 @@
|
||||
<?php
|
||||
class XMLDataFormatterTest extends SapphireTest {
|
||||
protected $arguments, $contents, $tagName;
|
||||
|
||||
public static $fixture_file = 'XMLDataFormatterTest.yml';
|
||||
|
||||
public function setUp() {
|
||||
ShortcodeParser::get_active()->register('test_shortcode', array($this, 'shortcodeSaver'));
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
ShortcodeParser::get_active()->unregister('test_shortcode');
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
protected $extraDataObjects = array(
|
||||
'XMLDataFormatterTest_DataObject'
|
||||
);
|
||||
@ -28,6 +41,36 @@ class XMLDataFormatterTest extends SapphireTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function testShortcodesInDataObject() {
|
||||
$formatter = new XMLDataFormatter();
|
||||
|
||||
$page = new XMLDataFormatterTest_DataObject();
|
||||
$page->Content = 'This is some test content [test_shortcode]test[/test_shortcode]';
|
||||
|
||||
$xml = new SimpleXMLElement('<?xml version="1.0"?>' . $formatter->convertDataObjectWithoutHeader($page));
|
||||
$this->assertEquals('This is some test content test', $xml->Content);
|
||||
|
||||
$page->Content = '[test_shortcode,id=-1]';
|
||||
$xml = new SimpleXMLElement('<?xml version="1.0"?>' . $formatter->convertDataObjectWithoutHeader($page));
|
||||
$this->assertEmpty('', $xml->Content);
|
||||
|
||||
$page->Content = '[bad_code,id=1]';
|
||||
|
||||
$xml = new SimpleXMLElement('<?xml version="1.0"?>' . $formatter->convertDataObjectWithoutHeader($page));
|
||||
$this->assertContains('[bad_code,id=1]', $xml->Content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the result of a shortcode parse in object properties for easy testing access.
|
||||
*/
|
||||
public function shortcodeSaver($arguments, $content = null, $parser, $tagName = null) {
|
||||
$this->arguments = $arguments;
|
||||
$this->contents = $content;
|
||||
$this->tagName = $tagName;
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
}
|
||||
class XMLDataFormatterTest_DataObject extends DataObject implements TestOnly {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user